diff options
author | Marek Safar <marek.safar@gmail.com> | 2013-05-29 13:02:00 +0400 |
---|---|---|
committer | Marek Safar <marek.safar@gmail.com> | 2013-05-29 13:02:53 +0400 |
commit | 02a3f41adffef32e6457d6d7b50d4784d8b003b2 (patch) | |
tree | 628b020fcf1569b7f668e0ab2f438f73fcebaa97 /mcs | |
parent | dcfebb9e96b057c19b3203c1b2f184a0a2840024 (diff) |
Run YieldAwaitable tests on default synchronization context. Fixes #12446
Diffstat (limited to 'mcs')
-rw-r--r-- | mcs/class/corlib/Test/System.Runtime.CompilerServices/YieldAwaitableTest.cs | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/mcs/class/corlib/Test/System.Runtime.CompilerServices/YieldAwaitableTest.cs b/mcs/class/corlib/Test/System.Runtime.CompilerServices/YieldAwaitableTest.cs index 752be984e5f..2ed377d1f56 100644 --- a/mcs/class/corlib/Test/System.Runtime.CompilerServices/YieldAwaitableTest.cs +++ b/mcs/class/corlib/Test/System.Runtime.CompilerServices/YieldAwaitableTest.cs @@ -91,13 +91,21 @@ namespace MonoTests.System.Runtime.CompilerServices } YieldAwaitable.YieldAwaiter a; + SynchronizationContext sc; [SetUp] public void Setup () { + sc = SynchronizationContext.Current; a = new YieldAwaitable ().GetAwaiter (); } + [TearDown] + public void TearDown () + { + SynchronizationContext.SetSynchronizationContext (sc); + } + [Test] public void IsCompleted () { @@ -121,6 +129,8 @@ namespace MonoTests.System.Runtime.CompilerServices public void OnCompleted_2 () { TaskScheduler scheduler = null; + SynchronizationContext.SetSynchronizationContext (null); + var mre = new ManualResetEvent (false); a.OnCompleted (() => { @@ -138,6 +148,7 @@ namespace MonoTests.System.Runtime.CompilerServices { var scheduler = new MyScheduler (); TaskScheduler ran_scheduler = null; + SynchronizationContext.SetSynchronizationContext (null); var t = Task.Factory.StartNew (() => { var mre = new ManualResetEvent (false); @@ -162,20 +173,13 @@ namespace MonoTests.System.Runtime.CompilerServices var mre = new ManualResetEvent (false); var context = new MyContext (); - var old = SynchronizationContext.Current; - try { - SynchronizationContext.SetSynchronizationContext (context); - a.OnCompleted (() => { - context_ran = SynchronizationContext.Current; - mre.Set (); - }); - - Assert.IsTrue (mre.WaitOne (1000), "#1"); - - } finally { - SynchronizationContext.SetSynchronizationContext (old); - } + SynchronizationContext.SetSynchronizationContext (context); + a.OnCompleted (() => { + context_ran = SynchronizationContext.Current; + mre.Set (); + }); + Assert.IsTrue (mre.WaitOne (1000), "#1"); Assert.IsNull (context_ran, "#2"); } } |