public void Schedule1000In1ms() { var queue = new SynchronousCommandQueue(); queue.Run(); var count = 0; var reset = new AutoResetEvent(false); Action one = delegate { count++; if (count == 1000) { reset.Set(); } }; using (var thread = new ThreadPoolScheduler()) { for (var i = 0; i < 1000; i++) { thread.Schedule(i, () => queue.Enqueue(one)); } Assert.IsTrue(reset.WaitOne(1200, false)); } }
public void TimeTilNext() { var queue = new SynchronousCommandQueue(); queue.Run(); Action action = () => Assert.Fail("Should not execute"); using (var timer = new ThreadPoolScheduler()) { long now = 0; long span = 0; timer.QueueEvent(new SingleEvent(500, () => queue.Enqueue(action), now)); Assert.IsTrue(timer.GetNextScheduledTime(ref span, 0)); Assert.AreEqual(500, span); Assert.IsTrue(timer.GetNextScheduledTime(ref span, 499)); Assert.AreEqual(1, span); Assert.IsFalse(timer.GetNextScheduledTime(ref span, 500)); Assert.AreEqual(0, span); } }