Prevent round end test from leaking (#9342)

This commit is contained in:
wrexbe
2022-07-01 23:39:16 -07:00
committed by GitHub
parent 5d3b6aa8d6
commit 6e0e350e86
2 changed files with 75 additions and 53 deletions

View File

@@ -15,6 +15,8 @@ using Content.Shared.Maps;
using NUnit.Framework; using NUnit.Framework;
using Robust.Client; using Robust.Client;
using Robust.Server; using Robust.Server;
using Robust.Server.GameStates;
using Robust.Server.Player;
using Robust.Shared.Configuration; using Robust.Shared.Configuration;
using Robust.Shared.ContentPack; using Robust.Shared.ContentPack;
using Robust.Shared.Exceptions; using Robust.Shared.Exceptions;
@@ -213,52 +215,61 @@ public static class PoolManager
private static async Task<PairTracker> GetServerClientPair(PoolSettings poolSettings, string testMethodName) private static async Task<PairTracker> GetServerClientPair(PoolSettings poolSettings, string testMethodName)
{ {
var poolRetrieveTimeWatch = new Stopwatch(); Pair pair = null;
poolRetrieveTimeWatch.Start(); try
await TestContext.Out.WriteLineAsync("Getting server/client");
Pair pair;
if (poolSettings.MustBeNew)
{ {
await TestContext.Out.WriteLineAsync($"Creating, because must be new pair"); var poolRetrieveTimeWatch = new Stopwatch();
pair = await CreateServerClientPair(poolSettings); poolRetrieveTimeWatch.Start();
} await TestContext.Out.WriteLineAsync("Getting server/client");
else if (poolSettings.MustBeNew)
{
pair = GrabOptimalPair(poolSettings);
if (pair != null)
{ {
var canSkip = pair.Settings.CanFastRecycle(poolSettings); await TestContext.Out.WriteLineAsync($"Creating, because must be new pair");
pair = await CreateServerClientPair(poolSettings);
if (!canSkip)
{
await TestContext.Out.WriteLineAsync($"Cleaning existing pair");
await CleanPooledPair(poolSettings, pair);
}
else
{
await TestContext.Out.WriteLineAsync($"Skip cleanup pair");
}
} }
else else
{ {
await TestContext.Out.WriteLineAsync($"Creating, because pool empty"); pair = GrabOptimalPair(poolSettings);
pair = await CreateServerClientPair(poolSettings); if (pair != null)
{
var canSkip = pair.Settings.CanFastRecycle(poolSettings);
if (!canSkip)
{
await TestContext.Out.WriteLineAsync($"Cleaning existing pair");
await CleanPooledPair(poolSettings, pair);
}
else
{
await TestContext.Out.WriteLineAsync($"Skip cleanup pair");
}
}
else
{
await TestContext.Out.WriteLineAsync($"Creating, because pool empty");
pair = await CreateServerClientPair(poolSettings);
}
}
var poolRetrieveTime = poolRetrieveTimeWatch.Elapsed;
await TestContext.Out.WriteLineAsync(
$"Got server/client (id:{pair.PairId},uses:{pair.TestHistory.Count}) in {poolRetrieveTime.TotalMilliseconds} ms");
pair.Settings = poolSettings;
pair.TestHistory.Add(testMethodName);
var usageWatch = new Stopwatch();
usageWatch.Start();
return new PairTracker()
{
Pair = pair,
UsageWatch = usageWatch
};
}
finally
{
if (pair != null)
{
TestContext.Out.WriteLine($"Test History|\n{string.Join('\n', pair.TestHistory)}\n|Test History End");
} }
} }
var poolRetrieveTime = poolRetrieveTimeWatch.Elapsed;
await TestContext.Out.WriteLineAsync($"Got server/client (id:{pair.PairId},uses:{pair.TestHistory.Count}) in {poolRetrieveTime.TotalMilliseconds} ms");
pair.Settings = poolSettings;
TestContext.Out.WriteLine($"Test History|\n{string.Join('\n', pair.TestHistory)}\n|Test History End");
pair.TestHistory.Add(testMethodName);
var usageWatch = new Stopwatch();
usageWatch.Start();
return new PairTracker()
{
Pair = pair,
UsageWatch = usageWatch
};
} }
private static Pair GrabOptimalPair(PoolSettings poolSettings) private static Pair GrabOptimalPair(PoolSettings poolSettings)
@@ -314,15 +325,17 @@ public static class PoolManager
{ {
cNetMgr.ClientConnect(null!, 0, null!); cNetMgr.ClientConnect(null!, 0, null!);
}); });
await ReallyBeIdle(pair,11);
} }
await ReallyBeIdle(pair,11);
await TestContext.Out.WriteLineAsync($"Recycling: {methodWatch.Elapsed.TotalMilliseconds} ms: Disconnecting client, and restarting server"); await TestContext.Out.WriteLineAsync($"Recycling: {methodWatch.Elapsed.TotalMilliseconds} ms: Disconnecting client, and restarting server");
await pair.Client.WaitPost(() => await pair.Client.WaitPost(() =>
{ {
cNetMgr.ClientDisconnect("Test pooling cleanup disconnect"); cNetMgr.ClientDisconnect("Test pooling cleanup disconnect");
}); });
await ReallyBeIdle(pair, 5);
await ReallyBeIdle(pair, 10);
if (!string.IsNullOrWhiteSpace(pair.Settings.ExtraPrototypes)) if (!string.IsNullOrWhiteSpace(pair.Settings.ExtraPrototypes))
{ {
@@ -413,10 +426,7 @@ public static class PoolManager
var server = pairTracker.Pair.Server; var server = pairTracker.Pair.Server;
var settings = pairTracker.Pair.Settings; var settings = pairTracker.Pair.Settings;
if (settings.NoServer) throw new Exception("Cannot setup test map without server"); if (settings.NoServer) throw new Exception("Cannot setup test map without server");
var mapData = new TestMapData var mapData = new TestMapData();
{
};
await server.WaitPost(() => await server.WaitPost(() =>
{ {
var mapManager = IoCManager.Resolve<IMapManager>(); var mapManager = IoCManager.Resolve<IMapManager>();

View File

@@ -8,6 +8,7 @@ using NUnit.Framework;
using Robust.Shared.Configuration; using Robust.Shared.Configuration;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Network;
namespace Content.IntegrationTests.Tests namespace Content.IntegrationTests.Tests
{ {
@@ -17,10 +18,8 @@ namespace Content.IntegrationTests.Tests
[Test] [Test]
public async Task Test() public async Task Test()
{ {
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings() await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { NoClient = true });
{
NoClient = true,
});
var server = pairTracker.Pair.Server; var server = pairTracker.Pair.Server;
var config = server.ResolveDependency<IConfigurationManager>(); var config = server.ResolveDependency<IConfigurationManager>();
@@ -32,14 +31,13 @@ namespace Content.IntegrationTests.Tests
await server.WaitAssertion(() => await server.WaitAssertion(() =>
{ {
ticker.RestartRound();
config.SetCVar(CCVars.GameLobbyEnabled, true); config.SetCVar(CCVars.GameLobbyEnabled, true);
config.SetCVar(CCVars.EmergencyShuttleTransitTime, 1f); config.SetCVar(CCVars.EmergencyShuttleTransitTime, 1f);
config.SetCVar(CCVars.EmergencyShuttleDockTime, 1f); config.SetCVar(CCVars.EmergencyShuttleDockTime, 1f);
roundEndSystem.DefaultCooldownDuration = TimeSpan.FromMilliseconds(250); roundEndSystem.DefaultCooldownDuration = TimeSpan.FromMilliseconds(100);
roundEndSystem.DefaultCountdownDuration = TimeSpan.FromMilliseconds(500); roundEndSystem.DefaultCountdownDuration = TimeSpan.FromMilliseconds(300);
roundEndSystem.DefaultRestartRoundDuration = TimeSpan.FromMilliseconds(250); roundEndSystem.DefaultRestartRoundDuration = TimeSpan.FromMilliseconds(100);
}); });
await server.WaitAssertion(() => await server.WaitAssertion(() =>
@@ -114,6 +112,20 @@ namespace Content.IntegrationTests.Tests
if (timeout.IsCompleted) throw new TimeoutException("Event took too long to trigger"); if (timeout.IsCompleted) throw new TimeoutException("Event took too long to trigger");
} }
// Need to clean self up
await server.WaitAssertion(() =>
{
config.SetCVar(CCVars.GameLobbyEnabled, false);
config.SetCVar(CCVars.EmergencyShuttleTransitTime, CCVars.EmergencyShuttleTransitTime.DefaultValue);
config.SetCVar(CCVars.EmergencyShuttleDockTime, CCVars.EmergencyShuttleDockTime.DefaultValue);
roundEndSystem.DefaultCooldownDuration = TimeSpan.FromSeconds(30);
roundEndSystem.DefaultCountdownDuration = TimeSpan.FromMinutes(4);
roundEndSystem.DefaultRestartRoundDuration = TimeSpan.FromMinutes(1);
EntitySystem.Get<GameTicker>().RestartRound();
});
await PoolManager.ReallyBeIdle(pairTracker.Pair, 10);
await pairTracker.CleanReturnAsync(); await pairTracker.CleanReturnAsync();
} }
} }