Skip to content

[tests] Fix flaky TestNSUrlSessionHandlerSendClientCertificate. Fixes #25240#25258

Merged
rolfbjarne merged 1 commit intomainfrom
dev/rolf/fix-flaky-client-cert-test
Apr 30, 2026
Merged

[tests] Fix flaky TestNSUrlSessionHandlerSendClientCertificate. Fixes #25240#25258
rolfbjarne merged 1 commit intomainfrom
dev/rolf/fix-flaky-client-cert-test

Conversation

@rolfbjarne
Copy link
Copy Markdown
Member

The test TestNSUrlSessionHandlerSendClientCertificate was flaky due to two issues:

  1. Missing upfront network check: EchoClientCertificateUrl was a plain field without AssertNetworkConnection(), unlike all other URLs in NetworkResources. When the external Azure server was unreachable, the test would attempt the request anyway instead of being skipped.

  2. Missing network error handling: When the request completed with a non-timeout network error (connection reset, HTTP 502, etc.), the test hard-failed on Assert.IsNull(ex) instead of being marked inconclusive. Other network-dependent tests in the file use IgnoreInCIIfBadNetwork(ex) for this purpose.

Fix:

  • Change EchoClientCertificateUrl to use AssertNetworkConnection() (consistent with other URLs)
  • Add IgnoreInCIIfBadNetwork(ex) before the assertion (consistent with other tests)

Fixes #25240

The test was flaky because:

1. EchoClientCertificateUrl was a plain field without an upfront network
   connectivity check (unlike all other URLs in NetworkResources), so the
   test would attempt the request even when the server was unreachable.

2. When the request completed with a non-timeout network error (e.g.,
   connection reset, HTTP 502), the test would hard-fail instead of being
   marked as inconclusive.

Fix both issues by:
- Changing EchoClientCertificateUrl to use AssertNetworkConnection() for
  an upfront reachability check (consistent with other URLs in the class).
- Adding IgnoreInCIIfBadNetwork(ex) before the assertion, matching the
  pattern used by other network-dependent tests in the file.

Fixes #25240

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 27, 2026 18:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Reduces CI flakiness in TestNSUrlSessionHandlerSendClientCertificate by ensuring the test is skipped/inconclusive under known-bad network conditions instead of hard-failing.

Changes:

  • Make NetworkResources.EchoClientCertificateUrl consistent with other network resources by routing it through AssertNetworkConnection (...).
  • Treat non-timeout network failures in TestNSUrlSessionHandlerSendClientCertificate as “bad network” in CI via TestRuntime.IgnoreInCIIfBadNetwork (ex) before asserting success.

Reviewed changes

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

File Description
tests/monotouch-test/System.Net.Http/NetworkResources.cs Ensures the client-certificate echo endpoint participates in the standard upfront network reachability/skip logic.
tests/monotouch-test/System.Net.Http/MessageHandlers.cs Marks CI failures due to transient/bad network as ignored/inconclusive rather than hard failures for this test.

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [PR Build #dede3df] Build passed (Build packages) ✅

Pipeline on Agent
Hash: dede3df436e5a02aa5cae7acd2e04abdd5dae41a [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [PR Build #dede3df] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: dede3df436e5a02aa5cae7acd2e04abdd5dae41a [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: dede3df436e5a02aa5cae7acd2e04abdd5dae41a [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [CI Build #dede3df] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: dede3df436e5a02aa5cae7acd2e04abdd5dae41a [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

🚀 [CI Build #dede3df] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 156 tests passed 🎉

Tests counts

✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 6 tests passed. Html Report (VSDrops) Download
✅ linker: All 44 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 11 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 15 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 12 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 11 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Ventura (13): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download

Linux Build Verification

Linux build succeeded

Pipeline on Agent
Hash: dede3df436e5a02aa5cae7acd2e04abdd5dae41a [PR build]

@rolfbjarne rolfbjarne enabled auto-merge (squash) April 28, 2026 07:15
@rolfbjarne rolfbjarne merged commit f61073b into main Apr 30, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CI Postmortem] Flaky: MonoTests.System.Net.Http.MessageHandlerTest.TestNSUrlSessionHandlerSendClientCertificate

4 participants