Repository navigation
test: make the mid-flight cancellation test cover every line deterministically - #383
Merged
Merged
Conversation
…istically 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 <noreply@anthropic.com>
Chris-Wolfgang
added a commit
that referenced
this pull request
Sep 27, 2026
…dent #383's reorder only narrowed the race: on macOS ARM64 the cancel could still land between TrySetResult and ThrowIfCancellationRequested, so the `while (true)` loop-back never ran and RunAsyncActionTests measured 98.9% (PR #391, run 36322172822, Stage 3). The action is now straight-line: signal started, block on the token's WaitHandle (10 s timeout), record whether cancellation was seen, then an unconditional `throw` of OperationCanceledException(token). No loop, and no reachable normal exit for the compiler to emit a closing-brace sequence point for. The test still proves the action was running, observed the cancellation (WaitOne returns true only once the token is cancelled, now asserted), and that RunAsync propagated the OperationCanceledException. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Chris-Wolfgang
added a commit
that referenced
this pull request
Sep 27, 2026
…tressTests (#391) * test(concurrency): clear the seven InspectCode alerts in ConcurrencyStressTests - AccessToModifiedClosure: the invocation counters are StrongBox<int>, so the lambdas capture a reference that never changes; the count is only touched through Interlocked / Volatile on .Value. - AsyncFixer06: Record.ExceptionAsync(async () => await call) instead of an implicit Task<Result> -> Task lambda conversion. - xUnit1031: no blocking call.Result; the completed call is awaited once (only when it did not throw) and the assertion reads that value. Same invariants; both race outcomes still observed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: make the mid-flight cancellation test's coverage timing-independent #383's reorder only narrowed the race: on macOS ARM64 the cancel could still land between TrySetResult and ThrowIfCancellationRequested, so the `while (true)` loop-back never ran and RunAsyncActionTests measured 98.9% (PR #391, run 36322172822, Stage 3). The action is now straight-line: signal started, block on the token's WaitHandle (10 s timeout), record whether cancellation was seen, then an unconditional `throw` of OperationCanceledException(token). No loop, and no reachable normal exit for the compiler to emit a closing-brace sequence point for. The test still proves the action was running, observed the cancellation (WaitOne returns true only once the token is cancelled, now asserted), and that RunAsync propagated the OperationCanceledException. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Sep 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The first PR run on the new 100% test-assembly gate (#379) was run 36285791752 on #381. It passed Stage 1 (Linux) and Stage 2 (Windows) but failed Stage 3 (macOS ARM64):
Wolfgang.TryPattern.Tests.Unitcame out at 99%, withRunAsyncActionTestsat 97.9%.Cause: a race in
RunAsync_Action_CancellationToken_when_cancellation_is_requested_after_action_started_the_action_is_cancelled. The action signalledactionStartedbefore entering its loop, and the test cancels as soon as it sees that signal. On a fast runner the cancel lands before the firstThrowIfCancellationRequested(), the action throws immediately, andTask.Delay(10).Wait();never runs. That's one line of about 48, exactly the 97.9%. So coverage depended on thread timing, and the gate turns that into a flaky failure on every PR.Fix: the action now signals after a full pass of the loop body (delay → signal → check), so every line runs before the test can cancel. The test still asserts the same thing: the call throws
OperationCanceledException, and the action observed the cancellation.Verification
dotnet build -c Release -p:TreatWarningsAsErrors=true: 0 errors.Wolfgang.TryPattern.Tests.Unit100%, no class under 100%.tests/for the same signal-then-loop pattern and this was the only instance.Until this merges, Stage 3 will fail intermittently on every PR (it depends on timing). Merge this first.
Refs #310
🤖 Generated with Claude Code