From dede3df436e5a02aa5cae7acd2e04abdd5dae41a Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Mon, 27 Apr 2026 20:27:29 +0200 Subject: [PATCH] [tests] Fix flaky TestNSUrlSessionHandlerSendClientCertificate test 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 https://github.com/dotnet/macios/issues/25240 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- tests/monotouch-test/System.Net.Http/MessageHandlers.cs | 1 + tests/monotouch-test/System.Net.Http/NetworkResources.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/monotouch-test/System.Net.Http/MessageHandlers.cs b/tests/monotouch-test/System.Net.Http/MessageHandlers.cs index bdea09aeb92a..03f759bdf6c6 100644 --- a/tests/monotouch-test/System.Net.Http/MessageHandlers.cs +++ b/tests/monotouch-test/System.Net.Http/MessageHandlers.cs @@ -703,6 +703,7 @@ public void TestNSUrlSessionHandlerSendClientCertificate () if (!done) { // timeouts happen in the bots due to dns issues, connection issues etc.. we do not want to fail Assert.Inconclusive ("Request timedout."); } else { + TestRuntime.IgnoreInCIIfBadNetwork (ex); Assert.IsNull (ex, "Exception wasn't expected."); X509Certificate2 certificate2 = X509CertificateLoader.LoadCertificate (global::System.Convert.FromBase64String (content)); Assert.AreEqual (certificate.Thumbprint, certificate2.Thumbprint); diff --git a/tests/monotouch-test/System.Net.Http/NetworkResources.cs b/tests/monotouch-test/System.Net.Http/NetworkResources.cs index 085a36039118..99fe7fc5c24f 100644 --- a/tests/monotouch-test/System.Net.Http/NetworkResources.cs +++ b/tests/monotouch-test/System.Net.Http/NetworkResources.cs @@ -13,7 +13,7 @@ public static class NetworkResources { public static string XamarinHttpUrl => AssertNetworkConnection ("http://dotnet.microsoft.com/apps/xamarin"); public static Uri XamarinUri => new Uri (XamarinUrl); public static string StatsUrl => AssertNetworkConnection ("https://api.imgur.com/2/stats"); - public static string EchoClientCertificateUrl = "https://corefx-net-tls.azurewebsites.net/EchoClientCertificate.ashx"; + public static string EchoClientCertificateUrl => AssertNetworkConnection ("https://corefx-net-tls.azurewebsites.net/EchoClientCertificate.ashx"); public static string [] HttpsUrls => new [] { MicrosoftUrl,