Skip to content

Commit

Permalink
Remove async from methods that were not really async
Browse files Browse the repository at this point in the history
  • Loading branch information
kbilsted committed Jan 30, 2024
1 parent 96f71b7 commit ba55677
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
20 changes: 10 additions & 10 deletions src/Demos/GreenFeetWorkFlow.Tests/AdoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -71,7 +71,7 @@ public async Task When_adding_two_steps_in_the_same_transaction_Then_both_execut
Dictionary<StepStatus, List<Step>> 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 = [(
Expand All @@ -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 }];
Expand All @@ -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";
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand All @@ -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();
Expand All @@ -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";
Expand All @@ -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();

Expand All @@ -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";
Expand Down
29 changes: 15 additions & 14 deletions src/Product/GreenFeetWorkFlow/WorkflowRuntimeData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ public WorkflowRuntimeData(IWorkflowIocContainer iocContainer, IWorkflowStepStat
this.WorkerCoordinator = workerCoordinator;
}

// TODO unittest
/// <summary> Reschedule a ready step to 'now' and send it activation data </summary>
public async Task<int> ActivateStepAsync(int id, object? activationArguments, object? transaction = null)
public int ActivateStep(int id, object? activationArguments, object? transaction = null)
{
var persister = iocContainer.GetInstance<IStepPersister>();

Expand All @@ -31,7 +32,7 @@ public async Task<int> ActivateStepAsync(int id, object? activationArguments, ob
return persister.Update(StepStatus.Ready, step);
},
transaction);
return await Task.FromResult(rows);
return rows;
}

/// <summary>
Expand All @@ -54,26 +55,26 @@ public async Task<int> ActivateStepAsync(int id, object? activationArguments, ob

/// <summary> Add step to be executed. May throw exception if persistence layer fails. For example when inserting multiple singleton elements </summary>
/// <returns>the identity of the step</returns>
public async Task<int> 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();

/// <summary> Add steps to be executed. May throw exception if persistence layer fails. For example when inserting multiple singleton elements </summary>
/// <returns>the identity of the steps</returns>
public async Task<int[]> 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<IStepPersister>();
var result = persister.InTransaction(() => persister.Insert(StepStatus.Ready, steps), transaction);
return await Task.FromResult(result);

Worker.ResetWaitForWorkers();
WorkerCoordinator?.TryAddWorker();

return result;
}

/// <summary> Add steps to be executed. May throw exception if persistence layer fails. For example when inserting multiple singleton elements.
Expand Down Expand Up @@ -114,18 +115,18 @@ internal void FixupNewStep(Step? originStep, Step step, DateTime now)
FormatStateForSerialization(step);
}

public async Task<List<Step>> SearchStepsAsync(SearchModel criteria, StepStatus target, object? transaction = null)
public List<Step> SearchSteps(SearchModel criteria, StepStatus target, object? transaction = null)
{
IStepPersister persister = iocContainer.GetInstance<IStepPersister>();
var result = persister.InTransaction(() => persister.SearchSteps(criteria, target), transaction);
return await Task.FromResult(result);
return result;
}

public async Task<Dictionary<StepStatus, List<Step>>> SearchStepsAsync(SearchModel criteria, FetchLevels fetchLevels, object? transaction = null)
public Dictionary<StepStatus, List<Step>> SearchSteps(SearchModel criteria, FetchLevels fetchLevels, object? transaction = null)
{
IStepPersister persister = iocContainer.GetInstance<IStepPersister>();
var result = persister.InTransaction(() => persister.SearchSteps(criteria, fetchLevels), transaction);
return await Task.FromResult(result);
return result;
}

/// <summary> Re-execute steps that are 'done' or 'failed' by inserting a clone into the 'ready' queue </summary>
Expand Down Expand Up @@ -181,7 +182,7 @@ public int[] ReExecuteSteps(SearchModel criteria, FetchLevels stepKinds, object?
/// <param name="criteria"></param>
/// <param name="transaction"></param>
/// <returns>The ids of the failed steps</returns>
public async Task<int[]> FailStepsAsync(SearchModel criteria, object? transaction = null)
public int[] FailSteps(SearchModel criteria, object? transaction = null)
{
IStepPersister persister = iocContainer.GetInstance<IStepPersister>();

Expand All @@ -198,7 +199,7 @@ public async Task<int[]> FailStepsAsync(SearchModel criteria, object? transactio
return steps.Select(x => x.Id).ToArray();
}, transaction);

return await Task.FromResult(ids);
return ids;
}

/// <summary> we round down to ensure a worker can pick up the step/rerun-step. if in unittest mode it may exit if not rounded. </summary>
Expand Down Expand Up @@ -229,4 +230,4 @@ internal void FormatStateForSerialization(Step step)
throw new Exception($"No formatter registered for format name '{step.StateFormat}'");
}
}
}
}

0 comments on commit ba55677

Please sign in to comment.