Skip to content

Handle transient ConnectException globally in on-device HTTP tests#11057

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-flaky-connection-test
Draft

Handle transient ConnectException globally in on-device HTTP tests#11057
Copilot wants to merge 3 commits intomainfrom
copilot/fix-flaky-connection-test

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 30, 2026

Summary

Fixes a flaky test failure in AndroidMessageHandlerSendsClientCertificate caused by transient network connectivity issues when connecting to corefx-net-tls.azurewebsites.net.

Problem

The test Xamarin.Android.NetTests.AndroidMessageHandlerTests.AndroidMessageHandlerSendsClientCertificate(False) fails intermittently with:

System.AggregateException : AggregateException_ctor_DefaultMessage (Connection failure)
----> System.Net.Http.HttpRequestException : Connection failure
----> Java.Net.ConnectException : Failed to connect to corefx-net-tls.azurewebsites.net/104.40.28.133:443

This is a transient network error unrelated to the functionality being tested.

Fix

Added Java.Net.ConnectException handling to the global IgnoreIfConnectionFailed(HttpRequestException) method in HttpClientHandlerTestBase, following the same pattern as the existing IOException check added in commit 1047b55. This ensures all on-device HTTP tests that use the shared helper methods (RunIgnoringNetworkIssues, ConnectIgnoreFailure, IgnoreIfConnectionFailed) automatically benefit from the new check. No per-test changes are needed.

…Certificate test

Agent-Logs-Url: https://github.com/dotnet/android/sessions/1a564216-e64a-43b1-8ce0-919d7bae7020

Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Comment on lines +290 to +296
HttpResponseMessage response;
try {
response = await client.GetAsync ("https://corefx-net-tls.azurewebsites.net/EchoClientCertificate.ashx");
} catch (HttpRequestException ex) when (ex.InnerException is Java.Net.ConnectException) {
Assert.Inconclusive ($"Ignoring transient connection failure: {ex.InnerException.Message}");
return;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@copilot are you fixing this the right way?

Can we do something similar to what was done here in a global spot for all tests?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point. Reworked in 78ee6e0 — moved the Java.Net.ConnectException check into the global IgnoreIfConnectionFailed(HttpRequestException) in HttpClientHandlerTestBase (same pattern as the IOException check from 1047b55). The test now delegates to IgnoreIfConnectionFailed via new AggregateException(ex) so all tests benefit from the new check.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@copilot should you undo the changes in this file then?!?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, reverted in c2364a0. The only change now is the Java.Net.ConnectException check in the global IgnoreIfConnectionFailed(HttpRequestException) in HttpClientHandlerTestBase.

…iled helper

Agent-Logs-Url: https://github.com/dotnet/android/sessions/b5e86868-a3b2-488b-ab9c-1f1f9f832db4

Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Copilot AI changed the title Handle transient ConnectException in AndroidMessageHandlerSendsClientCertificate test Handle transient ConnectException globally in on-device HTTP tests Mar 30, 2026
Copilot AI requested a review from jonathanpeppers March 30, 2026 21:16
… global fix

Agent-Logs-Url: https://github.com/dotnet/android/sessions/1146d37f-4036-4a89-91ba-6ca76a3adb27

Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
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