public void OnlyOneWorker_TriggerThroughQueue() { var dispatcher = new AsyncHandler(1); var state1 = new DispatchCommand(new FakeCommand()); var state2 = new DispatchCommand(new FakeCommand()); var evt = new ManualResetEvent(false); var context = new DownContext(x => evt.WaitOne(), null); dispatcher.HandleDownstream(context, state1); Assert.True(context.WaitDown(TimeSpan.FromMilliseconds(50))); context.ResetDown(); dispatcher.HandleDownstream(context, state2); Assert.False(context.WaitDown(TimeSpan.FromMilliseconds(50))); evt.Set(); Assert.True(context.WaitDown(TimeSpan.FromMilliseconds(50))); }
public void ShutDown_NoMoreDispatching() { var dispatcher = new AsyncHandler(2); var command = new FakeCommand(); var state = new DispatchCommand(command); var state2 = new DispatchCommand(new FakeCommand()); var context = new DownContext(null, null); // dispatch first and check that it's passed by properly dispatcher.HandleDownstream(context, state); Assert.True(context.WaitDown(TimeSpan.FromMilliseconds(50))); context.ResetDown(); dispatcher.Close(); dispatcher.HandleDownstream(context, state2); Assert.False(context.WaitDown(TimeSpan.FromMilliseconds(50))); }
public void TwoWorkers_DispatchTwoThreads() { var dispatcher = new AsyncHandler(2); var state1 = new DispatchCommand(new FakeCommand()); var state2 = new DispatchCommand(new FakeCommand()); var evt = new ManualResetEvent(false); var context = new DownContext(null, x => evt.WaitOne()); dispatcher.HandleDownstream(context, state1); Assert.True(context.WaitDown(TimeSpan.FromMilliseconds(100))); context.ResetDown(); dispatcher.HandleDownstream(context, state2); Assert.True(context.WaitDown(TimeSpan.FromMilliseconds(100))); }