Exemplo n.º 1
0
        private void AssertTaskSchedulerWritesSemaphoreTwice(Action <string, TaskScheduler> configureSchedulerAction)
        {
            var semaphoreFile = Path.GetTempFileName();

            File.Delete(semaphoreFile);

            var taskScheduler = new TaskScheduler(TaskQueue.Redis(TaskQueueTestFixture.RedisConnectionString), restoreFromBackup: false);

            configureSchedulerAction(semaphoreFile, taskScheduler);
            taskScheduler.Tick();

            File.Exists(semaphoreFile).Should().Be(false);

            // Confirm Scheduled Task Ran once
            Thread.Sleep(((IntervalSeconds) * 1000) + 10);
            taskScheduler.Tick();
            File.Exists(semaphoreFile).Should().Be(true);
            File.ReadAllText(semaphoreFile).Should().Be(TaskQueueTestFixture.SemaphoreText);

            // Confirm Ran Twice
            Thread.Sleep(((IntervalSeconds) * 1000) + 10);
            taskScheduler.Tick();
            File.Exists(semaphoreFile).Should().Be(true);
            File.ReadAllText(semaphoreFile).Should()
            .Be(TaskQueueTestFixture.SemaphoreText + TaskQueueTestFixture.SemaphoreText);

            taskScheduler.FlushBackupStorage();
        }
        private async Task AssertTaskSchedulerWritesSemaphoreTwice(Func <string, TaskScheduler, Task> configureSchedulerAction)
        {
            var semaphoreFile = Path.GetTempFileName();

            File.Delete(semaphoreFile);

            var taskQueue = TaskQueue.Redis(TaskQueueTestFixture.RedisConnectionString,
                                            queueName: Guid.NewGuid().ToString());
            var taskScheduler = new TaskScheduler(taskQueue);

            await configureSchedulerAction(semaphoreFile, taskScheduler);

            await taskScheduler.Tick();

            await taskQueue.ExecuteNext();

            File.Exists(semaphoreFile).Should().Be(false);

            // Confirm Scheduled Task Ran once
            Thread.Sleep(((IntervalSeconds) * 1000) + 10);
            await taskScheduler.Tick();

            await taskQueue.ExecuteNext();

            File.Exists(semaphoreFile).Should().Be(true);
            File.ReadAllText(semaphoreFile).Should().Be(TaskQueueTestFixture.SemaphoreText);

            // Confirm Ran Twice
            Thread.Sleep(((IntervalSeconds) * 1000) + 10);
            await taskScheduler.Tick();

            await taskQueue.ExecuteNext();

            File.Exists(semaphoreFile).Should().Be(true);
            File.ReadAllText(semaphoreFile).Should()
            .Be(TaskQueueTestFixture.SemaphoreText + TaskQueueTestFixture.SemaphoreText);

            taskScheduler.FlushBackupStorage();
        }