From a59a67d0e4d87ff86fb8ea65d0c9449bec40d819 Mon Sep 17 00:00:00 2001 From: Jordan Dominion Date: Tue, 9 Jan 2024 21:52:30 -0500 Subject: [PATCH] Properly dispose test TCP listeners --- .../Live/TestLiveServer.cs | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/tests/Tgstation.Server.Tests/Live/TestLiveServer.cs b/tests/Tgstation.Server.Tests/Live/TestLiveServer.cs index 0a4b956cc8..91466db1d0 100644 --- a/tests/Tgstation.Server.Tests/Live/TestLiveServer.cs +++ b/tests/Tgstation.Server.Tests/Live/TestLiveServer.cs @@ -61,6 +61,16 @@ namespace Tgstation.Server.Tests.Live static readonly Lazy mainDDPort = new(() => FreeTcpPort(odDDPort.Value, odDMPort.Value, compatDMPort.Value, compatDDPort.Value)); static readonly Lazy mainDMPort = new(() => FreeTcpPort(odDDPort.Value, odDMPort.Value, compatDMPort.Value, compatDDPort.Value, mainDDPort.Value)); + static void InitializePorts() + { + _ = odDMPort.Value; + _ = odDDPort.Value; + _ = compatDMPort.Value; + _ = compatDDPort.Value; + _ = mainDDPort.Value; + _ = mainDMPort.Value; + } + readonly ServerClientFactory clientFactory = new (new ProductHeaderValue(Assembly.GetExecutingAssembly().GetName().Name, Assembly.GetExecutingAssembly().GetName().Version.ToString())); public static List GetEngineServerProcessesOnPort(EngineType engineType, ushort? port) @@ -162,7 +172,8 @@ namespace Tgstation.Server.Tests.Live } catch { - l.Stop(); + using (l) + l.Stop(); throw; } @@ -172,10 +183,9 @@ namespace Tgstation.Server.Tests.Live } finally { - foreach(var l in listeners) - { - l.Stop(); - } + foreach (var l in listeners) + using (l) + l.Stop(); } Console.WriteLine($"Allocated port: {result}"); @@ -1238,6 +1248,8 @@ namespace Tgstation.Server.Tests.Live using (var currentProcess = System.Diagnostics.Process.GetCurrentProcess()) Assert.AreEqual(ProcessPriorityClass.Normal, currentProcess.PriorityClass); + InitializePorts(); + var maximumTestMinutes = TestingUtils.RunningInGitHubActions ? 90 : 20; using var hardCancellationTokenSource = new CancellationTokenSource(TimeSpan.FromMinutes(maximumTestMinutes)); var hardCancellationToken = hardCancellationTokenSource.Token;