[Mono.Posix] Workaround signal raising behavior.
authorJonathan Pryor <jonpryor@vt.edu>
Fri, 1 Jun 2012 16:02:49 +0000 (12:02 -0400)
committerJonathan Pryor <jonpryor@vt.edu>
Fri, 1 Jun 2012 16:09:37 +0000 (12:09 -0400)
The effects of Stdlib.raise() aren't immediate on OS X. The result is
that UnixSignalTest.TestDispose1():

Stdlib.raise (Signum.SIGINT);
Assert.AreEqual (a.Count, 1);

_may_ fail depending on timing.

Insert some Thread.Sleep()s to try to allow the signal to propogate.

mcs/class/Mono.Posix/Test/Mono.Unix/UnixSignalTest.cs

index 6120907159b3f471b53537a8e3edd3122bd8d007..3098596b4b0becd52c8deda139b7408c1fa4efb7 100644 (file)
@@ -328,6 +328,7 @@ namespace MonoTests.Mono.Unix {
                        UnixSignal b = new UnixSignal (Signum.SIGINT);
 
                        Stdlib.raise (Signum.SIGINT);
+                       SleepUntilSignaled (a);
 
                        Assert.AreEqual (a.Count, 1);
                        Assert.AreEqual (b.Count, 1);
@@ -336,11 +337,21 @@ namespace MonoTests.Mono.Unix {
                        b.Reset ();
 
                        Stdlib.raise (Signum.SIGINT);
+                       SleepUntilSignaled (b);
                        Assert.AreEqual (b.Count, 1);
 
                        b.Close ();
                }
 
+               static void SleepUntilSignaled (UnixSignal s)
+               {
+                       for (int i = 0; i < 10; ++i) {
+                               if (s.Count > 0)
+                                       break;
+                               Thread.Sleep (100);
+                       }
+               }
+
                [Test]
                public void TestDispose2 ()
                {
@@ -348,6 +359,7 @@ namespace MonoTests.Mono.Unix {
                        UnixSignal b = new UnixSignal (Signum.SIGINT);
 
                        Stdlib.raise (Signum.SIGINT);
+                       SleepUntilSignaled (a);
 
                        Assert.AreEqual (a.Count, 1);
                        Assert.AreEqual (b.Count, 1);
@@ -356,6 +368,7 @@ namespace MonoTests.Mono.Unix {
                        a.Reset ();
 
                        Stdlib.raise (Signum.SIGINT);
+                       SleepUntilSignaled (a);
                        Assert.AreEqual (a.Count, 1);
 
                        a.Close ();