public async Task GivenASqlTaskManager_WhenCreateTask_ThenNewTaskShouldBeCreated() { string queueId = Guid.NewGuid().ToString(); string taskId = Guid.NewGuid().ToString(); short typeId = 1; string inputData = "inputData"; TaskInfo taskInfo = new TaskInfo() { TaskId = taskId, QueueId = queueId, TaskTypeId = typeId, InputData = inputData, }; SqlServerTaskManager sqlServerTaskManager = new SqlServerTaskManager(_fixture.SqlConnectionWrapperFactory, NullLogger <SqlServerTaskManager> .Instance); taskInfo = await sqlServerTaskManager.CreateTaskAsync(taskInfo, CancellationToken.None); Assert.Equal(queueId, taskInfo.QueueId); Assert.Equal(taskId, taskInfo.TaskId); Assert.Equal(typeId, taskInfo.TaskTypeId); Assert.Equal(inputData, taskInfo.InputData); Assert.Equal(TaskStatus.Queued, taskInfo.Status); Assert.NotNull(taskInfo.HeartbeatDateTime); Assert.Null(taskInfo.RunId); Assert.False(taskInfo.IsCanceled); Assert.Equal(0, taskInfo.RetryCount); Assert.Null(taskInfo.Context); Assert.Null(taskInfo.Result); taskInfo = await sqlServerTaskManager.GetTaskAsync(taskId, CancellationToken.None); Assert.Equal(queueId, taskInfo.QueueId); Assert.Equal(taskId, taskInfo.TaskId); Assert.Equal(typeId, taskInfo.TaskTypeId); Assert.Equal(inputData, taskInfo.InputData); Assert.Equal(TaskStatus.Queued, taskInfo.Status); Assert.NotNull(taskInfo.HeartbeatDateTime); Assert.Null(taskInfo.RunId); Assert.False(taskInfo.IsCanceled); Assert.Equal(0, taskInfo.RetryCount); Assert.Null(taskInfo.Context); Assert.Null(taskInfo.Result); }
public async Task GivenARunningTask_WhenReachMaxRetryCount_ThenResetShouldFail() { string queueId = Guid.NewGuid().ToString(); TaskHostingConfiguration config = new TaskHostingConfiguration() { Enabled = true, QueueId = queueId, TaskHeartbeatTimeoutThresholdInSeconds = 60, }; IOptions <TaskHostingConfiguration> taskHostingConfig = Substitute.For <IOptions <TaskHostingConfiguration> >(); taskHostingConfig.Value.Returns(config); SqlServerTaskManager sqlServerTaskManager = new SqlServerTaskManager(_fixture.SqlConnectionWrapperFactory, NullLogger <SqlServerTaskManager> .Instance); SqlServerTaskConsumer sqlServerTaskConsumer = new SqlServerTaskConsumer(taskHostingConfig, _fixture.SqlConnectionWrapperFactory, NullLogger <SqlServerTaskConsumer> .Instance); string taskId = Guid.NewGuid().ToString(); short typeId = 1; string inputData = "inputData"; TaskInfo taskInfo = new TaskInfo() { TaskId = taskId, QueueId = queueId, TaskTypeId = typeId, InputData = inputData, MaxRetryCount = 1, }; _ = await sqlServerTaskManager.CreateTaskAsync(taskInfo, CancellationToken.None); TaskResultData result = new TaskResultData(TaskResult.Fail, "Result"); taskInfo = (await sqlServerTaskConsumer.GetNextMessagesAsync(1, 60, CancellationToken.None)).First(); taskInfo = await sqlServerTaskConsumer.ResetAsync(taskInfo.TaskId, result, taskInfo.RunId, CancellationToken.None); taskInfo = (await sqlServerTaskConsumer.GetNextMessagesAsync(1, 60, CancellationToken.None)).First(); await Assert.ThrowsAsync <TaskAlreadyCompletedException>(async() => await sqlServerTaskConsumer.ResetAsync(taskInfo.TaskId, result, taskInfo.RunId, CancellationToken.None)); taskInfo = await sqlServerTaskManager.GetTaskAsync(taskInfo.TaskId, CancellationToken.None); Assert.Equal(TaskStatus.Completed, taskInfo.Status); Assert.Equal(JsonConvert.SerializeObject(result), taskInfo.Result); }