From 2bba67cf347ff00d3b39e3f5d13e19a45605f9eb Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Sat, 22 Aug 2026 11:21:14 +1000 Subject: [PATCH] Give the terminate tests a margin, without letting them stop failing Both asserted WaitForExit(1000) after terminating a process. One second is a bet on the runner being idle, and on a loaded two core Windows runner it is not: the pair went red on main, and a re-run with no code change went green. Widening alone would have been wrong for the non-windowed case. That FakeDiffTool sleeps five seconds and then exits by itself, so any wait past five seconds passes whether the process was terminated or merely ran out - the same trap LaunchAndKill was in. So that one also asserts the exit code: TryTerminateProcess passes -1 to TerminateProcess, and running out returns 0. The windowed case needs no such guard, since a windowed FakeDiffTool runs until something closes it. Waiting longer there cannot turn a failure into a pass. Checked by making TryTerminateProcess skip the terminate: both tests fail, one on the exit code and one on the wait. --- src/DiffEngine.Tests/WindowsProcessTests.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/DiffEngine.Tests/WindowsProcessTests.cs b/src/DiffEngine.Tests/WindowsProcessTests.cs index cd96a365..2fe17ede 100644 --- a/src/DiffEngine.Tests/WindowsProcessTests.cs +++ b/src/DiffEngine.Tests/WindowsProcessTests.cs @@ -142,8 +142,10 @@ public async Task TryTerminateProcess_WithWindowedProcess_GracefullyCloses() await Assert.That(result).IsTrue(); - // Verify process exited gracefully - await Assert.That(process.WaitForExit(1000)).IsTrue(); + // Generous, because the margin here is the runner's, not the product's: a windowed + // FakeDiffTool runs until something closes it, so waiting longer cannot turn a failure + // into a pass. One second was a bet on a two core runner being idle + await Assert.That(process.WaitForExit(30000)).IsTrue(); } finally { @@ -191,8 +193,12 @@ public async Task TryTerminateProcess_WithNonWindowedProcess_ForcefullyTerminate await Assert.That(result).IsTrue(); - // Verify process was terminated (should be immediate with forceful kill) - await Assert.That(process.WaitForExit(1000)).IsTrue(); + // Waiting longer is not enough on its own here: this FakeDiffTool sleeps five seconds + // and then exits by itself, so a wait past that passes whether it was terminated or + // simply ran out. The exit code is what tells those apart - TryTerminateProcess passes + // -1 to TerminateProcess, and running out returns 0 + await Assert.That(process.WaitForExit(30000)).IsTrue(); + await Assert.That(process.ExitCode).IsNotEqualTo(0); } finally {