test(batch26): port cross-module websocket-dependent tests
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Diagnostics;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using Shouldly;
|
||||
using ZB.MOM.NatsNet.Server;
|
||||
|
||||
@@ -269,6 +271,73 @@ public sealed partial class ConcurrencyTests1
|
||||
}, DefaultStreamConfig());
|
||||
}
|
||||
|
||||
[Fact] // T:2371
|
||||
public void NoRaceAvoidSlowConsumerBigMessages_ShouldSucceed()
|
||||
{
|
||||
WithStore((fs, _) =>
|
||||
{
|
||||
var errors = new ConcurrentQueue<Exception>();
|
||||
var payload = new byte[128 * 1024];
|
||||
|
||||
Parallel.For(0, 40, i =>
|
||||
{
|
||||
try
|
||||
{
|
||||
fs.StoreMsg($"big.{i % 4}", null, payload, 0).Seq.ShouldBeGreaterThan(0UL);
|
||||
var sm = fs.LoadLastMsg($"big.{i % 4}", null);
|
||||
sm.ShouldNotBeNull();
|
||||
sm!.Msg.Length.ShouldBe(payload.Length);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
errors.Enqueue(ex);
|
||||
}
|
||||
});
|
||||
|
||||
errors.ShouldBeEmpty();
|
||||
fs.State().Msgs.ShouldBeGreaterThan(0UL);
|
||||
});
|
||||
}
|
||||
|
||||
[Fact] // T:2384
|
||||
public void NoRaceAcceptLoopsDoNotLeaveOpenedConn_ShouldSucceed()
|
||||
{
|
||||
var errors = new ConcurrentQueue<Exception>();
|
||||
|
||||
Parallel.For(0, 20, _ =>
|
||||
{
|
||||
TcpListener? listener = null;
|
||||
TcpClient? client = null;
|
||||
TcpClient? accepted = null;
|
||||
|
||||
try
|
||||
{
|
||||
listener = new TcpListener(IPAddress.Loopback, 0);
|
||||
listener.Start();
|
||||
var endpoint = (IPEndPoint)listener.LocalEndpoint;
|
||||
|
||||
var acceptTask = listener.AcceptTcpClientAsync();
|
||||
client = new TcpClient();
|
||||
client.Connect(endpoint.Address, endpoint.Port);
|
||||
accepted = acceptTask.GetAwaiter().GetResult();
|
||||
|
||||
accepted.Connected.ShouldBeTrue();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
errors.Enqueue(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
accepted?.Close();
|
||||
client?.Close();
|
||||
listener?.Stop();
|
||||
}
|
||||
});
|
||||
|
||||
errors.ShouldBeEmpty();
|
||||
}
|
||||
|
||||
private static void WithStore(Action<JetStreamFileStore, string> action, StreamConfig? cfg = null)
|
||||
{
|
||||
var root = NewRoot();
|
||||
|
||||
Reference in New Issue
Block a user