public void WaitForEventWithTimeout() { CountdownLatch countdown = new CountdownLatch(5); bool result = countdown.WaitOne(TimeSpan.FromMilliseconds(5)); Assert.IsFalse(result); }
public void WaitForEventWithTimeout() { TestTool.RunTasks(ThreadCount, () => { var countdown = new CountdownLatch(5); bool result = countdown.WaitOne(TimeSpan.FromMilliseconds(5)); Assert.IsFalse(result); }); }
public void ResetWaitForConsumers() { CountdownLatch countdown = new CountdownLatch(0); bool result = countdown.WaitOne(); Assert.IsTrue(result); countdown.Reset(5); result = countdown.WaitOne(TimeSpan.FromMilliseconds(5)); Assert.IsFalse(result); for (int i = 0; i < 5; i++) { ThreadPool.QueueUserWorkItem(delegate { countdown.Set(); }); } result = countdown.WaitOne(); Assert.IsTrue(result); }
public void ResetWaitForConsumers() { TestTool.RunTasks(ThreadCount, () => { var countdown = new CountdownLatch(0); var result = countdown.WaitOne(); Assert.IsTrue(result); countdown.Reset(5); result = countdown.WaitOne(TimeSpan.FromMilliseconds(5)); Assert.IsFalse(result); for(var i = 0; i < 5; i++) { ThreadPool.QueueUserWorkItem(state => countdown.Set()); } result = countdown.WaitOne(); Assert.IsTrue(result); }); }
public void WaitForEventToRun() { int count = 5000; CountdownLatch countdown = new CountdownLatch(count); bool[] done = new bool[count]; for (int i = 0; i < count; i++) { int j = i; ThreadPool.QueueUserWorkItem(delegate { done[j] = true; countdown.Set(); }); } bool result = countdown.WaitOne(); Assert.IsTrue(result); for (int i = 0; i < count; i++) { Assert.IsTrue(done[i], "{0} was not set to true", i); } }
public void WaintForEventToRun() { const int count = 50; TestTool.RunTasks(ThreadCount, () => { var countdown = new CountdownLatch(count); var done = new bool[count]; for(int i = 0; i < count; i++) { var j = i; ThreadPool.QueueUserWorkItem(delegate { done[j] = true; countdown.Set(); }); } bool result = countdown.WaitOne(); Assert.IsTrue(result); for(var i = 0; i < count; i++) Assert.IsTrue(done[i], "{0} was not set to true", i); }); }