From 9f152d9754b30dccaf12925eebeb53f4b82dceaa Mon Sep 17 00:00:00 2001 From: Erik Date: Tue, 19 May 2026 12:08:51 +0200 Subject: [PATCH] test(diagnostics): restore RenderingDiagnostics state in try/finally Final code review of Phase 1 flagged that the three flag-mutating tests leaked static state across test boundaries. Wrap each in try/finally that snapshots IndoorAll on entry and restores it on exit, matching the PhysicsDiagnosticsTests pattern at line 30-49. Tests now safe under parallel test runs + future additions. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../Rendering/RenderingDiagnosticsTests.cs | 80 +++++++++++++------ 1 file changed, 55 insertions(+), 25 deletions(-) diff --git a/tests/AcDream.Core.Tests/Rendering/RenderingDiagnosticsTests.cs b/tests/AcDream.Core.Tests/Rendering/RenderingDiagnosticsTests.cs index 8d020e5..f490b36 100644 --- a/tests/AcDream.Core.Tests/Rendering/RenderingDiagnosticsTests.cs +++ b/tests/AcDream.Core.Tests/Rendering/RenderingDiagnosticsTests.cs @@ -5,47 +5,77 @@ namespace AcDream.Core.Tests.Rendering; public sealed class RenderingDiagnosticsTests { + // Each flag-mutating test snapshots the IndoorAll state on entry and + // restores it via try/finally. RenderingDiagnostics is a process-wide + // static (env-var-initialized); without restoration a mutated state + // leaks into other tests + into parallel test runs. Mirrors the + // PhysicsDiagnosticsTests pattern at line 30-49. + [Fact] public void IndoorAll_True_TurnsAllFlagsOn() { - // Reset all flags off first to make the test deterministic - // regardless of env-var state on the test runner. - RenderingDiagnostics.ProbeIndoorWalkEnabled = false; - RenderingDiagnostics.ProbeIndoorLookupEnabled = false; - RenderingDiagnostics.ProbeIndoorUploadEnabled = false; - RenderingDiagnostics.ProbeIndoorXformEnabled = false; - RenderingDiagnostics.ProbeIndoorCullEnabled = false; + bool initial = RenderingDiagnostics.IndoorAll; + try + { + // Reset all flags off first to make the test deterministic + // regardless of env-var state on the test runner. + RenderingDiagnostics.ProbeIndoorWalkEnabled = false; + RenderingDiagnostics.ProbeIndoorLookupEnabled = false; + RenderingDiagnostics.ProbeIndoorUploadEnabled = false; + RenderingDiagnostics.ProbeIndoorXformEnabled = false; + RenderingDiagnostics.ProbeIndoorCullEnabled = false; - RenderingDiagnostics.IndoorAll = true; + RenderingDiagnostics.IndoorAll = true; - Assert.True(RenderingDiagnostics.ProbeIndoorWalkEnabled); - Assert.True(RenderingDiagnostics.ProbeIndoorLookupEnabled); - Assert.True(RenderingDiagnostics.ProbeIndoorUploadEnabled); - Assert.True(RenderingDiagnostics.ProbeIndoorXformEnabled); - Assert.True(RenderingDiagnostics.ProbeIndoorCullEnabled); - Assert.True(RenderingDiagnostics.IndoorAll); + Assert.True(RenderingDiagnostics.ProbeIndoorWalkEnabled); + Assert.True(RenderingDiagnostics.ProbeIndoorLookupEnabled); + Assert.True(RenderingDiagnostics.ProbeIndoorUploadEnabled); + Assert.True(RenderingDiagnostics.ProbeIndoorXformEnabled); + Assert.True(RenderingDiagnostics.ProbeIndoorCullEnabled); + Assert.True(RenderingDiagnostics.IndoorAll); + } + finally + { + RenderingDiagnostics.IndoorAll = initial; + } } [Fact] public void IndoorAll_False_TurnsAllFlagsOff() { - RenderingDiagnostics.IndoorAll = true; // start from all-on - RenderingDiagnostics.IndoorAll = false; + bool initial = RenderingDiagnostics.IndoorAll; + try + { + RenderingDiagnostics.IndoorAll = true; // start from all-on + RenderingDiagnostics.IndoorAll = false; - Assert.False(RenderingDiagnostics.ProbeIndoorWalkEnabled); - Assert.False(RenderingDiagnostics.ProbeIndoorLookupEnabled); - Assert.False(RenderingDiagnostics.ProbeIndoorUploadEnabled); - Assert.False(RenderingDiagnostics.ProbeIndoorXformEnabled); - Assert.False(RenderingDiagnostics.ProbeIndoorCullEnabled); - Assert.False(RenderingDiagnostics.IndoorAll); + Assert.False(RenderingDiagnostics.ProbeIndoorWalkEnabled); + Assert.False(RenderingDiagnostics.ProbeIndoorLookupEnabled); + Assert.False(RenderingDiagnostics.ProbeIndoorUploadEnabled); + Assert.False(RenderingDiagnostics.ProbeIndoorXformEnabled); + Assert.False(RenderingDiagnostics.ProbeIndoorCullEnabled); + Assert.False(RenderingDiagnostics.IndoorAll); + } + finally + { + RenderingDiagnostics.IndoorAll = initial; + } } [Fact] public void IndoorAll_OneOff_ReadsAsFalse() { - RenderingDiagnostics.IndoorAll = true; - RenderingDiagnostics.ProbeIndoorCullEnabled = false; // flip one off - Assert.False(RenderingDiagnostics.IndoorAll); + bool initial = RenderingDiagnostics.IndoorAll; + try + { + RenderingDiagnostics.IndoorAll = true; + RenderingDiagnostics.ProbeIndoorCullEnabled = false; // flip one off + Assert.False(RenderingDiagnostics.IndoorAll); + } + finally + { + RenderingDiagnostics.IndoorAll = initial; + } } [Theory]