feat(batch17): merge client-core-second-half

This commit is contained in:
Joseph Doherty
2026-02-28 19:54:15 -05:00
13 changed files with 1720 additions and 30 deletions

View File

@@ -63,6 +63,41 @@ public sealed class NatsServerTests
tlsConfig.ShouldNotBeNull();
}
[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]
public void ServerRateLimitLogging_ShouldSucceed()
{
var logger = new NatsServerCaptureLogger();
var (server, err) = NatsServer.NewServer(new ServerOptions());
err.ShouldBeNull();
server.SetLogger(logger, debugFlag: false, traceFlag: false);
server.RateLimitWarnf("batch17 warning");
server.RateLimitWarnf("batch17 warning");
logger.Warnings.Count.ShouldBe(1);
logger.Errors.Count.ShouldBe(0);
}
[Fact] // T:2886
public void CustomRouterAuthentication_ShouldSucceed()
{
@@ -575,10 +610,24 @@ 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) { }
}
private static void SetField(object target, string name, object? value)
{
target.GetType()
.GetField(name, BindingFlags.Instance | BindingFlags.NonPublic)!
.SetValue(target, value);
}
}