[corlib] Fix racy test
authorMarek Safar <marek.safar@gmail.com>
Tue, 24 Jun 2014 12:19:54 +0000 (14:19 +0200)
committerMarek Safar <marek.safar@gmail.com>
Tue, 24 Jun 2014 12:20:16 +0000 (14:20 +0200)
mcs/class/corlib/Test/System.Runtime.CompilerServices/TaskAwaiterTest.cs

index a403d5287e2d6af53add6c41d825a641bea42ae6..b8fd573a3662cbd5ce64f101a95b65e0422692c8 100644 (file)
@@ -102,6 +102,7 @@ namespace MonoTests.System.Runtime.CompilerServices
 
                string progress;
                SynchronizationContext sc;
+               ManualResetEvent mre;
 
                [SetUp]
                public void Setup ()
@@ -270,6 +271,7 @@ namespace MonoTests.System.Runtime.CompilerServices
                [Test]
                public void CompletionOnDifferentCustomSynchronizationContext ()
                {
+                       mre = new ManualResetEvent (false);
                        progress = "";
                        var syncContext = new SingleThreadSynchronizationContext ();
                        SynchronizationContext.SetSynchronizationContext (syncContext);
@@ -293,14 +295,18 @@ namespace MonoTests.System.Runtime.CompilerServices
                {
                        await Wait2 (ctx);
 
-                       progress += "2";
+                       if (mre.WaitOne (5000))
+                               progress += "2";
                }
 
                async Task Wait2 (SynchronizationContext ctx)
                {
                        await Task.Delay (10); // Force block suspend/return
 
-                       ctx.Post (l => progress += "3", null);
+                       ctx.Post (l => {
+                               progress += "3";
+                               mre.Set ();
+                       }, null);
 
                        progress += "1";