Skip to content

Instantly share code, notes, and snippets.

@rolfbjarne
Created July 22, 2016 17:29
Show Gist options
  • Save rolfbjarne/bba35c52548433a9d1373a5bfb30ae53 to your computer and use it in GitHub Desktop.
Save rolfbjarne/bba35c52548433a9d1373a5bfb30ae53 to your computer and use it in GitHub Desktop.
commit 7390836f6dda91c64a29ef5d2d97f73c7514cceb
Author: Rolf Bjarne Kvinge <[email protected]>
Date: Fri Jul 22 19:29:02 2016 +0200
[monotouch-test] Tweak UrlSessionTest.DownloadDataAsync to not crash the process if exceptions occur.
diff --git a/tests/monotouch-test/Foundation/UrlSessionTest.cs b/tests/monotouch-test/Foundation/UrlSessionTest.cs
index 94e8fae..caa6428 100644
--- a/tests/monotouch-test/Foundation/UrlSessionTest.cs
+++ b/tests/monotouch-test/Foundation/UrlSessionTest.cs
@@ -104,25 +104,32 @@ namespace MonoTouchFixtures.Foundation {
bool completed = false;
int failed_iteration = -1;
+ Exception ex = null;
TestRuntime.RunAsync (DateTime.Now.AddSeconds (30), async () => {
- for (int i = 0; i < 5; i++) {
- // Use the default configuration so we can make use of the shared cookie storage.
- var session = NSUrlSession.FromConfiguration (NSUrlSessionConfiguration.DefaultSessionConfiguration);
-
- var downloadUri = new Uri ("https://google.com");
- var downloadResponse = await session.CreateDownloadTaskAsync (downloadUri);
-
- var tempLocation = downloadResponse.Location;
- if (!File.Exists (tempLocation.Path)) {
- Console.WriteLine ("#{1} {0} does not exists", tempLocation, i);
- failed_iteration = i;
- break;
+ try {
+ for (int i = 0; i < 5; i++) {
+ // Use the default configuration so we can make use of the shared cookie storage.
+ var session = NSUrlSession.FromConfiguration (NSUrlSessionConfiguration.DefaultSessionConfiguration);
+
+ var downloadUri = new Uri ("https://google.com");
+ var downloadResponse = await session.CreateDownloadTaskAsync (downloadUri);
+
+ var tempLocation = downloadResponse.Location;
+ if (!File.Exists (tempLocation.Path)) {
+ Console.WriteLine ("#{1} {0} does not exists", tempLocation, i);
+ failed_iteration = i;
+ break;
+ }
}
+ } catch (Exception e) {
+ ex = e;
+ } finally {
+ completed = true;
}
- completed = true;
}, () => completed);
+ Assert.IsNull (ex, "Exception");
Assert.AreEqual (-1, failed_iteration, "Failed");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment