From 2efa7b64f5c04e6193d2b6475203cae62081e01d Mon Sep 17 00:00:00 2001 From: Manuel de la Pena Date: Mon, 11 Nov 2019 11:52:37 -0500 Subject: [PATCH 1/2] [Tests] If we have server errors. Mark test as inconclusive. If we are getting errors (500,401..) do not mark a link all test as a failure, but as inconclusive. Fixes: https://github.com/xamarin/maccore/issues/2056 --- tests/linker/mac/LinkAnyTest.cs | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/tests/linker/mac/LinkAnyTest.cs b/tests/linker/mac/LinkAnyTest.cs index 3d3750cb144a..e7146bc855cc 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://msdn.microsoft.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); } From f7fcc1334af378cb5b0231b7368fd9b000e206cd Mon Sep 17 00:00:00 2001 From: Manuel de la Pena Date: Tue, 12 Nov 2019 11:58:33 -0500 Subject: [PATCH 2/2] Update url. --- tests/linker/mac/LinkAnyTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/linker/mac/LinkAnyTest.cs b/tests/linker/mac/LinkAnyTest.cs index e7146bc855cc..ed75a48bc6b7 100644 --- a/tests/linker/mac/LinkAnyTest.cs +++ b/tests/linker/mac/LinkAnyTest.cs @@ -31,7 +31,7 @@ static async Task GetWebPageAsync () { // 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://msdn.microsoft.com"); + HttpResponseMessage response = await client.GetAsync ("http://example.com"); if(!response.IsSuccessStatusCode) { requestError = true; statusCode = response.StatusCode;