feat(batch24): complete leaf nodes implementation and verification

This commit is contained in:
Joseph Doherty
2026-03-01 01:31:57 -05:00
parent ff7e674ec4
commit 3e9ad16033
36 changed files with 3427 additions and 21 deletions

View File

@@ -171,4 +171,22 @@ public sealed partial class LeafNodeHandlerTests
((INatsAccount)account).RemoveClient(leaf);
account.NumLocalLeafNodes().ShouldBe(0);
}
[Fact] // T:1966
public void LeafNodeRoutedSubKeyDifferentBetweenLeafSubAndRoutedSub_ShouldSucceed()
{
var plain = new Subscription { Subject = "foo"u8.ToArray() };
var queue = new Subscription { Subject = "XYZ"u8.ToArray(), Queue = "foo"u8.ToArray() };
var routedPlain = LeafNodeHandler.KeyFromSubWithOrigin(plain);
var routedQueue = LeafNodeHandler.KeyFromSubWithOrigin(queue);
var leafPlain = LeafNodeHandler.KeyFromSubWithOrigin(plain, "XYZ");
var leafQueue = LeafNodeHandler.KeyFromSubWithOrigin(queue, "XYZ");
routedPlain.ShouldNotBe(routedQueue);
routedQueue.ShouldNotBe(leafPlain);
leafPlain.ShouldNotBe(leafQueue);
routedPlain.ShouldNotBe(leafPlain);
routedQueue.ShouldNotBe(leafQueue);
}
}

View File

@@ -204,4 +204,31 @@ public sealed partial class RouteHandlerTests
public Task<string[]> LookupHostAsync(string host, CancellationToken ct = default)
=> Task.FromResult(hosts);
}
[Fact] // T:2825
public void ClusterQueueGroupWeightTrackingLeak_ShouldSucceed()
{
var account = Account.NewAccount("$G");
var queueSub = new Subscription
{
Subject = "foo"u8.ToArray(),
Queue = "bar"u8.ToArray(),
Qw = 1,
};
account.UpdateLeafNodes(queueSub, 1);
var lqwsField = typeof(Account).GetField("_lqws", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
lqwsField.ShouldNotBeNull();
var lqws = (Dictionary<string, int>?)lqwsField!.GetValue(account);
lqws.ShouldNotBeNull();
lqws!.TryGetValue("foo bar", out var initialWeight).ShouldBeTrue();
initialWeight.ShouldBe(1);
account.UpdateLeafNodes(queueSub, -1);
lqws = (Dictionary<string, int>?)lqwsField.GetValue(account);
(lqws?.ContainsKey("foo bar") ?? false).ShouldBeFalse();
}
}