public void TestSchedulingOfPreemptiveUsingBaseClassShouldFailQueueing() { int numOfThreads = 2; SimpleTaskScheduler taskScheduler = SimpleTaskScheduler.CreatePreemptive(numOfThreads); TaskScheduler baseTaskScheduler = taskScheduler; Task t = CreateTask(id: 1, token: taskScheduler.GetExecutionToken()); t.Start(baseTaskScheduler); Assert.IsFalse(taskScheduler.IsTaskCurrentlyExecuting(t)); }
public void TestSchedulingOfNonPreemptiveUsingBaseClassShouldSucceedQueueing() { int numOfThreads = 2; SimpleTaskScheduler taskScheduler = SimpleTaskScheduler.CreateNonPreemptive(numOfThreads); TaskScheduler baseTaskScheduler = taskScheduler; Task t = CreateTask(id: 1, token: taskScheduler.GetExecutionToken()); t.Start(baseTaskScheduler); Task.Delay(500).Wait(); Assert.IsTrue(taskScheduler.IsTaskCurrentlyExecuting(t)); }
public void TestTwoTasksWithOneResourceLockingAndGettingMaxPriority() { int numOfThreads = 1; SimpleTaskScheduler taskScheduler = SimpleTaskScheduler.CreatePreemptive(numOfThreads); SimpleTaskScheduler.ExecutionToken token1 = taskScheduler.GetExecutionToken(); SimpleTaskScheduler.ExecutionToken token2 = taskScheduler.GetExecutionToken(); Task t1 = CreateTaskWithResourceLock(id: 1, token: token1, resource: new object());; Task t2 = CreateTask(id: 2, token: token2); taskScheduler.Register(t1, 5, 2500, token1); taskScheduler.Register(t2, 4, 2500, token2); t1.Start(taskScheduler); Task.Delay(500).Wait(); t2.Start(taskScheduler); Task.Delay(2000).Wait(); Assert.IsTrue(taskScheduler.IsTaskCurrentlyExecuting(t2)); }