public void SimpleContinueWithTest() { threadPool = new MyThreadPool(1); var task = threadPool.Submit <int>(() => 2 * 2).ContinueWith(x => x * 3); Assert.AreEqual(12, task.Result); Assert.IsTrue(task.IsCompleted); }
public void ContinueWorkAfterShutdownTest() { threadPool = new MyThreadPool(2); var task1 = threadPool.Submit(() => 5 * 7); threadPool.Shutdown(); Assert.Throws <InvalidOperationException>(() => threadPool.Submit(() => 2 + 1)); }
public void CorrectNumberOfThreadsTest() { int countOfThreads = 0; Object locker = new object(); threadPool = new MyThreadPool(Environment.ProcessorCount); for (int iter = 0; iter < 7; iter++) { threadPool.Submit(() => { lock (locker) { countOfThreads++; Thread.Sleep(30); return(1); } }); } Thread.Sleep(700); Assert.IsTrue(Environment.ProcessorCount <= countOfThreads); }
public MyTask(Func <TResult> func, MyThreadPool threadPool) { this.threadPool = threadPool; this.func = func; this.submitFunctionsQueue = new Queue <Action>(); }
public void SetUp() { threadPool = new MyThreadPool(Environment.ProcessorCount); }