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.
15 lines
388 B
C#
15 lines
388 B
C#
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;
|
|
}
|
|
}
|