Ejemplo n.º 1
0
        public void TestFirstTickTwoSecondsHourly()
        {
            // Create a dummy controller to record the callbacks.
            DummyControllerContext controllerContext = new DummyControllerContext();

            // Set up parameters for the PurgeTimerTask
            PurgeTimerTaskParameters params1 = new PurgeTimerTaskParameters();

            // Standard task parameters.
            params1.IsBackgroundTask  = true;
            params1.Name              = "TestRunOneTask";
            params1.RunInParallel     = false;
            params1.UseSeparateThread = true;
            params1.ControllerContext = controllerContext;

            // Specific task parameters.
            params1.PurgeOptionsCollection = new StackHashPurgeOptionsCollection();

            // Set the schedule so the task runs in 2 seconds time (every hour).
            params1.ScheduleCollection = new ScheduleCollection();

            Schedule schedule = new Schedule();

            schedule.DaysOfWeek = DaysOfWeek.Monday | DaysOfWeek.Tuesday | DaysOfWeek.Wednesday |
                                  DaysOfWeek.Thursday | DaysOfWeek.Friday | DaysOfWeek.Saturday | DaysOfWeek.Sunday;

            DateTime timeToRunTask = DateTime.Now.AddSeconds(2);

            schedule.Time   = new ScheduleTime(timeToRunTask.Hour, timeToRunTask.Minute, timeToRunTask.Second);
            schedule.Period = SchedulePeriod.Hourly;

            params1.ScheduleCollection.Add(schedule);


            // Create the task and run it.
            PurgeTimerTask task1       = new PurgeTimerTask(params1);
            TaskManager    taskManager = new TaskManager("Test");

            taskManager.Enqueue(task1);

            Assert.AreEqual(0, controllerContext.RunPurgeCallCount);

            // Now wait for a little over 2 seconds.
            Thread.Sleep(3300);

            Assert.AreEqual(1, controllerContext.RunPurgeCallCount);

            // Task should still be running after a tick.
            Assert.AreEqual(false, task1.CurrentTaskState.TaskCompleted);

            taskManager.AbortAllTasks(false);
            taskManager.WaitForTaskCompletion(task1, s_TaskTimeout);

            // Should be set to trigger in approximately an hour.

            long timeDiff = Math.Abs(60 * 60 * 1000 - task1.TimeInMilliseconds);

            Console.WriteLine("TimeDiff: " + timeDiff.ToString());
            Assert.AreEqual(true, timeDiff < 2000);
        }
Ejemplo n.º 2
0
        public void TestFirstTickTwoSecondsDaily()
        {
            // Create a dummy controller to record the callbacks.
            DummyControllerContext controllerContext = new DummyControllerContext();

            // Set up the task parameters.
            WinQualSyncTimerTaskParameters params1 = new WinQualSyncTimerTaskParameters();

            params1.IsBackgroundTask  = true;
            params1.Name              = "TestRunOneTask";
            params1.RunInParallel     = false;
            params1.UseSeparateThread = true;
            params1.ControllerContext = controllerContext;

            params1.ThisWinQualContext = new WinQualContext(null);

            // Time set to expire in 2 seconds but daily - so the one after should be tomorrow at the same time.
            params1.ScheduleCollection = new ScheduleCollection();
            Schedule schedule = new Schedule();

            schedule.DaysOfWeek = DaysOfWeek.Monday | DaysOfWeek.Tuesday | DaysOfWeek.Wednesday |
                                  DaysOfWeek.Thursday | DaysOfWeek.Friday | DaysOfWeek.Saturday | DaysOfWeek.Sunday;

            DateTime timeToRunTask = DateTime.Now.AddSeconds(2);

            schedule.Time   = new ScheduleTime(timeToRunTask.Hour, timeToRunTask.Minute, timeToRunTask.Second);
            schedule.Period = SchedulePeriod.Daily;

            params1.ScheduleCollection.Add(schedule);


            // Create and run the task.
            WinQualSyncTimerTask task1       = new WinQualSyncTimerTask(params1);
            TaskManager          taskManager = new TaskManager("Test");

            taskManager.Enqueue(task1);

            Assert.AreEqual(0, controllerContext.SynchronizeCallCount);

            // Now wait for a little over 2 seconds (+1)
            Thread.Sleep(4000);

            Assert.AreEqual(1, controllerContext.SynchronizeCallCount);

            // Task should still be running after a tick.
            Assert.AreEqual(false, task1.CurrentTaskState.TaskCompleted);

            taskManager.AbortAllTasks(false);
            taskManager.WaitForTaskCompletion(task1, s_TaskTimeout);
            taskManager.Dispose();

            // Should be set to trigger in approximately an hour.

            long timeDiff = Math.Abs(24 * 60 * 60 * 1000 - task1.TimeInMilliseconds);

            Assert.AreEqual(true, timeDiff < 2000);
        }
Ejemplo n.º 3
0
        public void TestFirstTickTwoSecondsWeekly()
        {
            // Create a dummy controller to record the call backs.
            DummyControllerContext controllerContext = new DummyControllerContext();

            PurgeTimerTaskParameters params1 = new PurgeTimerTaskParameters();

            params1.IsBackgroundTask  = true;
            params1.Name              = "TestRunOneTask";
            params1.RunInParallel     = false;
            params1.UseSeparateThread = true;
            params1.ControllerContext = controllerContext;

            params1.PurgeOptionsCollection = new StackHashPurgeOptionsCollection();
            params1.ScheduleCollection     = new ScheduleCollection();
            Schedule schedule = new Schedule();

            schedule.DaysOfWeek = Schedule.ConvertDateTimeDayToStackHashDay(DateTime.Now.DayOfWeek);


            DateTime timeToRunTask = DateTime.Now.AddSeconds(2);

            schedule.Time   = new ScheduleTime(timeToRunTask.Hour, timeToRunTask.Minute, timeToRunTask.Second);
            schedule.Period = SchedulePeriod.Weekly;

            params1.ScheduleCollection.Add(schedule);


            PurgeTimerTask task1 = new PurgeTimerTask(params1);

            // Create a task manager for the context.
            TaskManager taskManager = new TaskManager("Test");

            taskManager.Enqueue(task1);

            Assert.AreEqual(0, controllerContext.RunPurgeCallCount);

            // Now wait for a little over 2 seconds.
            Thread.Sleep(3200);

            Assert.AreEqual(1, controllerContext.RunPurgeCallCount);

            // Task should still be running after a tick.
            Assert.AreEqual(false, task1.CurrentTaskState.TaskCompleted);

            taskManager.AbortAllTasks(false);
            taskManager.WaitForTaskCompletion(task1, s_TaskTimeout);
            taskManager.Dispose();

            // Should be set to trigger in approximately a week.
            long timeDiff = Math.Abs(7 * 24 * 60 * 60 * 1000 - task1.TimeInMilliseconds);

            Assert.AreEqual(true, timeDiff < (500 + 60 * 60 * 1000)); // Could be an hour out if you run this test during the week before a daylight saving change.
        }