public void Scheduler_AddTimer_RetrieveTask() { var scheduler = new SimpleScheduler(); var task = scheduler.Start(() => 0, 10); Assert.IsTrue(task.Active, "Task should be active after Scheduler Insertion..."); }
public void Scheduler_StopTimer_TaskInactive() { var scheduler = new SimpleScheduler(); var task = scheduler.Start(() => 1, 1); task.Stop(); Assert.IsFalse(task.Active, "Task should be inactive after Scheduler Stop..."); }
public void Scheduler_StopTimerLatency_TaskNotRun() { var scheduler = new SimpleScheduler(); var run = false; var task = scheduler.Start(() => { run = true; return 0; }, 100); System.Threading.Thread.Sleep(50); task.Stop(); System.Threading.Thread.Sleep(100); Assert.IsFalse(run, "Task should not have run when Stopping before delay..."); }
public void Scheduler_MultiInsertInterval_FixedCountRun() { var scheduler = new SimpleScheduler(); // Long Interval Tasks var longCount = Enumerable.Range(0, 10).Select(i => 0).ToArray(); var longTasks = Enumerable.Range(0, 10).Select(i => scheduler.Start(() => { longCount[i]++; return longCount[i] == 5 ? 0 : 500; }, 500)).ToArray(); System.Threading.Thread.Sleep(100); // Short Interval Tasks var shortCount = Enumerable.Range(0, 10).Select(i => 0).ToArray(); var shortTasks = Enumerable.Range(0, 10).Select(i => scheduler.Start(() => { shortCount[i]++; return shortCount[i] == 10 ? 0 : 100; }, 1)).ToArray(); System.Threading.Thread.Sleep(1100); CollectionAssert.AreEqual(Enumerable.Range(0, 10).Select(i => 10), shortCount); CollectionAssert.AreEqual(Enumerable.Range(0, 10).Select(i => false), shortTasks.Select(t => t.Active)); System.Threading.Thread.Sleep(1900); CollectionAssert.AreEqual(Enumerable.Range(0, 10).Select(i => 5), longCount); CollectionAssert.AreEqual(Enumerable.Range(0, 10).Select(i => false), longTasks.Select(t => t.Active)); }
public void Scheduler_TimerException_LogDisplay() { var scheduler = new SimpleScheduler(); var task = scheduler.Start(() => { throw new Exception(); }, 1); System.Threading.Thread.Sleep(100); Assert.IsFalse(task.Active, "Task should have been scheduled to Test Exception..."); }
public void Scheduler_MultiInsertStopTest_AllTasksFinished() { var scheduler = new SimpleScheduler(); // Long Interval Tasks var longTasks = Enumerable.Range(0, 10).Select(i => scheduler.Start(() => 0, 1000)).ToArray(); System.Threading.Thread.Sleep(100); // Short Interval Tasks var shortTasks = Enumerable.Range(0, 10).Select(i => scheduler.Start(() => 0, 1)).ToArray(); System.Threading.Thread.Sleep(100); CollectionAssert.AreEqual(Enumerable.Range(0, 10).Select(i => false), shortTasks.Select(t => t.Active)); System.Threading.Thread.Sleep(900); CollectionAssert.AreEqual(Enumerable.Range(0, 10).Select(i => false), longTasks.Select(t => t.Active)); }
public void Scheduler_TimerStartLatency_LowerThan() { var scheduler = new SimpleScheduler(); var start = SimpleScheduler.Ticks; var finished = long.MaxValue; var task = scheduler.Start(() => { finished = SimpleScheduler.Ticks; return 0; }, 1); System.Threading.Thread.Sleep(100); Assert.Less(finished - start, 100, "Scheduler Task Latency is higher than 100ms!"); Assert.IsFalse(task.Active, "Task Should be inactive after Scheduling..."); }
public void Scheduler_IntervalTimerFixedCount_CountRun() { var scheduler = new SimpleScheduler(); int count = 0; var task = scheduler.Start(() => { count++; return count == 10 ? 0 : 1; }, 1); System.Threading.Thread.Sleep(200); Assert.AreEqual(10, count, "Task Should have been Scheduled 10 times..."); Assert.IsFalse(task.Active, "Task should be Inactive after Fixed Schedule count..."); }
public void Scheduler_StartTimerOnce_TaskRunOnce() { var scheduler = new SimpleScheduler(); int count = 0; var task = scheduler.Start(() => { count++; return 0; }, 1); System.Threading.Thread.Sleep(100); Assert.AreEqual(count, 1, "Task Should have been Scheduled once with no Interval..."); Assert.IsFalse(task.Active, "Task Should be inactive after one Scheduling..."); }
public void Scheduler_StartIntervalTimer_TaskRunMultipleTime() { var scheduler = new SimpleScheduler(); int count = 0; var task = scheduler.Start(() => { count++; return 1; }, 1); System.Threading.Thread.Sleep(100); var intermediate = count; Assert.Greater(intermediate, 0, "Task Should have been Scheduled multiple time with an Interval of 1ms..."); System.Threading.Thread.Sleep(100); task.Stop(); Assert.Greater(count, intermediate, "Task should have been scheduled again before stopping..."); }