Files
wwdpublic/Content.IntegrationTests/PoolManagerTestEventHandler.cs
VMSolidus 34af5566dd Fix Every Debug Test Fail (#1803)
# Description

Fuck the stupid "Tests kill themselves after a hardcoded time limit has
passed".

(cherry picked from commit 6a63c8744f462f041a121c7253a7689cf85a660b)
2025-02-28 16:22:53 +03:00

36 lines
1.4 KiB
C#

namespace Content.IntegrationTests;
[SetUpFixture]
public sealed class PoolManagerTestEventHandler
{
// This value is completely arbitrary.
private static TimeSpan MaximumTotalTestingTimeLimit => TimeSpan.FromMinutes(120);
private static TimeSpan HardStopTimeLimit => MaximumTotalTestingTimeLimit.Add(TimeSpan.FromMinutes(1));
[OneTimeSetUp]
public void Setup()
{
PoolManager.Startup(typeof(PoolManagerTestEventHandler).Assembly);
// If the tests seem to be stuck, we try to end it semi-nicely
_ = Task.Delay(MaximumTotalTestingTimeLimit).ContinueWith(_ =>
{
// This can and probably will cause server/client pairs to shut down MID test, and will lead to really confusing test failures.
TestContext.Error.WriteLine($"\n\n{nameof(PoolManagerTestEventHandler)}: ERROR: Tests are taking too long. Shutting down all tests. This may lead to weird failures/exceptions.\n\n");
PoolManager.Shutdown();
});
// If ending it nicely doesn't work within a minute, we do something a bit meaner.
_ = Task.Delay(HardStopTimeLimit).ContinueWith(_ =>
{
var deathReport = PoolManager.DeathReport();
Environment.FailFast($"Tests took way too ;\n Death Report:\n{deathReport}");
});
}
[OneTimeTearDown]
public void TearDown()
{
PoolManager.Shutdown();
}
}