Skip to content

test: resolve xUnit analyzer warnings for a warning-free build - #3

Merged
FranRuiz98 merged 1 commit into
masterfrom
test/resolve-xunit-analyzer-warnings
Jul 21, 2026
Merged

test: resolve xUnit analyzer warnings for a warning-free build#3
FranRuiz98 merged 1 commit into
masterfrom
test/resolve-xunit-analyzer-warnings

Conversation

@FranRuiz98

Copy link
Copy Markdown
Owner

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.

  • 154 × xUnit1051 — "Calls to methods which accept CancellationToken should use TestContext.Current.CancellationToken"
  • 3 × xUnit1031 — blocking Task.Result access in a test method

Changes

Passed TestContext.Current.CancellationToken to every flagged call across 19 test files:
HttpClient.GetAsync/PostAsync, Task.Delay, content ReadAsStringAsync/ReadAsByteArrayAsync/ReadFromJsonAsync, ICacheStore.GetAsync/SetAsync/RemoveAsync, and RequestCoalescer.ExecuteAsync — including calls whose argument list spans multiple lines around a lambda.

Replaced the blocking Task.Result accesses in ConditionalRequestCoalescingTests with awaited results (which also made the preceding Task.WhenAll redundant).

Notes for reviewer

  • Edits were driven off the analyzer's exact reported positions, not a blanket find/replace — so calls that already pass a token (e.g. Task.Delay(delay, ct) inside test helper stubs) are untouched.
  • No library code changed — test files only. The diff is 158 insertions / 157 deletions, almost entirely 1:1 line replacements.
  • One blocking call is intentionally left at Caching/StaleWhileRevalidateTests.cs:57 (gate.Task.GetAwaiter().GetResult()). It sits in a synchronous stub-handler lambda rather than a test method, so xUnit1031 does 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

  • Clean --no-incremental rebuild of the full solution: 0 warnings, 0 errors (xUnit1031: 0, xUnit1051: 0).
  • All 343 tests pass.

🤖 Generated with Claude Code

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>
@FranRuiz98
FranRuiz98 merged commit d7134ae into master Jul 21, 2026
2 checks passed
@FranRuiz98
FranRuiz98 deleted the test/resolve-xunit-analyzer-warnings branch July 21, 2026 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant