Eliminate PortTracker stub backlog by implementing Raft/file-store/stream/server/client/OCSP stubs and adding coverage. This makes all tracked stub features/tests executable and verified in the current porting phase.
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
// Copyright 2012-2026 The NATS Authors
|
||||
// Licensed under the Apache License, Version 2.0
|
||||
|
||||
using System.Reflection;
|
||||
using Shouldly;
|
||||
using ZB.MOM.NatsNet.Server;
|
||||
using ZB.MOM.NatsNet.Server.Internal;
|
||||
|
||||
namespace ZB.MOM.NatsNet.Server.Tests.Server;
|
||||
|
||||
public sealed class ServerLifecycleStubFeaturesTests
|
||||
{
|
||||
[Fact]
|
||||
public void LifecycleHelpers_RemoveRouteAndReload_ShouldBehave()
|
||||
{
|
||||
var (server, err) = NatsServer.NewServer(new ServerOptions());
|
||||
err.ShouldBeNull();
|
||||
server.ShouldNotBeNull();
|
||||
|
||||
var route = new ClientConnection(ClientKind.Router) { Cid = 42 };
|
||||
var routes = new Dictionary<string, List<ClientConnection>> { ["pool"] = [route] };
|
||||
var clients = new Dictionary<ulong, ClientConnection> { [route.Cid] = route };
|
||||
|
||||
SetField(server!, "_routes", routes);
|
||||
SetField(server!, "_clients", clients);
|
||||
|
||||
server.ForEachRoute(_ => { });
|
||||
|
||||
InvokePrivate(server!, "RemoveRoute", route);
|
||||
((Dictionary<string, List<ClientConnection>>)GetField(server!, "_routes")).Count.ShouldBe(0);
|
||||
((Dictionary<ulong, ClientConnection>)GetField(server!, "_clients")).Count.ShouldBe(0);
|
||||
|
||||
var nonce = new byte[16];
|
||||
InvokePrivate(server!, "GenerateNonce", nonce);
|
||||
nonce.Any(b => b != 0).ShouldBeTrue();
|
||||
|
||||
var before = (DateTime)GetField(server!, "_configTime");
|
||||
server.Reload();
|
||||
var after = (DateTime)GetField(server!, "_configTime");
|
||||
after.ShouldBeGreaterThanOrEqualTo(before);
|
||||
}
|
||||
|
||||
private static object GetField(object target, string name)
|
||||
{
|
||||
return target.GetType()
|
||||
.GetField(name, BindingFlags.Instance | BindingFlags.NonPublic)!
|
||||
.GetValue(target)!;
|
||||
}
|
||||
|
||||
private static void SetField(object target, string name, object value)
|
||||
{
|
||||
target.GetType()
|
||||
.GetField(name, BindingFlags.Instance | BindingFlags.NonPublic)!
|
||||
.SetValue(target, value);
|
||||
}
|
||||
|
||||
private static void InvokePrivate(object target, string name, params object[] args)
|
||||
{
|
||||
target.GetType()
|
||||
.GetMethod(name, BindingFlags.Instance | BindingFlags.NonPublic)!
|
||||
.Invoke(target, args);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user