feat(batch17): port lifecycle, tls, and rate-limited logging features

This commit is contained in:
Joseph Doherty
2026-02-28 19:32:59 -05:00
parent 8d5964efff
commit 4974339b52
8 changed files with 694 additions and 18 deletions

View File

@@ -6,6 +6,26 @@ namespace ZB.MOM.NatsNet.Server.Tests.ImplBacklog;
public sealed class NatsServerTests
{
[Fact]
public void RateLimitedClientLogging_ShouldSuppressDuplicates()
{
var logger = new NatsServerCaptureLogger();
var (server, err) = NatsServer.NewServer(new ServerOptions());
err.ShouldBeNull();
server.SetLogger(logger, debugFlag: true, traceFlag: true);
var c = new ClientConnection(ClientKind.Client, server, new MemoryStream());
c.RateLimitWarnf("duplicate warning {0}", "A");
c.RateLimitWarnf("duplicate warning {0}", "A");
c.RateLimitFormatWarnf("format warning {0}", "B");
c.RateLimitFormatWarnf("format warning {0}", "C");
c.RateLimitErrorf("duplicate error {0}", "X");
c.RateLimitErrorf("duplicate error {0}", "X");
logger.Warnings.Count.ShouldBe(2);
logger.Errors.Count.ShouldBe(1);
}
[Fact] // T:2886
public void CustomRouterAuthentication_ShouldSucceed()
{
@@ -518,4 +538,17 @@ public sealed class NatsServerTests
"TestServerShutdownDuringStart".ShouldNotBeNullOrWhiteSpace();
}
private sealed class NatsServerCaptureLogger : INatsLogger
{
public List<string> Warnings { get; } = [];
public List<string> Errors { get; } = [];
public void Noticef(string format, params object[] args) { }
public void Warnf(string format, params object[] args) => Warnings.Add(string.Format(format, args));
public void Fatalf(string format, params object[] args) { }
public void Errorf(string format, params object[] args) => Errors.Add(string.Format(format, args));
public void Debugf(string format, params object[] args) { }
public void Tracef(string format, params object[] args) { }
}
}