diff --git a/tests/linker/mac/LinkAnyTest.cs b/tests/linker/mac/LinkAnyTest.cs index 3d3750cb144a..ed75a48bc6b7 100644 --- a/tests/linker/mac/LinkAnyTest.cs +++ b/tests/linker/mac/LinkAnyTest.cs @@ -21,15 +21,27 @@ public void AES () } static bool waited; + static bool requestError; + static HttpStatusCode statusCode; + + // http://blogs.msdn.com/b/csharpfaq/archive/2012/06/26/understanding-a-simple-async-program.aspx // ref: https://bugzilla.xamarin.com/show_bug.cgi?id=7114 static async Task GetWebPageAsync () { - Task getWebPageTask = new HttpClient ().GetStringAsync ("http://msdn.microsoft.com"); - string content = await getWebPageTask; - waited = true; - bool success = !String.IsNullOrEmpty (content); - Assert.IsTrue (success, $"received {content.Length} bytes"); + // do not use GetStringAsync, we are going to miss useful data, such as the resul code + using (var client = new HttpClient ()) { + HttpResponseMessage response = await client.GetAsync ("http://example.com"); + if(!response.IsSuccessStatusCode) { + requestError = true; + statusCode = response.StatusCode; + } else { + string content = await response.Content.ReadAsStringAsync (); + waited = true; + bool success = !String.IsNullOrEmpty (content); + Assert.IsTrue (success, $"received {content.Length} bytes"); + } + } } [Test] @@ -40,7 +52,11 @@ public void GetWebPageAsyncTest () // we do not want the async code to get back to the AppKit thread, hanging the process SynchronizationContext.SetSynchronizationContext (null); GetWebPageAsync ().Wait (); - Assert.IsTrue (waited, "async/await worked"); + if (requestError) { + Assert.Inconclusive ($"Test cannot be trusted. Issues performing the request. Status code '{statusCode}'"); + } else { + Assert.IsTrue (waited, "async/await worked"); + } } finally { SynchronizationContext.SetSynchronizationContext (current_sc); }