diff options
author | Alexander Köplinger <alex.koeplinger@outlook.com> | 2016-01-29 18:51:02 +0300 |
---|---|---|
committer | Alexander Köplinger <alex.koeplinger@outlook.com> | 2016-01-29 18:51:02 +0300 |
commit | bf5947a0fd2b523c30833605ee69b2b041aa43f4 (patch) | |
tree | 51958eee9a369337d3b329d43bee59c0937de95f /mcs | |
parent | 02d4680c096b6fc343fbe6efd164e265ea319ffe (diff) |
[corlib] Improve CancellationTokenSource test
Get rid of the Thread.Sleep calls that are prone to timing issues.
Diffstat (limited to 'mcs')
-rw-r--r-- | mcs/class/corlib/Test/System.Threading/CancellationTokenSourceTest.cs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/mcs/class/corlib/Test/System.Threading/CancellationTokenSourceTest.cs b/mcs/class/corlib/Test/System.Threading/CancellationTokenSourceTest.cs index efd4683fd9a..3a80f5ae0d2 100644 --- a/mcs/class/corlib/Test/System.Threading/CancellationTokenSourceTest.cs +++ b/mcs/class/corlib/Test/System.Threading/CancellationTokenSourceTest.cs @@ -55,8 +55,10 @@ namespace MonoTests.System.Threading { int called = 0; var cts = new CancellationTokenSource (TimeSpan.FromMilliseconds (20)); - cts.Token.Register (() => called++); - Thread.Sleep (50); + var mre = new ManualResetEvent (false); + cts.Token.Register (() => { called++; mre.Set (); }); + + Assert.IsTrue (mre.WaitOne (1000), "Not called in 1000ms"); Assert.AreEqual (1, called, "#1"); } @@ -89,10 +91,12 @@ namespace MonoTests.System.Threading { int called = 0; var cts = new CancellationTokenSource (); - cts.Token.Register (() => called++); + var mre = new ManualResetEvent (false); + cts.Token.Register (() => { called++; mre.Set (); }); cts.CancelAfter (50); cts.Dispose (); - Thread.Sleep (100); + + Assert.IsFalse (mre.WaitOne (100), "Shouldn't have been called"); Assert.AreEqual (0, called, "#1"); } |