public void TestFunctionPause() { SchedulerTester.WaitForStartOfSecond(); SchedulerTester schedulerTester = new SchedulerTester(); PeriodicSchedule schedule = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.Every); List <TimeSpan> expectedResults = new List <TimeSpan> { new TimeSpan(0, 0, 1), new TimeSpan(0, 0, 3), new TimeSpan(0, 0, 5), new TimeSpan(0, 0, 7), new TimeSpan(0, 0, 9) }; schedulerTester.AddTest(schedule, expectedResults, delegate { DateTime resultTime = DateTime.UtcNow; Scheduler.DisableAll(); Thread.Sleep(1500); Scheduler.EnableAll(); return(resultTime); }); schedulerTester.Run(); }
public void TestStartEnabled() { SchedulerTester.WaitForStartOfSecond(); SchedulerTester schedulerTester = new SchedulerTester(); PeriodicSchedule schedule = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.Every); List <TimeSpan> expectedResults = new List <TimeSpan> { new TimeSpan(0, 0, 1), new TimeSpan(0, 0, 2), new TimeSpan(0, 0, 3), new TimeSpan(0, 0, 4), new TimeSpan(0, 0, 5), new TimeSpan(0, 0, 6), new TimeSpan(0, 0, 7), new TimeSpan(0, 0, 8), new TimeSpan(0, 0, 9) }; schedulerTester.SetStartTime(); schedulerTester.AddTest(Scheduler.Add <DateTime>(schedule, SchedulerTester.TestFunction, enabled: true), expectedResults); while (!schedulerTester.Completed()) { Thread.Sleep(10); } schedulerTester.Stop(); schedulerTester.CheckResults(); }
public void TestTwoSeconds() { SchedulerTester.WaitForStartOfSecond(true); SchedulerTester schedulerTester = new SchedulerTester(); PeriodicSchedule schedule = new PeriodicSchedule( hour: Hour.Every, minute: Minute.Every, second: Second.EveryTwoSeconds); List <TimeSpan> expectedResults = new List <TimeSpan> { new TimeSpan(0, 0, 2), new TimeSpan(0, 0, 4), new TimeSpan(0, 0, 6), new TimeSpan(0, 0, 8), new TimeSpan(0, 0, 10), new TimeSpan(0, 0, 12), new TimeSpan(0, 0, 14), new TimeSpan(0, 0, 16), new TimeSpan(0, 0, 18) }; schedulerTester.AddTest(schedule, expectedResults); schedulerTester.Run(); }
public void TestTwoSchedulers() { SchedulerTester.WaitForStartOfSecond(); SchedulerTester schedulerTester = new SchedulerTester(); PeriodicSchedule schedule = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.Every); List <TimeSpan> expectedResults = new List <TimeSpan> { new TimeSpan(0, 0, 1), new TimeSpan(0, 0, 2), new TimeSpan(0, 0, 3), new TimeSpan(0, 0, 4), new TimeSpan(0, 0, 5), new TimeSpan(0, 0, 6), new TimeSpan(0, 0, 7), new TimeSpan(0, 0, 8), new TimeSpan(0, 0, 9) }; schedulerTester.AddTest(schedule, expectedResults); schedule = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.Every); IScheduledFunction <int> scheduledFunction = Scheduler.Add <int>(schedule, function => function.History.Count() > 0 ? function.History.Last().Result + 1 : 1, enabled: false); Scheduler.Enable(scheduledFunction); schedulerTester.Run(); Scheduler.Disable(scheduledFunction); Queue <ScheduledFunctionResult <int> > results = new Queue <ScheduledFunctionResult <int> >(scheduledFunction.History); int resultCount = 0; while (results.Count > 0) { resultCount++; if (resultCount > 9) { Assert.Fail("ScheduledFunction<int>: Too many results returned"); break; } Assert.AreEqual(resultCount, results.Dequeue().Result); } if (resultCount < 9) { Assert.Fail("ScheduledFunction<int>: Not enough results returned"); } }
public void TestFunctionAdd() { SchedulerTester.WaitForStartOfSecond(); SchedulerTester schedulerTester1 = new SchedulerTester(); SchedulerTester schedulerTester2 = null; PeriodicSchedule schedule = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.Every); List <TimeSpan> expectedResults = new List <TimeSpan> { new TimeSpan(0, 0, 1), new TimeSpan(0, 0, 2) }; schedulerTester1.AddTest(schedule, expectedResults, delegate { DateTime resultTime = DateTime.UtcNow; if (schedulerTester2 == null) { schedulerTester2 = new SchedulerTester(); schedule = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.Every); expectedResults = new List <TimeSpan> { new TimeSpan(0, 0, 1), new TimeSpan(0, 0, 2), new TimeSpan(0, 0, 3), new TimeSpan(0, 0, 4) }; schedulerTester2.AddTest(schedule, expectedResults); schedulerTester2.Start(); } return(resultTime); }); schedulerTester1.Run(); while (schedulerTester2 == null || !schedulerTester2.Completed()) { Thread.Sleep(10); } schedulerTester2.Stop(); schedulerTester2.CheckResults(); }
public void TestDisable() { SchedulerTester.WaitForStartOfSecond(); SchedulerTester schedulerTester = new SchedulerTester(); PeriodicSchedule schedule = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.Every); List <TimeSpan> expectedResults = new List <TimeSpan> { new TimeSpan(0, 0, 1), new TimeSpan(0, 0, 2), new TimeSpan(0, 0, 3), new TimeSpan(0, 0, 4), new TimeSpan(0, 0, 5), new TimeSpan(0, 0, 6), new TimeSpan(0, 0, 7), new TimeSpan(0, 0, 8), new TimeSpan(0, 0, 9) }; schedulerTester.AddTest(schedule, expectedResults); schedule = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.Every); expectedResults = new List <TimeSpan> { new TimeSpan(0, 0, 6), new TimeSpan(0, 0, 7), new TimeSpan(0, 0, 8), new TimeSpan(0, 0, 9) }; IScheduledFunction <DateTime> scheduledFunction = schedulerTester.AddTest(schedule, expectedResults); schedulerTester.Start(); Thread.Sleep(200); Scheduler.Disable(scheduledFunction); Thread.Sleep(6000); Scheduler.Enable(scheduledFunction); while (!schedulerTester.Completed()) { Thread.Sleep(10); } schedulerTester.Stop(); schedulerTester.CheckResults(); }
public void TestMinimumGap1() { SchedulerTester.WaitForStartOfSecond(); SchedulerTester schedulerTester = new SchedulerTester(); PeriodicSchedule schedule = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.Every, minimumGap: TimeSpan.FromSeconds(2)); List <TimeSpan> expectedResults = new List <TimeSpan> { new TimeSpan(0, 0, 3), new TimeSpan(0, 0, 6), new TimeSpan(0, 0, 9), new TimeSpan(0, 0, 12), new TimeSpan(0, 0, 15) }; schedulerTester.AddTest(schedule, expectedResults); schedulerTester.Run(); }
public void TestExecuteImmediately1() { SchedulerTester.WaitForStartOfSecond(true); SchedulerTester schedulerTester = new SchedulerTester(); PeriodicSchedule schedule = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.EveryOtherSecond); List <TimeSpan> expectedResults = new List <TimeSpan> { new TimeSpan(0, 0, 1), new TimeSpan(0, 0, 3), new TimeSpan(0, 0, 5), new TimeSpan(0, 0, 7), new TimeSpan(0, 0, 9) }; schedulerTester.AddTest( Scheduler.Add <DateTime>(schedule, SchedulerTester.TestFunction, enabled: false, executeImmediately: false), expectedResults); schedulerTester.Run(); }
public void TestMinimumGap2() { SchedulerTester.WaitForStartOfSecond(); SchedulerTester schedulerTester = new SchedulerTester(); PeriodicSchedule schedule = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.Every, minimumGap: TimeSpan.FromSeconds(2)); List <TimeSpan> expectedResults = new List <TimeSpan> { TimeSpan.MinValue, // Immediate execution new TimeSpan(0, 0, 3), new TimeSpan(0, 0, 6), new TimeSpan(0, 0, 9), new TimeSpan(0, 0, 12), new TimeSpan(0, 0, 15) }; schedulerTester.AddTest( Scheduler.Add <DateTime>(schedule, SchedulerTester.TestFunction, enabled: false, executeImmediately: true), expectedResults); schedulerTester.Run(); }
public void TestStartAfter() { SchedulerTester.WaitForStartOfSecond(); SchedulerTester schedulerTester = new SchedulerTester(); DateTime startAfterTime = DateTime.UtcNow.AddSeconds(4); PeriodicSchedule schedule = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.Every); List <TimeSpan> expectedResults = new List <TimeSpan> { new TimeSpan(0, 0, 5), new TimeSpan(0, 0, 6), new TimeSpan(0, 0, 7), new TimeSpan(0, 0, 8), new TimeSpan(0, 0, 9) }; schedulerTester.AddTest( Scheduler.Add <DateTime>(schedule, SchedulerTester.TestFunction, enabled: false, startAfter: startAfterTime), expectedResults); schedulerTester.Run(); }