Exemplo n.º 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);
        }
Exemplo n.º 2
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);
        }