public void Stop_ManyTasks_StopAll() { var pipeline = ""; var target = new SmartThreadPoolTaskExecutor(); target.Timeout = TimeSpan.FromMilliseconds(1000); target.Add(() => { Thread.Sleep(5); pipeline += "1"; }); target.Add(() => { Thread.Sleep(5); pipeline += "2"; }); target.Add(() => { Thread.Sleep(5); pipeline += "3"; }); Parallel.Invoke( () => Assert.IsTrue(target.Start()), () => { Thread.Sleep(100); target.Stop(); }); }
public void Start_AnyTaskWithException_Exception() { var pipeline = ""; var target = new SmartThreadPoolTaskExecutor(); target.Add(() => { throw new Exception("1"); }); target.Add(() => { Thread.Sleep(5); pipeline += "2"; }); target.Add(() => { Thread.Sleep(5); pipeline += "3"; }); ExceptionAssert.IsThrowing(new Exception("1"), () => { target.Start(); }); }
public void Stop_Tasks_ShutdownCalled() { var pipeline = ""; var target = new SmartThreadPoolTaskExecutor(); target.Timeout = TimeSpan.FromMilliseconds(1000); target.Add(() => { Thread.Sleep(500); pipeline += "1"; }); target.Add(() => { Thread.Sleep(500); pipeline += "2"; }); target.Add(() => { Thread.Sleep(500); pipeline += "3"; }); Parallel.Invoke( () => target.Start(), () => { Thread.Sleep(100); target.Stop(); }); Assert.IsFalse(target.IsRunning); }
public void Start_Timeout_False() { var pipeline = "1"; var target = new SmartThreadPoolTaskExecutor(); target.Timeout = TimeSpan.FromMilliseconds(2); target.Add(() => { Thread.Sleep(10); pipeline += "2"; }); var actual = target.Start(); Assert.IsFalse(actual); }
public void Start_ManyTasks_ParallelExecuted() { var pipeline = ""; var target = new SmartThreadPoolTaskExecutor (); target.Add (() => { pipeline += "1"; }); target.Add (() => { Thread.Sleep(10); pipeline += "2"; }); target.Add (() => { pipeline += "3"; }); target.Start (); Assert.AreEqual ("132", pipeline); }
public void Start_ManyTasks_ParallelExecuted() { var pipeline = ""; var target = new SmartThreadPoolTaskExecutor(); target.Add(() => { pipeline += "1"; }); target.Add(() => { Thread.Sleep(10); pipeline += "2"; }); target.Add(() => { pipeline += "3"; }); target.Start(); Assert.AreEqual("132", pipeline); }