test: resolve xUnit analyzer warnings for a warning-free build - #3
Merged
Merged
Conversation
The test project emitted 154 xUnit1051 warnings ("Calls to methods which accept
CancellationToken should use TestContext.Current.CancellationToken") plus 3
xUnit1031 warnings (blocking .Result access). The library already built clean,
but the repo convention is zero compiler warnings across the solution.
- Pass TestContext.Current.CancellationToken to every flagged call
(HttpClient GetAsync/PostAsync, Task.Delay, content ReadAs*Async,
ICacheStore GetAsync/SetAsync/RemoveAsync, RequestCoalescer.ExecuteAsync),
including calls whose argument list spans multiple lines.
- Replace blocking Task.Result access with awaited results in
ConditionalRequestCoalescingTests.
Only the flagged call sites were touched, so calls that already pass a token
(e.g. Task.Delay(delay, ct) inside test helper stubs) are unchanged. No library
code modified. Full solution now builds with 0 warnings / 0 errors; all 343
tests pass.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
What & why
The library project already built clean, but the test project emitted 157 analyzer warnings, so the solution as a whole was never warning-free — against the repo convention of zero compiler warnings.
xUnit1051— "Calls to methods which accept CancellationToken should useTestContext.Current.CancellationToken"xUnit1031— blockingTask.Resultaccess in a test methodChanges
Passed
TestContext.Current.CancellationTokento every flagged call across 19 test files:HttpClient.GetAsync/PostAsync,Task.Delay, contentReadAsStringAsync/ReadAsByteArrayAsync/ReadFromJsonAsync,ICacheStore.GetAsync/SetAsync/RemoveAsync, andRequestCoalescer.ExecuteAsync— including calls whose argument list spans multiple lines around a lambda.Replaced the blocking
Task.Resultaccesses inConditionalRequestCoalescingTestswith awaited results (which also made the precedingTask.WhenAllredundant).Notes for reviewer
Task.Delay(delay, ct)inside test helper stubs) are untouched.Caching/StaleWhileRevalidateTests.cs:57(gate.Task.GetAwaiter().GetResult()). It sits in a synchronous stub-handler lambda rather than a test method, soxUnit1031does not apply, and it is load-bearing: it deliberately blocks the background stale-while-revalidate call so the test can assert the stale response is served immediately. The zero warning count is genuine, not achieved by suppression.Verification
--no-incrementalrebuild of the full solution: 0 warnings, 0 errors (xUnit1031: 0,xUnit1051: 0).🤖 Generated with Claude Code