Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions tests/monotouch-test/Foundation/NSDataTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,27 @@ public void Https ()
Assert.Ignore ("NSData.FromUrl doesn't seem to work in watchOS");
}
#endif
using (var url = new NSUrl ("https://www.microsoft.com/robots.txt"))
using (var x = NSData.FromUrl (url)) {
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;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the test was to detect an error...
with that change I don't think you can trigger the 2nd assert (unless an empty file was present)
so basically the test can't fail (so it's not worth much)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spouliot we can check the domain of the error and decide what to do?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well.. thx Cocoa, we would get the not so useful "NSCocoaErrorDomain Code=256", which means an unknown error happened.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, a reachability (to host) error would be fine to ignore, but other errors would not be

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have used several company urls, lets hope trying several will work, else we can do an increasing timeout retry.

}
Assert.Fail ("None of the urls could be fetch.");
}

[Test]
Expand Down