Skip to content

Commit 0509e6f

Browse files
Copilotdanielgerlag
andcommitted
Update test to verify async step behavior more thoroughly
Co-authored-by: danielgerlag <[email protected]>
1 parent f43d460 commit 0509e6f

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

test/WorkflowCore.IntegrationTests/Scenarios/StopAsyncScenario.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,27 @@ public async Task StopAsync_should_wait_for_running_steps_to_complete()
6565
var workflowId = await Host.StartWorkflow<Object>("StopAsyncWorkflow", null);
6666

6767
// Wait for the step to start executing
68-
await Task.Delay(500);
69-
var stepStartedTime = DateTime.Now;
68+
var waitCount = 0;
69+
while (StopAsyncWorkflow.StepStartTime == null && waitCount < 50)
70+
{
71+
await Task.Delay(100);
72+
waitCount++;
73+
}
74+
75+
StopAsyncWorkflow.StepStartTime.Should().NotBeNull("the step should have started before stopping");
76+
StopAsyncWorkflow.StepEndTime.Should().BeNull("the step should still be running");
7077

7178
// Act - Call StopAsync which should wait for the step to complete
7279
var stopwatch = Stopwatch.StartNew();
7380
await Host.StopAsync(default);
7481
stopwatch.Stop();
7582

7683
// Assert
77-
// The step should have started
78-
StopAsyncWorkflow.StepStartTime.Should().NotBeNull("the step should have started");
79-
8084
// The step should have completed
8185
StopAsyncWorkflow.StepEndTime.Should().NotBeNull("the step should have completed before StopAsync returned");
8286

83-
// StopAsync should have taken at least 4 seconds (5 seconds delay minus the 500ms we waited)
84-
stopwatch.ElapsedMilliseconds.Should().BeGreaterThan(4000,
87+
// StopAsync should have taken at least 3 seconds (the remaining delay time)
88+
stopwatch.ElapsedMilliseconds.Should().BeGreaterOrEqualTo(3000,
8589
"StopAsync should wait for the running step to complete");
8690
}
8791

0 commit comments

Comments
 (0)