Skip to content

[Mono.Android-Tests] Ignore temporary HTTP errors in async test methods. #9942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2025

Conversation

jpobst
Copy link
Contributor

@jpobst jpobst commented Mar 19, 2025

In the never-ending saga of trying to ignore temporary HTTP errors in Mono.Android-Tests test methods, our latest attempt uses Assert.Ignore. Behind the scenes, Assert.Ignore breaks out of a test by throwing NUnit.Framework.IgnoreException. However our very dated test runner doesn't seem to handle this exception properly when in an async Task test method, resulting in this test failure:

System.AggregateException : AggregateException_ctor_DefaultMessage (Ignoring network/server failure: ServiceUnavailable)
----> NUnit.Framework.IgnoreException : Ignoring network/server failure: ServiceUnavailable
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean )
   at System.Threading.Tasks.Task.Wait(Int32 , CancellationToken )
   at System.Threading.Tasks.Task.Wait()
   at NUnit.Framework.Internal.AsyncInvocationRegion.AsyncTaskInvocationRegion.WaitForPendingOperationsToComplete(Object invocationResult)
   at NUnit.Framework.Internal.Commands.TestMethodCommand.RunAsyncTestMethod(TestExecutionContext context)
--IgnoreException
   at NUnit.Framework.Assert.Ignore(String message, Object[] args)
   at NUnit.Framework.Assert.Ignore(String message)
   at Xamarin.Android.NetTests.AndroidHandlerTestBase.EnsureSuccessStatusCode(HttpResponseMessage response)
   at Xamarin.Android.NetTests.AndroidMessageHandlerTests.ServerCertificateCustomValidationCallback_Redirects()

For the 2 async Task tests we have, instead check if the HTTP status code indicates we should ignore the test, and if so, just exit the test early. It will show up as "Passed" instead of "Ignored", which isn't perfect, but better than "Failed".

@jpobst jpobst changed the title [Mono.Android-Tests] Ignore temporary HTTP errors in asnyc test methods. [Mono.Android-Tests] Ignore temporary HTTP errors in async test methods. Mar 19, 2025
@jpobst jpobst marked this pull request as ready for review March 19, 2025 22:20
@jpobst jpobst requested a review from jonpryor as a code owner March 19, 2025 22:20
@jpobst jpobst requested a review from pjcollins March 19, 2025 22:20
@jonpryor jonpryor merged commit 951e2be into main Mar 20, 2025
56 of 58 checks passed
@jonpryor jonpryor deleted the dev/jpobst/async-http-error branch March 20, 2025 16:36
@github-actions github-actions bot locked and limited conversation to collaborators Apr 20, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants