feat(batch18): implement group-b server core helpers

This commit is contained in:
Joseph Doherty
2026-02-28 19:24:25 -05:00
parent f8d384711d
commit 108d06dd57
6 changed files with 180 additions and 7 deletions

View File

@@ -40,6 +40,59 @@ public sealed class ServerLifecycleStubFeaturesTests
after.ShouldBeGreaterThanOrEqualTo(before);
}
[Fact]
public void NumRemotesInternal_WhenRoutesRegistered_ReturnsRouteBucketCount()
{
var (server, err) = NatsServer.NewServer(new ServerOptions());
err.ShouldBeNull();
server.ShouldNotBeNull();
SetField(
server!,
"_routes",
new Dictionary<string, List<ClientConnection>>
{
["a"] = [],
["b"] = [],
["c"] = [],
});
var numRemotesInternal = server.GetType()
.GetMethod("NumRemotesInternal", BindingFlags.Instance | BindingFlags.NonPublic);
numRemotesInternal.ShouldNotBeNull();
var count = (int)numRemotesInternal!.Invoke(server, null)!;
count.ShouldBe(3);
server.NumRemotes().ShouldBe(3);
}
[Fact]
public void ReadyForConnectionsInternal_WhenRouteListenerErrorPresent_ReturnsDetailedFailure()
{
var opts = new ServerOptions
{
DontListen = true,
Cluster = new ClusterOpts { Port = 6222 },
LeafNode = new LeafNodeOpts { Port = 0 },
Websocket = new WebsocketOpts { Port = 0 },
Mqtt = new MqttOpts { Port = 0 },
};
var (server, err) = NatsServer.NewServer(opts);
err.ShouldBeNull();
server.ShouldNotBeNull();
SetField(server!, "_routeListenerErr", new InvalidOperationException("route listener failed"));
var readyForConnectionsInternal = server.GetType()
.GetMethod("ReadyForConnectionsInternal", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
readyForConnectionsInternal.ShouldNotBeNull();
var readyError = readyForConnectionsInternal!.Invoke(server, [TimeSpan.FromMilliseconds(40)]) as Exception;
readyError.ShouldNotBeNull();
readyError!.Message.ShouldContain("route(");
readyError.Message.ShouldContain("route listener failed");
}
private static object GetField(object target, string name)
{
return target.GetType()