Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,15 @@ protected void RunIgnoringNetworkIssues (Action runner, out bool connectionFaile
}
}

bool IgnoreIfConnectionFailed (AggregateException aex, out bool connectionFailed)
protected bool IgnoreIfConnectionFailed (AggregateException aex, out bool connectionFailed)
{
if (IgnoreIfConnectionFailed (aex.InnerException as HttpRequestException, out connectionFailed))
return true;

return IgnoreIfConnectionFailed (aex.InnerException as WebException, out connectionFailed);
if (IgnoreIfConnectionFailed (aex.InnerException as WebException, out connectionFailed))
return true;

return IgnoreIfSocketException (aex, out connectionFailed);
}

bool IgnoreIfConnectionFailed (HttpRequestException hrex, out bool connectionFailed)
Expand All @@ -145,6 +148,26 @@ bool IgnoreIfConnectionFailed (WebException wex, out bool connectionFailed)

return false;
}

bool IgnoreIfSocketException (Exception ex, out bool connectionFailed)
{
connectionFailed = false;
// Check the exception and all inner exceptions for transient socket errors
var current = ex;
while (current != null) {
if (current is Java.Net.SocketException socketEx) {
var message = socketEx.Message ?? "";
if (message.Contains ("Broken pipe", StringComparison.OrdinalIgnoreCase) ||
message.Contains ("Connection reset", StringComparison.OrdinalIgnoreCase)) {
connectionFailed = true;
Assert.Ignore ($"Ignoring transient socket error: {socketEx}");
return true;
}
}
current = current.InnerException;
}
return false;
}
}

[Category ("AndroidClientHandler")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,13 @@ public async Task HttpContentStreamIsRewoundAfterCancellation ()
try {
await client.SendAsync (request, tcs.Token).ConfigureAwait (false);
// If we get here without exception, that's also OK for this test
} catch (AggregateException ex) {
if (IgnoreIfConnectionFailed (ex, out _))
return;
// Expected - cancellation or connection error
// We catch all exceptions to ensure the test doesn't fail due to unhandled exceptions
Console.WriteLine ($"Exception during first request (expected): {ex}");
exceptionThrown = true;
} catch (Exception ex) {
// Expected - cancellation or connection error
// We catch all exceptions to ensure the test doesn't fail due to unhandled exceptions
Expand Down