44using Xunit ;
55using FluentAssertions ;
66using WorkflowCore . Testing ;
7- using System . Threading ;
7+ using System . Threading . Tasks ;
8+ using Microsoft . Extensions . DependencyInjection ;
89
910namespace WorkflowCore . IntegrationTests . Scenarios
1011{
@@ -19,45 +20,42 @@ public class MyDataClass
1920 public string StrValue2 { get ; set ; }
2021 }
2122
23+ public class SomeTask : StepBodyAsync
24+ {
25+ public TimeSpan Delay { get ; set ; }
26+
27+ public override async Task < ExecutionResult > RunAsync ( IStepExecutionContext context )
28+ {
29+ await Task . Delay ( Delay ) ;
30+
31+ return ExecutionResult . Next ( ) ;
32+ }
33+ }
34+
2235 public class ParallelEventsWorkflow : IWorkflow < MyDataClass >
2336 {
24- public string Id => "EventWorkflow" ;
37+ public string Id => nameof ( ParallelEventsScenario ) ;
2538 public int Version => 1 ;
2639 public void Build ( IWorkflowBuilder < MyDataClass > builder )
2740 {
2841 builder
2942 . StartWith ( context => ExecutionResult . Next ( ) )
3043 . Parallel ( )
3144 . Do ( then =>
32- then . WaitFor ( "Event1" , data => EVENT_KEY ) . Then ( x =>
33- {
34- Thread . Sleep ( 300 ) ;
35- return ExecutionResult . Next ( ) ;
36- } ) )
45+ then . WaitFor ( "Event1" , data => EVENT_KEY ) . Then < SomeTask > ( )
46+ . Input ( step => step . Delay , data => TimeSpan . FromMilliseconds ( 2000 ) ) )
3747 . Do ( then =>
38- then . WaitFor ( "Event2" , data => EVENT_KEY ) . Then ( x =>
39- {
40- Thread . Sleep ( 100 ) ;
41- return ExecutionResult . Next ( ) ;
42- } ) )
48+ then . WaitFor ( "Event2" , data => EVENT_KEY ) . Then < SomeTask > ( )
49+ . Input ( step => step . Delay , data => TimeSpan . FromMilliseconds ( 2000 ) ) )
4350 . Do ( then =>
44- then . WaitFor ( "Event3" , data => EVENT_KEY ) . Then ( x =>
45- {
46- Thread . Sleep ( 1000 ) ;
47- return ExecutionResult . Next ( ) ;
48- } ) )
51+ then . WaitFor ( "Event3" , data => EVENT_KEY ) . Then < SomeTask > ( )
52+ . Input ( step => step . Delay , data => TimeSpan . FromMilliseconds ( 5000 ) ) )
4953 . Do ( then =>
50- then . WaitFor ( "Event4" , data => EVENT_KEY ) . Then ( x =>
51- {
52- Thread . Sleep ( 100 ) ;
53- return ExecutionResult . Next ( ) ;
54- } ) )
54+ then . WaitFor ( "Event4" , data => EVENT_KEY ) . Then < SomeTask > ( )
55+ . Input ( step => step . Delay , data => TimeSpan . FromMilliseconds ( 100 ) ) )
5556 . Do ( then =>
56- then . WaitFor ( "Event5" , data => EVENT_KEY ) . Then ( x =>
57- {
58- Thread . Sleep ( 100 ) ;
59- return ExecutionResult . Next ( ) ;
60- } ) )
57+ then . WaitFor ( "Event5" , data => EVENT_KEY ) . Then < SomeTask > ( )
58+ . Input ( step => step . Delay , data => TimeSpan . FromMilliseconds ( 100 ) ) )
6159 . Join ( )
6260 . Then ( x =>
6361 {
@@ -71,16 +69,21 @@ public ParallelEventsScenario()
7169 Setup ( ) ;
7270 }
7371
72+ protected override void ConfigureServices ( IServiceCollection services )
73+ {
74+ services . AddWorkflow ( s => s . UsePollInterval ( TimeSpan . FromSeconds ( 1 ) ) ) ;
75+ }
76+
7477 [ Fact ]
75- public void Scenario ( )
78+ public async Task Scenario ( )
7679 {
7780 var eventKey = Guid . NewGuid ( ) . ToString ( ) ;
78- var workflowId = StartWorkflow ( new MyDataClass { StrValue1 = eventKey , StrValue2 = eventKey } ) ;
79- Host . PublishEvent ( "Event1" , EVENT_KEY , "Pass1" ) ;
80- Host . PublishEvent ( "Event2" , EVENT_KEY , "Pass2" ) ;
81- Host . PublishEvent ( "Event3" , EVENT_KEY , "Pass3" ) ;
82- Host . PublishEvent ( "Event4" , EVENT_KEY , "Pass4" ) ;
83- Host . PublishEvent ( "Event5" , EVENT_KEY , "Pass5" ) ;
81+ var workflowId = await StartWorkflowAsync ( new MyDataClass { StrValue1 = eventKey , StrValue2 = eventKey } ) ;
82+ await Host . PublishEvent ( "Event1" , EVENT_KEY , "Pass1" ) ;
83+ await Host . PublishEvent ( "Event2" , EVENT_KEY , "Pass2" ) ;
84+ await Host . PublishEvent ( "Event3" , EVENT_KEY , "Pass3" ) ;
85+ await Host . PublishEvent ( "Event4" , EVENT_KEY , "Pass4" ) ;
86+ await Host . PublishEvent ( "Event5" , EVENT_KEY , "Pass5" ) ;
8487
8588 WaitForWorkflowToComplete ( workflowId , TimeSpan . FromSeconds ( 30 ) ) ;
8689
0 commit comments