From 92168043b8c005a30fcecd383d998d119cb99c68 Mon Sep 17 00:00:00 2001 From: Manuel de la Pena Date: Mon, 10 Jun 2019 22:40:31 +0200 Subject: [PATCH 1/2] [Tests] If there are network issues do not set the tests as a failure. We do have a test that fails when there are issues accessing the remote resource. If an error is raised, rather than setting the tests as an error, set them to inconclusive with the message of the error. Related issue: https://github.com/xamarin/maccore/issues/1725 --- tests/monotouch-test/Foundation/NSDataTest.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/monotouch-test/Foundation/NSDataTest.cs b/tests/monotouch-test/Foundation/NSDataTest.cs index ef1b51873a77..ab9db7fc9207 100644 --- a/tests/monotouch-test/Foundation/NSDataTest.cs +++ b/tests/monotouch-test/Foundation/NSDataTest.cs @@ -155,9 +155,14 @@ public void Https () Assert.Ignore ("NSData.FromUrl doesn't seem to work in watchOS"); } #endif + NSError error; using (var url = new NSUrl ("https://www.microsoft.com/robots.txt")) - using (var x = NSData.FromUrl (url)) { - Assert.That ((x != null) && (x.Length > 0)); + using (var x = NSData.FromUrl (url, NSDataReadingOptions.Uncached, out error)) { + if (error != null) { + Assert.Inconclusive ($"Could not access url error is '{error.Description}'"); + } else { + Assert.That ((x != null) && (x.Length > 0)); + } } } From 283558da5ec8b709b676adce4ddb43da2efc611f Mon Sep 17 00:00:00 2001 From: Manuel de la Pena Date: Tue, 11 Jun 2019 17:42:12 +0200 Subject: [PATCH 2/2] Use a list of urls to try several times. --- tests/monotouch-test/Foundation/NSDataTest.cs | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/tests/monotouch-test/Foundation/NSDataTest.cs b/tests/monotouch-test/Foundation/NSDataTest.cs index ab9db7fc9207..43219fc3a1ae 100644 --- a/tests/monotouch-test/Foundation/NSDataTest.cs +++ b/tests/monotouch-test/Foundation/NSDataTest.cs @@ -155,15 +155,27 @@ public void Https () Assert.Ignore ("NSData.FromUrl doesn't seem to work in watchOS"); } #endif - NSError error; - using (var url = new NSUrl ("https://www.microsoft.com/robots.txt")) - using (var x = NSData.FromUrl (url, NSDataReadingOptions.Uncached, out error)) { - if (error != null) { - Assert.Inconclusive ($"Could not access url error is '{error.Description}'"); - } else { - Assert.That ((x != null) && (x.Length > 0)); + // we have network issues, try several urls, if one works, be happy, else fail + var urls = new string [] { + "https://www.microsoft.com/robots.txt", + "https://www.xamarin.com/robots.txt", + "http://www.bing.com/robots.txt", + "https://www.xbox.com/robots.txt", + "https://www.msn.com/robots.txt", + "https://visualstudio.microsoft.com/robots.txt", + }; + for (var i = 0; i < urls.Length; i++) { + NSError error; + using (var nsUrl = new NSUrl (urls [i])) + using (var x = NSData.FromUrl (nsUrl, NSDataReadingOptions.Uncached, out error)) { + if (error != null) + continue; + Assert.That (x != null); + Assert.That (x.Length > 0); + return; } } + Assert.Fail ("None of the urls could be fetch."); } [Test]