Skip to content

Commit b0992c3

Browse files
Adding in new test for parallel raise events in workflow (#1155) (#1157)
* Adding in new test for parallel raise events in workflow Signed-off-by: Ryan Lettieri <[email protected]> Signed-off-by: Hal Spang <[email protected]> Co-authored-by: Ryan Lettieri <[email protected]>
1 parent 99d874a commit b0992c3

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

test/Dapr.E2E.Test.App/Startup.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ public void ConfigureServices(IServiceCollection services)
7070

7171
var itemToPurchase = input;
7272

73+
// There are 5 of the same event to test that multiple similarly-named events can be raised in parallel
74+
await context.WaitForExternalEventAsync<string>("ChangePurchaseItem");
75+
await context.WaitForExternalEventAsync<string>("ChangePurchaseItem");
76+
await context.WaitForExternalEventAsync<string>("ChangePurchaseItem");
77+
await context.WaitForExternalEventAsync<string>("ChangePurchaseItem");
7378
itemToPurchase = await context.WaitForExternalEventAsync<string>("ChangePurchaseItem");
7479

7580
// In real life there are other steps related to placing an order, like reserving

test/Dapr.E2E.Test/Workflows/WorkflowTest.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,16 @@ public async Task TestWorkflows()
9393
input: input,
9494
workflowOptions: workflowOptions);
9595

96-
// RAISE EVENT TEST
97-
await daprClient.RaiseWorkflowEventAsync(instanceId2, workflowComponent, "ChangePurchaseItem", "computers");
96+
// PARALLEL RAISE EVENT TEST
97+
var event1 = daprClient.RaiseWorkflowEventAsync(instanceId2, workflowComponent, "ChangePurchaseItem", "computers");
98+
var event2 = daprClient.RaiseWorkflowEventAsync(instanceId2, workflowComponent, "ChangePurchaseItem", "computers");
99+
var event3 = daprClient.RaiseWorkflowEventAsync(instanceId2, workflowComponent, "ChangePurchaseItem", "computers");
100+
var event4 = daprClient.RaiseWorkflowEventAsync(instanceId2, workflowComponent, "ChangePurchaseItem", "computers");
101+
var event5 = daprClient.RaiseWorkflowEventAsync(instanceId2, workflowComponent, "ChangePurchaseItem", "computers");
102+
103+
var externalEvents = Task.WhenAll(event1, event2, event3, event4, event5);
104+
var winner = await Task.WhenAny(externalEvents, Task.Delay(TimeSpan.FromSeconds(30)));
105+
externalEvents.IsCompletedSuccessfully.Should().BeTrue($"Unsuccessful at raising events. Status of events: {externalEvents.IsCompletedSuccessfully}");
98106

99107
// Wait up to 30 seconds for the workflow to complete and check the output
100108
using var cts = new CancellationTokenSource(delay: TimeSpan.FromSeconds(30));

0 commit comments

Comments
 (0)