feat(batch18): implement group-a server core helpers
This commit is contained in:
@@ -17,6 +17,8 @@
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Net.Security;
|
||||
using System.Threading;
|
||||
using NSubstitute;
|
||||
using NSubstitute.ExceptionExtensions;
|
||||
using Shouldly;
|
||||
@@ -280,6 +282,27 @@ public sealed class ServerTests
|
||||
[Fact]
|
||||
public void NeedsCompression_S2Fast_ReturnsTrue()
|
||||
=> NatsServer.NeedsCompression(CompressionMode.S2Fast).ShouldBeTrue();
|
||||
|
||||
[Theory]
|
||||
[InlineData(CompressionMode.S2Uncompressed, "writer_concurrency=1", "writer_uncompressed")]
|
||||
[InlineData(CompressionMode.S2Best, "writer_concurrency=1", "writer_best_compression")]
|
||||
[InlineData(CompressionMode.S2Better, "writer_concurrency=1", "writer_better_compression")]
|
||||
public void S2WriterOptions_KnownModes_ReturnExpectedOptions(
|
||||
string mode,
|
||||
string expectedFirst,
|
||||
string expectedSecond)
|
||||
{
|
||||
var options = NatsServer.S2WriterOptions(mode);
|
||||
|
||||
options.ShouldNotBeNull();
|
||||
options!.ShouldBe([expectedFirst, expectedSecond]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void S2WriterOptions_UnsupportedMode_ReturnsNull()
|
||||
{
|
||||
NatsServer.S2WriterOptions(CompressionMode.S2Fast).ShouldBeNull();
|
||||
}
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
@@ -292,6 +315,57 @@ public sealed class ServerTests
|
||||
/// </summary>
|
||||
public sealed class ServerListenersTests
|
||||
{
|
||||
[Fact]
|
||||
public void TlsTimeout_IncompleteHandshake_ClosesConnection()
|
||||
{
|
||||
var c = new ClientConnection(ClientKind.Client, nc: new MemoryStream());
|
||||
using var tls = new SslStream(new MemoryStream(), leaveInnerStreamOpen: false);
|
||||
|
||||
c.IsClosed().ShouldBeFalse();
|
||||
|
||||
NatsServer.TlsTimeout(c, tls);
|
||||
|
||||
c.IsClosed().ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StartGoRoutine_WithLabels_InvokesSetGoRoutineLabels()
|
||||
{
|
||||
var (s, err) = NatsServer.NewServer(new ServerOptions());
|
||||
err.ShouldBeNull();
|
||||
s.ShouldNotBeNull();
|
||||
s!.Start();
|
||||
|
||||
var signal = new ManualResetEventSlim(false);
|
||||
IReadOnlyList<KeyValuePair<string, string>>? observed = null;
|
||||
|
||||
NatsServer.SetGoRoutineLabelsHookForTest = labels =>
|
||||
{
|
||||
observed = labels;
|
||||
signal.Set();
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
var started = s.StartGoRoutine(
|
||||
() => { },
|
||||
new Dictionary<string, string> { ["component"] = "server", ["loop"] = "tls" });
|
||||
|
||||
started.ShouldBeTrue();
|
||||
signal.Wait(TimeSpan.FromSeconds(2)).ShouldBeTrue();
|
||||
|
||||
observed.ShouldNotBeNull();
|
||||
observed!.ShouldContain(kv => kv.Key == "component" && kv.Value == "server");
|
||||
observed.ShouldContain(kv => kv.Key == "loop" && kv.Value == "tls");
|
||||
}
|
||||
finally
|
||||
{
|
||||
NatsServer.SetGoRoutineLabelsHookForTest = null;
|
||||
s.Shutdown();
|
||||
s.WaitForShutdown();
|
||||
}
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// GenerateInfoJson (feature 3069) — Test ID 2906
|
||||
// Mirrors Go TestServerJsonMarshalNestedStructsPanic (guards against
|
||||
|
||||
Reference in New Issue
Block a user