Remove the use of ExpectedException in Mono.Posix Tests (#4698)
[mono.git] / mcs / class / Mono.Posix / Test / Mono.Unix / UnixSignalTest.cs
index 14613104d9b7c0198895e604cd4fbc5149329719..1516c51e3e5868fcc52dc72df252690d40d2d815 100644 (file)
@@ -8,21 +8,17 @@
 //
 
 using NUnit.Framework;
-#if !MONODROID
-using NUnit.Framework.SyntaxHelpers;
-#endif
+
 using System;
 using System.Text;
 using System.Threading;
 using Mono.Unix;
 using Mono.Unix.Android;
 using Mono.Unix.Native;
-#if !MONODROID
-namespace NUnit.Framework.SyntaxHelpers { class Dummy {} }
-#endif
+
 namespace MonoTests.Mono.Unix {
 
-       [TestFixture]
+       [TestFixture, Category ("NotOnWindows")]
        public class UnixSignalTest {
 
                // helper method to create a thread waiting on a UnixSignal
@@ -140,14 +136,16 @@ namespace MonoTests.Mono.Unix {
                }
 
                [Test]
-               [ExpectedException]
                [Category ("NotOnMac")]
                public void TestSignumPropertyThrows ()
                {
                        if (!TestHelper.CanUseRealTimeSignals ())
                                return;
-                       UnixSignal signal1 = new UnixSignal (new RealTimeSignum (0));
-                       Signum s = signal1.Signum;
+
+                       Assert.Throws<InvalidOperationException> (() => {
+                               UnixSignal signal1 = new UnixSignal (new RealTimeSignum (0));
+                               Signum s = signal1.Signum;
+                       });
                }
 
                [Test]
@@ -162,14 +160,16 @@ namespace MonoTests.Mono.Unix {
                }
        
                [Test]
-               [ExpectedException]
                [Category ("NotOnMac")]
                public void TestRealTimePropertyThrows ()
                {
                        if (!TestHelper.CanUseRealTimeSignals ())
-                               return;
-                       UnixSignal signal1 = new UnixSignal (Signum.SIGSEGV);
-                       RealTimeSignum s = signal1.RealTimeSignum;
+                                       return;
+
+                       Assert.Throws<InvalidOperationException> (() => {
+                               UnixSignal signal1 = new UnixSignal (Signum.SIGSEGV);
+                               RealTimeSignum s = signal1.RealTimeSignum;
+                       });
                }
 
                [Test]
@@ -424,6 +424,10 @@ namespace MonoTests.Mono.Unix {
                        foreach (Thread t in threads)
                                t.Join ();
                        AssertCountSet (usignals);
+                       // signal delivery might take some time, wait a bit before closing
+                       // the UnixSignal so we can ignore it and not terminate the process
+                       // when a SIGHUP/SIGTERM arrives afterwards
+                       Thread.Sleep (1000);
                        CloseSignals (usignals);
                }
 
@@ -456,6 +460,7 @@ namespace MonoTests.Mono.Unix {
                                s.Close ();
                }
 
+               // Create thread that issues many signals from a set of harmless signals
                static Thread CreateRaiseStormThread (int max)
                {
                        return new Thread (delegate () {
@@ -486,6 +491,7 @@ namespace MonoTests.Mono.Unix {
                        CloseSignals (usignals);
                }
 
+               // Create thread that repeatedly registers then unregisters signal handlers
                static Thread CreateSignalCreatorThread ()
                {
                        return new Thread (delegate () {
@@ -523,6 +529,7 @@ namespace MonoTests.Mono.Unix {
                        CloseSignals (usignals);
                }
 
+               // Create thread that blocks until at least one of the given signals is received
                static Thread CreateWaitAnyThread (params UnixSignal[] usignals)
                {
                        return new Thread (delegate () {