Skip to content

Add mocked resilience tests exercising the Polly pipeline#393

Merged
ptr727 merged 2 commits into
developfrom
feature/resilience-mock-tests
Jul 10, 2026
Merged

Add mocked resilience tests exercising the Polly pipeline#393
ptr727 merged 2 commits into
developfrom
feature/resilience-mock-tests

Conversation

@ptr727

@ptr727 ptr727 commented Jul 10, 2026

Copy link
Copy Markdown
Owner

Summary

Adds deterministic, network-free tests that actually exercise the HttpClientFactory resilience pipeline (previously the factory tests only constructed clients). A stub HttpMessageHandler is swapped in as the resilience handler's inner transport, so the real Polly retry/circuit-breaker pipeline runs against scripted outcomes offline.

Covers the transient-classification logic in IsTransientFailure:

  • Transient status (500 -> 503 -> 200): retried, succeeds, handler called 3 times.
  • Non-transient status (404): not retried, handler called once.
  • Timeout (a cancellation carrying an inner TimeoutException): retried - validates that request timeouts are treated as transient.
  • Caller cancellation (a plain OperationCanceledException): not retried.

These deterministically confirm the timeout-vs-cancellation behavior without relying on CI network availability.

Notes

  • Re-adds a documented test-scoped CA2007 suppression to UtilitiesTests/.editorconfig: xUnit forbids ConfigureAwait in test methods (xUnit1030), so CA2007 is unsatisfiable in async test helpers (standard practice for test projects).
  • Test-only change - no library code or public API is modified, so the published package and the sibling integrations are unaffected.

Verification

  • dotnet build - 0 warnings / 0 errors.
  • dotnet test - 149 passed (+4).
  • dotnet format style --verify-no-changes clean.

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings July 10, 2026 18:45
@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 46.20%. Comparing base (405af67) to head (86237b7).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop     #393   +/-   ##
========================================
  Coverage    46.20%   46.20%           
========================================
  Files           13       13           
  Lines         1160     1160           
  Branches       107      107           
========================================
  Hits           536      536           
  Misses         593      593           
  Partials        31       31           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds deterministic, offline xUnit tests to exercise the HttpClientFactory resilience pipeline (Polly retry/circuit-breaker) against scripted HTTP outcomes, and updates test analyzer settings to avoid unsatisfiable async rules in xUnit tests.

Changes:

  • Add HttpClientFactoryResilienceTests that validate transient vs non-transient status handling and timeout-vs-caller-cancellation behavior through the real resilience handler.
  • Introduce a test-only StubHttpMessageHandler to provide scripted responses/exceptions and track attempt counts.
  • Disable CA2007 in UtilitiesTests to avoid conflict with xUnit’s ConfigureAwait guidance in test code.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
UtilitiesTests/HttpClientFactoryResilienceTests.cs Adds new deterministic tests and a stub transport to validate retry/transient classification in the resilience pipeline.
UtilitiesTests/.editorconfig Disables CA2007 for the test project to avoid conflict with xUnit analyzer guidance.

Comment thread UtilitiesTests/HttpClientFactoryResilienceTests.cs Outdated
Copilot AI review requested due to automatic review settings July 10, 2026 18:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@ptr727
ptr727 merged commit c3c7843 into develop Jul 10, 2026
12 checks passed
@ptr727
ptr727 deleted the feature/resilience-mock-tests branch July 10, 2026 18:56
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.

2 participants