diff --git a/tests/monotouch-test/CoreAnimation/LayerTest.cs b/tests/monotouch-test/CoreAnimation/LayerTest.cs index 5cf0be59a801..8c689285b031 100644 --- a/tests/monotouch-test/CoreAnimation/LayerTest.cs +++ b/tests/monotouch-test/CoreAnimation/LayerTest.cs @@ -131,9 +131,11 @@ public void TestBug26532 () } catch (Exception e) { ex = e; } - }); + }) { + IsBackground = true, + }; thread.Start (); - thread.Join (); + Assert.That (thread.Join (TimeSpan.FromSeconds (10)), Is.True, "Thread.Join timed out"); var watch = new Stopwatch (); watch.Start (); @@ -181,7 +183,7 @@ public void TestCALayerDelegateDispose () IsBackground = true, }; t.Start (); - t.Join (); + Assert.That (t.Join (TimeSpan.FromSeconds (5)), Is.True, "Thread.Join timed out"); GC.Collect (); NSRunLoop.Main.RunUntil (NSDate.Now.AddSeconds (0.1)); diff --git a/tests/monotouch-test/CoreImage/CIKernelTests.cs b/tests/monotouch-test/CoreImage/CIKernelTests.cs index 87cf3717ede0..3376f816d7e0 100644 --- a/tests/monotouch-test/CoreImage/CIKernelTests.cs +++ b/tests/monotouch-test/CoreImage/CIKernelTests.cs @@ -153,9 +153,11 @@ public void CIKernel_BasicTest () } catch (Exception ex2) { ex = ex2; } - }); + }) { + IsBackground = true, + }; t.Start (); - t.Join (); + Assert.That (t.Join (TimeSpan.FromSeconds (30)), Is.True, "Thread.Join timed out"); if (ex is not null) throw ex; } diff --git a/tests/monotouch-test/Foundation/NSStreamTest.cs b/tests/monotouch-test/Foundation/NSStreamTest.cs index d6c441e6403a..ce64ceed03cd 100644 --- a/tests/monotouch-test/Foundation/NSStreamTest.cs +++ b/tests/monotouch-test/Foundation/NSStreamTest.cs @@ -63,7 +63,9 @@ public void ConnectToHost () return; } - var listenThread = new Thread (new ParameterizedThreadStart (DebugListener)); + var listenThread = new Thread (new ParameterizedThreadStart (DebugListener)) { + IsBackground = true, + }; listenThread.Start (listener); NSStream.CreatePairWithSocketToHost (new IPEndPoint (IPAddress.Loopback, port), out read, out write); read.Open (); @@ -74,7 +76,7 @@ public void ConnectToHost () Assert.That (read.Read (result, 5), Is.EqualTo ((nint) 5)); for (int i = 0; i < 5; i++) Assert.That (result [i], Is.EqualTo (send [i] * 10)); - listenThread.Join (); + Assert.That (listenThread.Join (TimeSpan.FromSeconds (10)), Is.True, "listenThread.Join timed out"); listener.Stop (); read.Close (); write.Close (); diff --git a/tests/monotouch-test/Foundation/NotificationCenter.cs b/tests/monotouch-test/Foundation/NotificationCenter.cs index cab2406ee854..adea6d9968d4 100644 --- a/tests/monotouch-test/Foundation/NotificationCenter.cs +++ b/tests/monotouch-test/Foundation/NotificationCenter.cs @@ -140,7 +140,7 @@ public void ThreadSafe () // OK, we're done now, time to stop. stopSignal.Set (); for (var i = 0; i < threadCount; i++) { - threads [i].Join (); + Assert.That (threads [i].Join (TimeSpan.FromSeconds (5)), Is.True, $"Thread {i} failed to join within 5 seconds"); } Assert.That (ex, Is.Null, "Exception"); } diff --git a/tests/monotouch-test/Foundation/ThreadTest.cs b/tests/monotouch-test/Foundation/ThreadTest.cs index 120d545ebc14..93028e29763b 100644 --- a/tests/monotouch-test/Foundation/ThreadTest.cs +++ b/tests/monotouch-test/Foundation/ThreadTest.cs @@ -40,7 +40,7 @@ public void GetEntryAssemblyReturnsOk () IsBackground = true, }; t.Start (); - t.Join (); + Assert.That (t.Join (TimeSpan.FromSeconds (5)), Is.True, "Thread.Join timed out"); Assert.That (rv, Is.EqualTo (0)); } diff --git a/tests/monotouch-test/Foundation/TimerTest.cs b/tests/monotouch-test/Foundation/TimerTest.cs index 7e7ad52f4db4..be39f8e5be9b 100644 --- a/tests/monotouch-test/Foundation/TimerTest.cs +++ b/tests/monotouch-test/Foundation/TimerTest.cs @@ -42,7 +42,7 @@ public void Bug17793 () thread.Start (); Assert.That (evt.Wait (TimeSpan.FromSeconds (5)), Is.True, "Not signalled twice in 5s"); - thread.Join (); + Assert.That (thread.Join (TimeSpan.FromSeconds (10)), Is.True, "Thread.Join timed out"); } } @@ -70,7 +70,7 @@ public void Bug2443 () thread.Start (); Assert.That (evt.Wait (TimeSpan.FromSeconds (5)), Is.True, "Not signalled twice in 5s"); - thread.Join (); + Assert.That (thread.Join (TimeSpan.FromSeconds (10)), Is.True, "Thread.Join timed out"); } } @@ -101,7 +101,7 @@ public void CreateTimer_NewSignature () Assert.That (evt.WaitOne (TimeSpan.FromSeconds (5)), Is.True, "WaitOne"); Assert.That (result, Is.True, "result"); - thread.Join (); + Assert.That (thread.Join (TimeSpan.FromSeconds (10)), Is.True, "Thread.Join timed out"); } } } diff --git a/tests/monotouch-test/ObjCRuntime/RegistrarTest.cs b/tests/monotouch-test/ObjCRuntime/RegistrarTest.cs index b1f2ef35a054..c72e97e531d4 100644 --- a/tests/monotouch-test/ObjCRuntime/RegistrarTest.cs +++ b/tests/monotouch-test/ObjCRuntime/RegistrarTest.cs @@ -2122,9 +2122,11 @@ public void BlockCollection () } catch (Exception e) { ex = e; } - }); + }) { + IsBackground = true, + }; thread.Start (); - thread.Join (); + Assert.That (thread.Join (TimeSpan.FromSeconds (30)), Is.True, "Thread.Join timed out"); GC.Collect (); GC.WaitForPendingFinalizers (); TestRuntime.RunAsync (TimeSpan.FromSeconds (30), () => { }, () => ObjCBlockTester.FreedBlockCount > initialFreedCount); diff --git a/tests/monotouch-test/ObjCRuntime/RuntimeTest.cs b/tests/monotouch-test/ObjCRuntime/RuntimeTest.cs index 0fc4318e3168..10a84df16946 100644 --- a/tests/monotouch-test/ObjCRuntime/RuntimeTest.cs +++ b/tests/monotouch-test/ObjCRuntime/RuntimeTest.cs @@ -198,7 +198,7 @@ public bool UsableUntilDeadImpl () IsBackground = true, }; t.Start (); - t.Join (); + Assert.That (t.Join (TimeSpan.FromSeconds (5)), Is.True, "Thread.Join timed out"); // Now we have a handle to an object that may be garbage collected at any time. int counter = 0; @@ -297,7 +297,7 @@ public void FinalizationRaceCondition () IsBackground = true }; thread.Start (); - thread.Join (); + Assert.That (thread.Join (TimeSpan.FromSeconds (5)), Is.True, "Thread.Join timed out"); var getter1 = new Func ((key) => dict [key] as NSString); var getter2 = new Func ((key) => dict [key] as NSString); @@ -555,9 +555,11 @@ public void ResurrectedObjectsDisposedTest (Type type) var t1 = new Thread (() => { for (int i = 0; i < objects.Length; i++) Messaging.bool_objc_msgSend_IntPtr_int (invokerClassHandle, Selector.GetHandle ("invokeMe:wait:"), objects [i], 0); - }); + }) { + IsBackground = true, + }; t1.Start (); - t1.Join (); + Assert.That (t1.Join (TimeSpan.FromSeconds (5)), Is.True, "Thread.Join timed out"); // Collect all those managed wrappers, and make sure their finalizers are executed. GC.Collect (); diff --git a/tests/monotouch-test/SystemConfiguration/NetworkReachabilityTest.cs b/tests/monotouch-test/SystemConfiguration/NetworkReachabilityTest.cs index 0c57a89ef086..d1ceeeb70e39 100644 --- a/tests/monotouch-test/SystemConfiguration/NetworkReachabilityTest.cs +++ b/tests/monotouch-test/SystemConfiguration/NetworkReachabilityTest.cs @@ -220,10 +220,12 @@ public void SetNotification_GCHandleFreed () // Dispose to ensure GCHandle is freed reachability.Dispose (); } - }); + }) { + IsBackground = true, + }; thread.Start (); - thread.Join (); + Assert.That (thread.Join (TimeSpan.FromSeconds (5)), Is.True, "Thread.Join timed out"); // Force garbage collection GC.Collect (); @@ -263,10 +265,12 @@ public void SetNotification_GCHandleFreedWithNull () // Store weak reference to track if object is collected weakRefs [i] = new WeakReference (reachability); } - }); + }) { + IsBackground = true, + }; thread.Start (); - thread.Join (); + Assert.That (thread.Join (TimeSpan.FromSeconds (5)), Is.True, "Thread.Join timed out"); // Force garbage collection GC.Collect ();