From a131fea124fec7b5b2a950183f3940c28edce6ab Mon Sep 17 00:00:00 2001 From: Jordan Dominion Date: Sat, 14 Sep 2024 16:49:15 -0400 Subject: [PATCH] Changing port allocation tactics for the millionth time --- .../Live/TestLiveServer.cs | 36 +++---------------- 1 file changed, 5 insertions(+), 31 deletions(-) diff --git a/tests/Tgstation.Server.Tests/Live/TestLiveServer.cs b/tests/Tgstation.Server.Tests/Live/TestLiveServer.cs index 1c17f587c0..597889e131 100644 --- a/tests/Tgstation.Server.Tests/Live/TestLiveServer.cs +++ b/tests/Tgstation.Server.Tests/Live/TestLiveServer.cs @@ -43,7 +43,6 @@ using Tgstation.Server.Host.Database; using Tgstation.Server.Host.Extensions; using Tgstation.Server.Host.Jobs; using Tgstation.Server.Host.System; -using Tgstation.Server.Host.Utils; using Tgstation.Server.Tests.Live.Instance; namespace Tgstation.Server.Tests.Live @@ -53,6 +52,7 @@ namespace Tgstation.Server.Tests.Live [TestCategory("RequiresDatabase")] public sealed class TestLiveServer { + const ushort InitialPort = 42069; public static readonly Version TestUpdateVersion = new(5, 11, 0); static readonly Lazy odDMPort = new(() => FreeTcpPort()); @@ -64,6 +64,7 @@ namespace Tgstation.Server.Tests.Live static void InitializePorts() { + tcpPortCounter = InitialPort; _ = odDMPort.Value; _ = odDDPort.Value; _ = compatDMPort.Value; @@ -156,38 +157,11 @@ namespace Tgstation.Server.Tests.Live return result; } + static ushort tcpPortCounter = InitialPort; + static ushort FreeTcpPort(params ushort[] usedPorts) { - ushort result; - var listeners = new List(); - - try - { - do - { - var l = new TcpListener(IPAddress.Any, 0); - l.Start(); - try - { - listeners.Add(l); - } - catch - { - using (l) - l.Stop(); - throw; - } - - result = (ushort)((IPEndPoint)l.LocalEndpoint).Port; - } - while (usedPorts.Contains(result) || result < 20000); - } - finally - { - foreach (var l in listeners) - using (l) - l.Stop(); - } + ushort result = tcpPortCounter++; Console.WriteLine($"Allocated port: {result}"); return result;