public void WaitAll_SingleThread_MultipleTasks() { var workerPool = new ParallelTaskWorkerPool(1); var task1 = new BusyTask(); var task2 = new BusyTask(); workerPool.Enqueue(task1); workerPool.Enqueue(task2); workerPool.Start(); Assert.IsFalse(workerPool.WaitAll(10), "Threads should not have exited, 2 tasks are in progress"); Assert.AreEqual(BusyTaskState.Executing, task1.State); Assert.AreEqual(BusyTaskState.Queued, task2.State); task1.MarkTaskAsCompleted(); Assert.IsFalse(workerPool.WaitAll(10), "Threads should not have exited, 1 task is in progress"); Assert.AreEqual(BusyTaskState.Completed, task1.State); Assert.AreEqual(BusyTaskState.Executing, task2.State); task2.MarkTaskAsCompleted(); Assert.IsTrue(workerPool.WaitAll(100), "Threads should have exited, all work is complete"); Assert.AreEqual(BusyTaskState.Completed, task1.State); Assert.AreEqual(BusyTaskState.Completed, task2.State); }
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 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"); }
public void WaitAll_SingleTask() { var workerPool = new ParallelTaskWorkerPool(1); var task = new BusyTask(); workerPool.Enqueue(task); workerPool.Start(); Assert.IsFalse(workerPool.WaitAll(10), "Threads should not have exited, work is in progress"); task.MarkTaskAsCompleted(); Assert.IsTrue(workerPool.WaitAll(100), "Threads should have exited, all work is complete"); }