diff --git a/src/Demos/GreenFeetWorkFlow.Tests/AdoTests.cs b/src/Demos/GreenFeetWorkFlow.Tests/AdoTests.cs index 45ba80c..c7f1856 100644 --- a/src/Demos/GreenFeetWorkFlow.Tests/AdoTests.cs +++ b/src/Demos/GreenFeetWorkFlow.Tests/AdoTests.cs @@ -45,7 +45,7 @@ public void When_executing_OneStep_with_initialstate_Then_that_state_is_accessib } [Test] - public async Task When_adding_two_steps_in_the_same_transaction_Then_both_execute() + public void When_adding_two_steps_in_the_same_transaction_Then_both_execute() { string[] stepResults = new string[2]; const string name = "v1/When_adding_two_steps_in_the_same_transaction_Then_succeed"; @@ -71,7 +71,7 @@ public async Task When_adding_two_steps_in_the_same_transaction_Then_both_execut Dictionary> GetAllByFlowId() => helper.Engine!.Data.SearchSteps(new SearchModel(FlowId: helper.FlowId), FetchLevels.ALL); [Test] - public async Task When_executing_step_throwing_special_FailCurrentStepException_Then_fail_current_step() + public void When_executing_step_throwing_special_FailCurrentStepException_Then_fail_current_step() { const string name = "test-throw-failstepexception"; helper.StepHandlers = [( @@ -86,7 +86,7 @@ public async Task When_executing_step_throwing_special_FailCurrentStepException_ } [Test] - public async Task When_executing_step_throwing_special_FailCurrentStepException_using_step_Then_fail_current_step() + public void When_executing_step_throwing_special_FailCurrentStepException_using_step_Then_fail_current_step() { const string name = "test-throw-failstepexception_from_step_variable"; helper.Steps = [new Step(name) { FlowId = helper.FlowId }]; @@ -98,7 +98,7 @@ public async Task When_executing_step_throwing_special_FailCurrentStepException_ } [Test] - public async Task When_executing_step_throwing_special_FailCurrentStepException_and_add_step_Then_fail_current_step_and_add_ready_step() + public void When_executing_step_throwing_special_FailCurrentStepException_and_add_step_Then_fail_current_step_and_add_ready_step() { var name = "test-throw-failstepexception-with-newStep"; var nameNewStep = "test-throw-failstepexception-with-newStep-newstepname"; @@ -168,7 +168,7 @@ public async Task When_executing_step_throwing_special_FailCurrentStepException_ } [Test] - public async Task When_executing_step_throwing_exception_Then_rerun_current_step_and_ensure_state_is_unchanged() + public void When_executing_step_throwing_exception_Then_rerun_current_step_and_ensure_state_is_unchanged() { int? dbid = null; const string name = "test-throw-exception"; @@ -392,7 +392,7 @@ public void When_step_is_in_the_future_Then_it_wont_execute() } [Test] - public async Task When_step_is_in_the_future_Then_it_can_be_activated_to_execute_now() + public void When_step_is_in_the_future_Then_it_can_be_activated_to_execute_now() { string? stepResult = null; const string name = "When_step_is_in_the_future_Then_it_can_be_activated_to_execute_now"; @@ -408,7 +408,7 @@ public async Task When_step_is_in_the_future_Then_it_can_be_activated_to_execute // activate var id = GetByFlowId().Single().Id; - var count = await helper.Engine!.Data.ActivateStepAsync(id, null); + var count = helper.Engine!.Data.ActivateStep(id, null); count.Should().Be(1); helper.Start(); @@ -418,7 +418,7 @@ public async Task When_step_is_in_the_future_Then_it_can_be_activated_to_execute } [Test] - public async Task When_step_is_in_the_future_Then_it_can_be_activated_to_execute_now_with_args() + public void When_step_is_in_the_future_Then_it_can_be_activated_to_execute_now_with_args() { string? stepResult = null; string args = "1234"; @@ -434,7 +434,7 @@ public async Task When_step_is_in_the_future_Then_it_can_be_activated_to_execute // activate var id = GetByFlowId().Single().Id; - var count = await helper.Engine!.Data.ActivateStepAsync(id, args); + var count = helper.Engine!.Data.ActivateStep(id, args); count.Should().Be(1); helper.Start(); @@ -443,7 +443,7 @@ public async Task When_step_is_in_the_future_Then_it_can_be_activated_to_execute } [Test] - public async Task TwoSteps_flow_with_last_step_undefined_stephandler__so_test_terminate() + public void TwoSteps_flow_with_last_step_undefined_stephandler__so_test_terminate() { string? stepResult = null; const string name = "undefined-next-step/cookFood"; diff --git a/src/Product/GreenFeetWorkFlow/WorkflowRuntimeData.cs b/src/Product/GreenFeetWorkFlow/WorkflowRuntimeData.cs index c758fd0..fb9cae5 100644 --- a/src/Product/GreenFeetWorkFlow/WorkflowRuntimeData.cs +++ b/src/Product/GreenFeetWorkFlow/WorkflowRuntimeData.cs @@ -15,8 +15,9 @@ public WorkflowRuntimeData(IWorkflowIocContainer iocContainer, IWorkflowStepStat this.WorkerCoordinator = workerCoordinator; } + // TODO unittest /// Reschedule a ready step to 'now' and send it activation data - public async Task ActivateStepAsync(int id, object? activationArguments, object? transaction = null) + public int ActivateStep(int id, object? activationArguments, object? transaction = null) { var persister = iocContainer.GetInstance(); @@ -31,7 +32,7 @@ public async Task ActivateStepAsync(int id, object? activationArguments, ob return persister.Update(StepStatus.Ready, step); }, transaction); - return await Task.FromResult(rows); + return rows; } /// @@ -54,26 +55,26 @@ public async Task ActivateStepAsync(int id, object? activationArguments, ob /// Add step to be executed. May throw exception if persistence layer fails. For example when inserting multiple singleton elements /// the identity of the step - public async Task AddStepAsync(Step step, object? transaction = null) => (await AddStepsAsync(new[] { step }, transaction)).Single(); + public int AddStep(Step step, object? transaction = null) => AddSteps(new[] { step }, transaction).Single(); /// Add steps to be executed. May throw exception if persistence layer fails. For example when inserting multiple singleton elements /// the identity of the steps - public async Task AddStepsAsync(Step[] steps, object? transaction = null) + public int[] AddSteps(Step[] steps, object? transaction = null) { var now = DateTime.Now; - foreach (var x in steps) + foreach (var step in steps) { - FixupNewStep(null, x, now); + FixupNewStep(null, step, now); } IStepPersister persister = iocContainer.GetInstance(); var result = persister.InTransaction(() => persister.Insert(StepStatus.Ready, steps), transaction); - return await Task.FromResult(result); Worker.ResetWaitForWorkers(); WorkerCoordinator?.TryAddWorker(); + return result; } /// Add steps to be executed. May throw exception if persistence layer fails. For example when inserting multiple singleton elements. @@ -114,18 +115,18 @@ internal void FixupNewStep(Step? originStep, Step step, DateTime now) FormatStateForSerialization(step); } - public async Task> SearchStepsAsync(SearchModel criteria, StepStatus target, object? transaction = null) + public List SearchSteps(SearchModel criteria, StepStatus target, object? transaction = null) { IStepPersister persister = iocContainer.GetInstance(); var result = persister.InTransaction(() => persister.SearchSteps(criteria, target), transaction); - return await Task.FromResult(result); + return result; } - public async Task>> SearchStepsAsync(SearchModel criteria, FetchLevels fetchLevels, object? transaction = null) + public Dictionary> SearchSteps(SearchModel criteria, FetchLevels fetchLevels, object? transaction = null) { IStepPersister persister = iocContainer.GetInstance(); var result = persister.InTransaction(() => persister.SearchSteps(criteria, fetchLevels), transaction); - return await Task.FromResult(result); + return result; } /// Re-execute steps that are 'done' or 'failed' by inserting a clone into the 'ready' queue @@ -181,7 +182,7 @@ public int[] ReExecuteSteps(SearchModel criteria, FetchLevels stepKinds, object? /// /// /// The ids of the failed steps - public async Task FailStepsAsync(SearchModel criteria, object? transaction = null) + public int[] FailSteps(SearchModel criteria, object? transaction = null) { IStepPersister persister = iocContainer.GetInstance(); @@ -198,7 +199,7 @@ public async Task FailStepsAsync(SearchModel criteria, object? transactio return steps.Select(x => x.Id).ToArray(); }, transaction); - return await Task.FromResult(ids); + return ids; } /// we round down to ensure a worker can pick up the step/rerun-step. if in unittest mode it may exit if not rounded. @@ -229,4 +230,4 @@ internal void FormatStateForSerialization(Step step) throw new Exception($"No formatter registered for format name '{step.StateFormat}'"); } } -} \ No newline at end of file +}