public void TestValueRetrieveString() { // setup handler and add task Threadnaught handler = new Threadnaught(); string taskString = "blah blah blah"; int task1 = handler.AddTask(new Task <string>(() => WasteTimeString(1, taskString))); // get the value Assert.AreEqual(handler.GetTaskValue <string>(task1), taskString); }
public void TestValueRetrieveInt() { // setup handler and add task Threadnaught handler = new Threadnaught(); int taskNumber = 1; int task1 = handler.AddTask(new Task <int>(() => WasteTimeInt(taskNumber))); // get the value Assert.AreEqual(handler.GetTaskValue <int>(task1), taskNumber); }
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 TestWait() { // 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))); // pick a task to run int taskToRun = PickRandomTaskKey(taskKeys); handler.WaitForTask(taskToRun); Assert.AreEqual(handler.GetTask(taskToRun).Status, TaskStatus.RanToCompletion); taskKeys.Where(m => m != taskToRun).ToList().ForEach(m => Assert.AreEqual(handler.GetTask(m).Status, TaskStatus.Created)); }
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(); } }
public void TextAutoExecute() { Threadnaught handler = new Threadnaught(false); int task1 = handler.AddTask(new Task(() => ExecuteWasteTime(1))); int task2 = handler.AddTask(new Task(() => ExecuteWasteTime(2))); int task3 = handler.AddTask(new Task(() => ExecuteWasteTime(3))); handler.StartTask(task1); handler.StartTask(task3); handler.WaitForTask(task1); handler.WaitForTask(task3); // if task two rant o completion or ran, it failed Task taskTwo = handler.GetTask(task2); if (taskTwo.Status == TaskStatus.RanToCompletion || taskTwo.Status == TaskStatus.Running) { Assert.Fail(); } }
public void TestAdd() { Threadnaught handler = new Threadnaught(); int task1 = handler.AddTask(new Task(() => AddWasteTime(1))); int task2 = handler.AddTask(new Task(() => AddWasteTime(2))); int task3 = handler.AddTask(new Task(() => AddWasteTime(3))); handler.WaitForTask(task1); handler.WaitForTask(task2); handler.WaitForTask(task3); // if any of the stats havent ran to completion, this test failed if (new List <TaskStatus>() { handler.GetTask(task1).Status, handler.GetTask(task2).Status, handler.GetTask(task3).Status }.Any(m => m != TaskStatus.RanToCompletion)) { Assert.Fail(); } }