Example #1
0
        public async Task ItAllowsForRecurringTaskCrontabSchedulesToBeChanged()
        {
            var taskName = Guid.NewGuid().ToString();

            Func <string, TaskScheduler, Task> configureSchedulerAction = async(semaphoreFile, taskScheduler) =>
            {
                var crontab = $"*/{IntervalSeconds} * * * * *";
                TaskSchedulerTestHelpers.SynchronizeToCrontabNextStart(crontab);
                Thread.Sleep(10);

                await taskScheduler.AddRecurringTask(() => TaskQueueTestFixture.WriteSemaphore(semaphoreFile),
                                                     crontab, taskName);
            };

            Func <string, TaskScheduler, Task> reconfigureRecurringTaskIntervalAction = async(semaphoreFile, taskScheduler) =>
            {
                // Must synchronize to next start time or test becomes flaky
                var newCrontab = $"*/{IntervalSeconds*2} * * * * *";
                TaskSchedulerTestHelpers.SynchronizeToCrontabNextStart(newCrontab);
                Thread.Sleep(10);

                await taskScheduler.AddRecurringTask(() => TaskQueueTestFixture.WriteSemaphore(semaphoreFile),
                                                     newCrontab, taskName);
            };

            await TaskSchedulerTestHelpers.AssertTaskSchedulerWritesSemaphoreTwiceAfterReconfiguringInterval(
                IntervalSeconds,
                configureSchedulerAction,
                reconfigureRecurringTaskIntervalAction);
        }
Example #2
0
        public async Task ItExecutesARecurringTaskAtTheSpecifiedInterval()
        {
            Func <string, TaskScheduler, Task> configureSchedulerAction = async(semaphoreFile, taskScheduler) =>
            {
                await taskScheduler.AddRecurringTask(() => TaskQueueTestFixture.WriteSemaphore(semaphoreFile),
                                                     TimeSpan.FromSeconds(IntervalSeconds), RandomTaskName);
            };

            await TaskSchedulerTestHelpers.AssertTaskSchedulerWritesSemaphoreTwice(
                IntervalSeconds,
                configureSchedulerAction);
        }
Example #3
0
        public async Task ItExecutesAScheduledTaskAtTheSpecifiedDateTimeOnlyOnce()
        {
            Func <string, TaskScheduler, Task> configureSchedulerAction = async(semaphoreFile, taskScheduler) =>
            {
                await taskScheduler.AddScheduledTask(() => TaskQueueTestFixture.WriteSemaphore(semaphoreFile),
                                                     DateTime.UtcNow + TimeSpan.FromSeconds(IntervalSeconds));
            };

            await TaskSchedulerTestHelpers.AssertTaskSchedulerWritesSemaphoreOnlyOnce(
                IntervalSeconds,
                configureSchedulerAction);
        }
Example #4
0
        public async Task ItExecutesARecurringTaskAtTheSpecifiedCrontabInterval()
        {
            Func <string, TaskScheduler, Task> configureSchedulerAction = async(semaphoreFile, taskScheduler) =>
            {
                var crontab = $"*/{IntervalSeconds} * * * * *";
                TaskSchedulerTestHelpers.SynchronizeToCrontabNextStart(crontab);
                Thread.Sleep(10);

                await taskScheduler.AddRecurringTask(() => TaskQueueTestFixture.WriteSemaphore(semaphoreFile),
                                                     crontab, RandomTaskName);
            };

            await TaskSchedulerTestHelpers.AssertTaskSchedulerWritesSemaphoreTwice(IntervalSeconds,
                                                                                   configureSchedulerAction);
        }
Example #5
0
        public async Task ItAllowsForScheduledTasksToBeCanceled()
        {
            var           taskName      = Guid.NewGuid().ToString();
            ScheduledTask scheduledTask = null;

            Func <string, TaskScheduler, Task> configureSchedulerAction = async(semaphoreFile, taskScheduler) =>
            {
                scheduledTask = await taskScheduler.AddScheduledTask(() => TaskQueueTestFixture.WriteSemaphore(semaphoreFile),
                                                                     DateTime.UtcNow + TimeSpan.FromSeconds(IntervalSeconds));
            };

            Func <TaskScheduler, Task> cancelTaskAction = async(taskScheduler) =>
            {
                (await taskScheduler.CancelScheduledTask(scheduledTask)).Should().BeTrue();
            };

            await TaskSchedulerTestHelpers.AssertTaskSchedulerDoesNotWriteSemaphore(
                IntervalSeconds,
                configureSchedulerAction,
                cancelTaskAction);
        }
Example #6
0
        public async Task ItAllowsForRecurringTasksToBeCanceled()
        {
            var           taskName      = Guid.NewGuid().ToString();
            RecurringTask recurringTask = null;

            Func <string, TaskScheduler, Task> configureSchedulerAction = async(semaphoreFile, taskScheduler) =>
            {
                recurringTask = await taskScheduler.AddRecurringTask(() => TaskQueueTestFixture.WriteSemaphore(semaphoreFile),
                                                                     $"*/{IntervalSeconds} * * * * *", taskName);
            };

            Func <TaskScheduler, Task> cancelTaskAction = async(taskScheduler) =>
            {
                (await taskScheduler.CancelRecurringTask(recurringTask)).Should().BeTrue();
            };

            await TaskSchedulerTestHelpers.AssertTaskSchedulerDoesNotWriteSemaphore(
                IntervalSeconds,
                configureSchedulerAction,
                cancelTaskAction);
        }
Example #7
0
        public async Task ItAllowsForRecurringTaskTimespanSchedulesToBeChanged()
        {
            var taskName = Guid.NewGuid().ToString();

            Func <string, TaskScheduler, Task> configureSchedulerAction = async(semaphoreFile, taskScheduler) =>
            {
                await taskScheduler.AddRecurringTask(() => TaskQueueTestFixture.WriteSemaphore(semaphoreFile),
                                                     TimeSpan.FromSeconds(IntervalSeconds), taskName);
            };

            Func <string, TaskScheduler, Task> reconfigureRecurringTaskIntervalAction = async(semaphoreFile, taskScheduler) =>
            {
                await taskScheduler.AddRecurringTask(() => TaskQueueTestFixture.WriteSemaphore(semaphoreFile),
                                                     TimeSpan.FromSeconds(IntervalSeconds * 2), taskName);
            };

            await TaskSchedulerTestHelpers.AssertTaskSchedulerWritesSemaphoreTwiceAfterReconfiguringInterval(
                IntervalSeconds,
                configureSchedulerAction,
                reconfigureRecurringTaskIntervalAction);
        }