From d5349848cc23f1b4a6c59509e6c0cd5172cd606a Mon Sep 17 00:00:00 2001 From: Chris Wolfgang <210299580+Chris-Wolfgang@users.noreply.github.com> Date: Sat, 26 Sep 2026 21:48:20 -0400 Subject: [PATCH] test: make the mid-flight cancellation test cover every line deterministically RunAsync_Action_CancellationToken_when_cancellation_is_requested_after_ action_started signalled "started" before the loop, so a fast runner could cancel before the first `Task.Delay(10).Wait()`, leaving that line uncovered on some runs. With the 100% test-assembly gate (#379) that made Stage 3 (macOS ARM64) fail at 97.9% on PR #381's run 36285791752 while Linux and Windows passed. The action now signals after a full pass of the loop body, so every line executes before the test cancels. Co-Authored-By: Claude Opus 5.5 --- .../RunAsyncActionTests.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/Wolfgang.TryPattern.Tests.Unit/RunAsyncActionTests.cs b/tests/Wolfgang.TryPattern.Tests.Unit/RunAsyncActionTests.cs index c5d76e51..dc6d8a72 100644 --- a/tests/Wolfgang.TryPattern.Tests.Unit/RunAsyncActionTests.cs +++ b/tests/Wolfgang.TryPattern.Tests.Unit/RunAsyncActionTests.cs @@ -247,14 +247,17 @@ public async Task RunAsync_Action_CancellationToken_when_cancellation_is_request void Action() { - actionStarted.TrySetResult(true); - try { + // Signal "started" only after a full pass of the loop body, so + // every line runs before the test can cancel. Signalling first + // let a fast runner cancel before the first delay, leaving that + // line uncovered on some runs (97.9% on macOS ARM64). while (true) { - cts.Token.ThrowIfCancellationRequested(); Task.Delay(10).Wait(); + actionStarted.TrySetResult(true); + cts.Token.ThrowIfCancellationRequested(); } } catch (OperationCanceledException)