forked from space-syndicate/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoolManagerTestEventHandler.cs
35 lines (31 loc) · 1.35 KB
/
PoolManagerTestEventHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
namespace Content.IntegrationTests;
[SetUpFixture]
public sealed class PoolManagerTestEventHandler
{
// This value is completely arbitrary.
private static TimeSpan MaximumTotalTestingTimeLimit => TimeSpan.FromMinutes(20);
private static TimeSpan HardStopTimeLimit => MaximumTotalTestingTimeLimit.Add(TimeSpan.FromMinutes(1));
[OneTimeSetUp]
public void Setup()
{
PoolManager.Startup();
// 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();
}
}