Skip to content

Commit 5fefd46

Browse files
authored
Fixed flaky test for delay activity - TestResumeWithDelay
Fixed flaky test - TestResumeWithDelay
2 parents a85438b + cfd3ab2 commit 5fefd46

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

src/Test/TestCases.Runtime/WorflowInstanceResumeBookmarkAsyncTests.cs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -394,24 +394,38 @@ public void SuspensionLeadsToBookmarkCreation()
394394
[Fact]
395395
public static void TestResumeWithDelay()
396396
{
397-
var testSequence = new TestSequence()
397+
var testSequence = new Sequence()
398398
{
399399
Activities =
400400
{
401-
new TestDelay()
401+
new Delay()
402402
{
403-
Duration = TimeSpan.FromMilliseconds(200)
403+
Duration = TimeSpan.FromMilliseconds(100)
404404
},
405405
}
406406
};
407-
WorkflowApplicationTestExtensions.Persistence.FileInstanceStore jsonStore = new WorkflowApplicationTestExtensions.Persistence.FileInstanceStore(".\\~");
408-
TestWorkflowRuntime workflowRuntime = TestRuntime.CreateTestWorkflowRuntime(testSequence, null, jsonStore, PersistableIdleAction.Unload);
409-
workflowRuntime.ExecuteWorkflow();
410-
workflowRuntime.PersistWorkflow();
411-
workflowRuntime.WaitForUnloaded();
412-
workflowRuntime.LoadWorkflow();
413-
workflowRuntime.ResumeWorkflow();
414-
workflowRuntime.WaitForCompletion(false);
407+
408+
using var unloaded = new ManualResetEvent(false);
409+
using var completed = new ManualResetEvent(false);
410+
var instanceStore = new MemoryInstanceStore();
411+
412+
WorkflowApplication workflowApplication = new WorkflowApplication(testSequence);
413+
workflowApplication.InstanceStore = instanceStore;
414+
workflowApplication.PersistableIdle = (_) => PersistableIdleAction.Unload;
415+
workflowApplication.Unloaded = (_) => unloaded.Set();
416+
417+
workflowApplication.Run();
418+
var workflowInstanceId = workflowApplication.Id;
419+
unloaded.WaitOne(); // Wait for workflow to unload after persistable idle
420+
421+
// Create a new WorkflowApplication instance to load and resume the workflow
422+
WorkflowApplication resumedApplication = new WorkflowApplication(testSequence);
423+
resumedApplication.InstanceStore = instanceStore;
424+
resumedApplication.Completed = (_) => completed.Set();
425+
426+
resumedApplication.Load(workflowInstanceId);
427+
resumedApplication.Run(); // Resume the workflow
428+
completed.WaitOne(); // Wait for workflow to complete
415429
}
416430
[Fact]
417431
public static void TestNoPersistSerialization()

0 commit comments

Comments
 (0)