public void TestTaskThrottling() { // setup a task handler Threadnaught handler = new Threadnaught(3); // add tasks List <int> taskKeys = new List <int>(); newTasks.ForEach(m => taskKeys.Add(handler.AddTask(m, false))); // wait for them then tell the tester to check for those keys handler.WaitForTasks(taskKeys, true); }
public void TestWaitMultiple() { // create the task handler Threadnaught handler = new Threadnaught(false); // false to check the auto start on the wait // setup a list to get the task keys List <int> taskKeys = new List <int>(); // add the tasks to the handler newTasks.ForEach(m => taskKeys.Add(handler.AddTask(m))); // get the keys we want to run List <int> tasksToRun = PickRandomTaskKeys(taskKeys, 4); // wait for the tasks handler.WaitForTasks(tasksToRun); // make sure the tasks are run to completion tasksToRun.ForEach(m => Assert.AreEqual(handler.GetTask(m).Status, TaskStatus.RanToCompletion)); }
public void TestTaskRemoval() { // setup a task handler Threadnaught handler = new Threadnaught(true); // add tasks List <int> taskKeys = new List <int>(); newTasks.ForEach(m => taskKeys.Add(handler.AddTask(m))); // pick some tasks to run List <int> tasksToRun = PickRandomTaskKeys(taskKeys, 6); // wait for them then tell the tester to check for those keys handler.WaitForTasks(tasksToRun, true); // if any of the keys exist, it should fail if (handler.TaskQueue.Keys.Where(m => tasksToRun.Any(x => x == m)).Count() > 0) { Assert.Fail(); } }