public void WaitAll_TwoThreads_MultipleTasks() { var workerPool = new ParallelTaskWorkerPool(2); var task1 = new BusyTask(); var task2 = new BusyTask(); workerPool.Enqueue(task1); workerPool.Enqueue(task2); workerPool.Start(); Assert.That(workerPool.WaitAll(10), Is.False, "Threads should not have exited, 2 tasks are in progress"); Assert.That(task1.State, Is.EqualTo(BusyTaskState.Executing)); Assert.That(task2.State, Is.EqualTo(BusyTaskState.Executing)); task1.MarkTaskAsCompleted(); Assert.That(workerPool.WaitAll(10), Is.False, "Threads should not have exited, 1 task is in progress"); Assert.That(task1.State, Is.EqualTo(BusyTaskState.Completed)); Assert.That(task2.State, Is.EqualTo(BusyTaskState.Executing)); task2.MarkTaskAsCompleted(); Assert.That(workerPool.WaitAll(100), Is.True, "Threads should have exited, all work is complete"); Assert.That(task1.State, Is.EqualTo(BusyTaskState.Completed)); Assert.That(task2.State, Is.EqualTo(BusyTaskState.Completed)); }
public void EnqueueCannotBeCalledAfterWorkHasStarted() { var workerPool = new ParallelTaskWorkerPool(1); workerPool.Start(); Assert.Throws <InvalidOperationException>(() => workerPool.Enqueue(new NoOpTask())); }
public void WaitAll_SingleTask() { var workerPool = new ParallelTaskWorkerPool(1); var task = new BusyTask(); workerPool.Enqueue(task); workerPool.Start(); Assert.That(workerPool.WaitAll(10), Is.False, "Threads should not have exited, work is in progress"); task.MarkTaskAsCompleted(); Assert.That(workerPool.WaitAll(100), Is.True, "Threads should have exited, all work is complete"); }
private void RunTestsInParallel(ITestEventListener listener, TestFilter filter, List <TestEngineResult> results, bool disposeRunners) { var workerPool = new ParallelTaskWorkerPool(LevelOfParallelism); var tasks = new List <TestExecutionTask>(); foreach (ITestEngineRunner runner in Runners) { var task = new TestExecutionTask(runner, listener, filter, disposeRunners); tasks.Add(task); workerPool.Enqueue(task); } workerPool.Start(); workerPool.WaitAll(); foreach (var task in tasks) { LogResultsFromTask(task, results); } }