Repository navigation
test(concurrency): clear the seven InspectCode alerts in ConcurrencyStressTests - #391
Merged
Merged
Conversation
…tressTests - 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>
…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>
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
All 7 open code-scanning alerts are InspectCode warnings in the
ConcurrencyStressTests.csadded by #376. Each is a real finding, fixed rather than suppressed:AccessToModifiedClosureStrongBox<int>, so each lambda captures a reference that never changes. The count is only touched throughInterlocked.Increment(ref box.Value)/Volatile.Read(ref box.Value).AsyncFixer06Record.ExceptionAsync(async () => await call)replaces the implicitTask<Result>→Tasklambda conversion.xUnit1031call.Result. When the call didn't throw it is awaited once (thrown is null ? await call : null), and the assertion pattern-matches that value (result is { Succeeded: true, Value: 42 }).The test invariants are unchanged.
Verification
jb inspectcode TryPattern.sln --severity=WARNING --no-buildafter a solution build):origin/main's file: exactly the 7 CI findings (same rules, same lines);dotnet build -c Release -p:TreatWarningsAsErrors=true: 0 errors.STRESS_ITERATIONS=20000. Both race outcomes still occur: the cancel won 36/100 and 2/100 rounds.Wolfgang.TryPattern.Tests.Concurrencystill at 100%, so it passes the new test-assembly gate.Also: the macOS coverage flake (second commit)
The first CI run failed only Stage 3 (macOS ARM64):
Tests.Unitat 99%, withRunAsyncActionTestsat 98.9% and line 256, thewhile (true)loop-back, uncovered in both macOS reports. #383's reorder only narrowed the race: the cancel could still land betweenTrySetResultandThrowIfCancellationRequested(), so the loop never went round a second time.The action in
RunAsync_Action_CancellationToken_when_cancellation_is_requested_after_action_started_the_action_is_cancelledis now straight-line:WaitHandle(10 s timeout, so a missing cancel fails instead of hanging);throw new OperationCanceledException(token).With no loop and no reachable normal exit, the compiler emits no closing-brace sequence point. A trailing
ThrowIfCancellationRequested()had left those braces uncovered on every run. The test still asserts thatRunAsyncpropagates theOperationCanceledException, and now also asserts that the action observed the cancellation.Verified: 200/200 repeated runs on net10.0.
RunAsyncActionTestshas no uncovered lines in any single-framework report (net48, net6.0–net10.0), so coverage no longer depends on timing. On the macOS framework set,Tests.Unitis at 100%.Closes #384
Closes #385
Closes #386
Closes #387
Closes #388
Closes #389
Closes #390
🤖 Generated with Claude Code