diff --git a/tests/Mono.Android-Tests/Xamarin.Android.Net/AndroidMessageHandlerTests.cs b/tests/Mono.Android-Tests/Xamarin.Android.Net/AndroidMessageHandlerTests.cs index c240ac94ccb..c462fc4ed20 100644 --- a/tests/Mono.Android-Tests/Xamarin.Android.Net/AndroidMessageHandlerTests.cs +++ b/tests/Mono.Android-Tests/Xamarin.Android.Net/AndroidMessageHandlerTests.cs @@ -39,20 +39,29 @@ protected override HttpMessageHandler CreateHandler () #if NET [Test] [TestCaseSource (nameof (DecompressionSource))] - [Retry (5)] + // Disabled because it doesn't exist in NUnitLite, uncomment when/if we switch to full NUnit + // When we can use it, replace all the Console.WriteLine calls with Assert.Warn + // [Retry (5)] public async Task Decompression (string urlPath, string encoding, string jsonFieldName) { // Catch all the exceptions and warn about them or otherwise [Retry] above won't work try { - DoDecompression (urlPath, encoding, jsonFieldName); + int count = 0; + // Remove the loop when [Retry] can be used + while (count < 5) { + if (await DoDecompression (urlPath, encoding, jsonFieldName)) { + return; + } + count++; + } } catch (Exception ex) { - Assert.Warn ("Unexpected exception thrown"); - Assert.Warn (ex.ToString ()); + Console.WriteLine ("Unexpected exception thrown"); + Console.WriteLine (ex.ToString ()); Assert.Fail ("Exception should have not been thrown"); } } - void DoDecompression (string urlPath, string encoding, string jsonFieldName) + async Task DoDecompression (string urlPath, string encoding, string jsonFieldName) { var handler = new AndroidMessageHandler { AutomaticDecompression = DecompressionMethods.All @@ -66,7 +75,9 @@ void DoDecompression (string urlPath, string encoding, string jsonFieldName) // we will sleep a short while before failing the test if (!response.IsSuccessStatusCode) { System.Threading.Thread.Sleep (1000); - Assert.Fail ($"Request ended with a failure error code: {response.StatusCode}"); + // Uncomment when we can use [Retry] + //Assert.Fail ($"Request ended with a failure error code: {response.StatusCode}"); + return false; } foreach (string enc in response.Content.Headers.ContentEncoding) { @@ -77,13 +88,15 @@ void DoDecompression (string urlPath, string encoding, string jsonFieldName) string responseBody = await response.Content.ReadAsStringAsync (); - Assert.Warn ("-- Retrieved JSON start"); - Assert.Warn (responseBody); - Assert.Warn ("-- Retrieved JSON end"); + Console.WriteLine ("-- Retrieved JSON start"); + Console.WriteLine (responseBody); + Console.WriteLine ("-- Retrieved JSON end"); Assert.IsTrue (responseBody.Length > 0, "Response was empty"); Assert.AreEqual (response.Content.Headers.ContentLength, responseBody.Length, "Retrieved data length is different than the one specified in the Content-Length header"); Assert.IsTrue (responseBody.Contains ($"\"{jsonFieldName}\"", StringComparison.OrdinalIgnoreCase), $"\"{jsonFieldName}\" should have been in the response JSON"); + + return true; } #endif