From 5a9317027ff8ac49d16ff2f1377f84da844d7766 Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Thu, 3 Aug 2023 15:07:21 +1200 Subject: [PATCH] Warn on improperly disposed tests. (#18594) --- .github/workflows/build-test-debug.yml | 2 +- .github/workflows/build-test-release.yml | 2 +- Content.IntegrationTests/PoolManager.cs | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-test-debug.yml b/.github/workflows/build-test-debug.yml index 89abcee445..416955a644 100644 --- a/.github/workflows/build-test-debug.yml +++ b/.github/workflows/build-test-debug.yml @@ -51,7 +51,7 @@ jobs: shell: pwsh run: | $env:DOTNET_gcServer=1 - dotnet test --no-build --configuration DebugOpt Content.IntegrationTests/Content.IntegrationTests.csproj -- NUnit.ConsoleOut=0 + dotnet test --no-build --configuration DebugOpt Content.IntegrationTests/Content.IntegrationTests.csproj -- NUnit.ConsoleOut=0 NUnit.MapWarningTo=Failed ci-success: name: Build & Test Debug needs: diff --git a/.github/workflows/build-test-release.yml b/.github/workflows/build-test-release.yml index 07ce558fb0..9ff89d47e8 100644 --- a/.github/workflows/build-test-release.yml +++ b/.github/workflows/build-test-release.yml @@ -51,7 +51,7 @@ jobs: shell: pwsh run: | $env:DOTNET_gcServer=1 - dotnet test --configuration Tools --no-build Content.IntegrationTests/Content.IntegrationTests.csproj -- NUnit.ConsoleOut=0 + dotnet test --configuration Tools --no-build Content.IntegrationTests/Content.IntegrationTests.csproj -- NUnit.ConsoleOut=0 NUnit.MapWarningTo=Failed ci-success: name: Build & Test Release needs: diff --git a/Content.IntegrationTests/PoolManager.cs b/Content.IntegrationTests/PoolManager.cs index c66bc260d3..397a20950d 100644 --- a/Content.IntegrationTests/PoolManager.cs +++ b/Content.IntegrationTests/PoolManager.cs @@ -947,6 +947,10 @@ public sealed class PairTracker : IAsyncDisposable _testOut = testOut; } + // Convenience properties. + public RobustIntegrationTest.ServerIntegrationInstance Server => Pair.Server; + public RobustIntegrationTest.ClientIntegrationInstance Client => Pair.Client; + private async Task OnDirtyDispose() { var usageTime = UsageWatch.Elapsed; @@ -957,6 +961,10 @@ public sealed class PairTracker : IAsyncDisposable PoolManager.NoCheckReturn(Pair); var disposeTime = dirtyWatch.Elapsed; await _testOut.WriteLineAsync($"{nameof(DisposeAsync)}: Disposed pair {Pair.PairId} in {disposeTime.TotalMilliseconds} ms"); + + // Test pairs should only dirty dispose if they are failing. If they are not failing, this probably happened + // because someone forgot to clean-return the pair. + Assert.Warn("Test was dirty-disposed."); } private async Task OnCleanDispose()