PoolManagerTestEventHandler.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. namespace Content.IntegrationTests;
  2. [SetUpFixture]
  3. public sealed class PoolManagerTestEventHandler
  4. {
  5. // This value is completely arbitrary.
  6. private static TimeSpan MaximumTotalTestingTimeLimit => TimeSpan.FromMinutes(20);
  7. private static TimeSpan HardStopTimeLimit => MaximumTotalTestingTimeLimit.Add(TimeSpan.FromMinutes(1));
  8. [OneTimeSetUp]
  9. public void Setup()
  10. {
  11. PoolManager.Startup();
  12. // If the tests seem to be stuck, we try to end it semi-nicely
  13. _ = Task.Delay(MaximumTotalTestingTimeLimit).ContinueWith(_ =>
  14. {
  15. // This can and probably will cause server/client pairs to shut down MID test, and will lead to really confusing test failures.
  16. 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");
  17. PoolManager.Shutdown();
  18. });
  19. // If ending it nicely doesn't work within a minute, we do something a bit meaner.
  20. _ = Task.Delay(HardStopTimeLimit).ContinueWith(_ =>
  21. {
  22. var deathReport = PoolManager.DeathReport();
  23. Environment.FailFast($"Tests took way too ;\n Death Report:\n{deathReport}");
  24. });
  25. }
  26. [OneTimeTearDown]
  27. public void TearDown()
  28. {
  29. PoolManager.Shutdown();
  30. }
  31. }