2 // TimerTest.cs - NUnit test cases for System.Threading.Timer
5 // Zoltan Varga (vargaz@freemail.hu)
7 // (C) 2004 Novell, Inc (http://www.novell.com)
10 using NUnit.Framework;
12 using System.Threading;
14 namespace MonoTests.System.Threading {
18 // This whole test seems to fail randomly. Either
19 // - It is relying on a race it might not win (that the timer code runs)
20 // - We have a very obscure bug with appdomains.
22 // Am going with door #1, but it would be nice to investigate this.
25 public class TimerTest : Assertion {
27 [Category ("NotWorking")]
28 public void TestDueTime ()
31 Timer t = new Timer (new TimerCallback (Callback), null, 200, Timeout.Infinite);
33 AssertEquals ("t0", 0, counter);
35 AssertEquals ("t1", 1, counter);
37 AssertEquals ("t2", 1, counter);
41 Assert ("t3", counter > 20);
46 [Category ("NotWorking")]
47 public void TestChange ()
50 Timer t = new Timer (new TimerCallback (Callback), null, 1, 1);
53 Assert ("t1", c > 20);
56 Assert ("t2", counter <= c + 6);
61 [Category ("NotWorking")]
62 public void TestZeroDueTime () {
65 Timer t = new Timer (new TimerCallback (Callback), null, 0, Timeout.Infinite);
67 AssertEquals (1, counter);
68 t.Change (0, Timeout.Infinite);
70 AssertEquals (2, counter);
75 [Category ("NotWorking")]
76 public void TestDispose ()
79 Timer t = new Timer (new TimerCallback (CallbackTestDispose), null, 10, 10);
86 AssertEquals (c, counter);
90 public void TestDispose2 ()
92 Timer t = new Timer (new TimerCallback (CallbackTestDispose), null, 10, 10);
98 [Category ("NotWorking")]
99 public void TestDisposeOnCallback () {
101 t1 = new Timer (new TimerCallback (CallbackTestDisposeOnCallback), null, 0, 10);
106 t1 = new Timer (new TimerCallback (CallbackTestDisposeOnCallback), null, 50, 0);
111 private void CallbackTestDisposeOnCallback (object foo)
113 if (++counter == 3) {
119 private void CallbackTestDispose (object foo)
124 private void Callback (object foo)