public void Should_result_in_no_waiting_actions_in_the_queue() { Fiber fiber = new ThreadFiber(); fiber.Add(() => Thread.Sleep(1000)); var called = new Future<bool>(); fiber.Add(() => called.Complete(true)); fiber.Shutdown(112.Seconds()); called.IsCompleted.ShouldBeTrue(); }
public void Should_result_in_no_waiting_actions_in_the_queue() { Fiber fiber = new ThreadFiber(); fiber.Add(() => Thread.Sleep(1000)); var called = new Future <bool>(); fiber.Add(() => called.Complete(true)); fiber.Shutdown(112.Seconds()); called.IsCompleted.ShouldBeTrue(); }
public void Using_the_load_generator_should_share_the_load() { Fiber thread1 = new ThreadFiber(); thread1.Add(() => { var generator1 = new LoadGenerator <FirstCommand, FirstResponse>(); generator1.Run(RemoteBus, LocalBus.Endpoint, Instances.Values.Select(x => x.DataBus), 100, x => new FirstCommand(x)); }); thread1.Shutdown(3.Minutes()); }
public void Should_properly_release_one_waiting_writer() { const int writerCount = 10; const int messageCount = 1000; var complete = new Future <bool>(); int total = 0; Fiber reader = new ThreadFiber(); try { Thread.Sleep(100); Stopwatch timer = Stopwatch.StartNew(); var writers = new List <Fiber>(); for (int i = 0; i < writerCount; i++) { Fiber fiber = new PoolFiber(); for (int j = 0; j < messageCount; j++) { fiber.Add(() => { SuperSleeper.Wait(1); reader.Add(() => { total++; if (total == writerCount * messageCount) { complete.Complete(true); } }); }); } writers.Add(fiber); } complete.WaitUntilCompleted(20.Seconds()).ShouldBeTrue(); timer.Stop(); Trace.WriteLine("Elapsed time: " + timer.ElapsedMilliseconds + "ms (expected " + writerCount * messageCount + ")"); } finally { reader.Stop(); } }
public void Should_properly_release_one_waiting_writer() { const int writerCount = 10; const int messageCount = 1000; var complete = new Future<bool>(); int total = 0; Fiber reader = new ThreadFiber(); try { Thread.Sleep(100); Stopwatch timer = Stopwatch.StartNew(); var writers = new List<Fiber>(); for (int i = 0; i < writerCount; i++) { Fiber fiber = new ThreadPoolFiber(); for (int j = 0; j < messageCount; j++) { fiber.Add(() => { SuperSleeper.Wait(1); reader.Add(() => { total++; if (total == writerCount*messageCount) complete.Complete(true); }); }); } writers.Add(fiber); } complete.WaitUntilCompleted(20.Seconds()).ShouldBeTrue(); timer.Stop(); Trace.WriteLine("Elapsed time: " + timer.ElapsedMilliseconds + "ms (expected " + writerCount*messageCount + ")"); } finally { reader.Stop(); } }