//============================= private void RunSimpleProcessWorkTest(int minThreadCount, int maxThreadCount, int queueCapacity, int workCount = 100000) { using (DynamicThreadPool testInst = new DynamicThreadPool(minThreadCount, maxThreadCount, queueCapacity, "name")) { Assert.IsTrue(testInst.ThreadCount >= minThreadCount); Assert.IsTrue(testInst.ActiveThreadCount >= minThreadCount); Assert.AreEqual(queueCapacity, testInst.QueueCapacity); Assert.IsTrue(testInst.IsWork); int expectedWork = workCount; int executedWork = 0; for (int i = 0; i < expectedWork; i++) { testInst.Run(() => { Interlocked.Increment(ref executedWork); }); } testInst.Dispose(true, true, true); Assert.AreEqual(0, testInst.ThreadCount); Assert.IsFalse(testInst.IsWork); Assert.AreEqual(expectedWork, executedWork); testInst.CompleteAdding(); } }
public void TestCantAddAfterCompleteAdding() { using (DynamicThreadPool testInst = new DynamicThreadPool(0, Environment.ProcessorCount, -1, "name")) { Assert.IsTrue(testInst.TryRun(() => { })); testInst.CompleteAdding(); Assert.IsFalse(testInst.TryRun(() => { })); testInst.Run(() => { }); } }