feat: create NATS.Server.TestUtilities with shared helpers
Add shared test utility library with TestPortAllocator.GetFreePort() and SocketTestHelper.ReadUntilAsync() to deduplicate helpers across test projects. This is the foundation for splitting the monolithic test project into feature-focused test projects.
This commit is contained in:
14
tests/NATS.Server.TestUtilities/TestPortAllocator.cs
Normal file
14
tests/NATS.Server.TestUtilities/TestPortAllocator.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace NATS.Server.TestUtilities;
|
||||
|
||||
public static class TestPortAllocator
|
||||
{
|
||||
public static int GetFreePort()
|
||||
{
|
||||
using var sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
sock.Bind(new IPEndPoint(IPAddress.Loopback, 0));
|
||||
return ((IPEndPoint)sock.LocalEndPoint!).Port;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user