Skip to content

Commit

Permalink
Adding in new test for parallel raise events in workflow (#1155)
Browse files Browse the repository at this point in the history
* Adding in new test for parallel raise events in workflow

Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
  • Loading branch information
RyanLettieri authored and halspang committed Oct 6, 2023
1 parent 99d874a commit feb7039
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions test/Dapr.E2E.Test.App/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public void ConfigureServices(IServiceCollection services)
var itemToPurchase = input;
// There are 5 of the same event to test that multiple similarly-named events can be raised in parallel
await context.WaitForExternalEventAsync<string>("ChangePurchaseItem");
await context.WaitForExternalEventAsync<string>("ChangePurchaseItem");
await context.WaitForExternalEventAsync<string>("ChangePurchaseItem");
await context.WaitForExternalEventAsync<string>("ChangePurchaseItem");
itemToPurchase = await context.WaitForExternalEventAsync<string>("ChangePurchaseItem");
// In real life there are other steps related to placing an order, like reserving
Expand Down
12 changes: 10 additions & 2 deletions test/Dapr.E2E.Test/Workflows/WorkflowTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,16 @@ public async Task TestWorkflows()
input: input,
workflowOptions: workflowOptions);

// RAISE EVENT TEST
await daprClient.RaiseWorkflowEventAsync(instanceId2, workflowComponent, "ChangePurchaseItem", "computers");
// PARALLEL RAISE EVENT TEST
var event1 = daprClient.RaiseWorkflowEventAsync(instanceId2, workflowComponent, "ChangePurchaseItem", "computers");
var event2 = daprClient.RaiseWorkflowEventAsync(instanceId2, workflowComponent, "ChangePurchaseItem", "computers");
var event3 = daprClient.RaiseWorkflowEventAsync(instanceId2, workflowComponent, "ChangePurchaseItem", "computers");
var event4 = daprClient.RaiseWorkflowEventAsync(instanceId2, workflowComponent, "ChangePurchaseItem", "computers");
var event5 = daprClient.RaiseWorkflowEventAsync(instanceId2, workflowComponent, "ChangePurchaseItem", "computers");

var externalEvents = Task.WhenAll(event1, event2, event3, event4, event5);
var winner = await Task.WhenAny(externalEvents, Task.Delay(TimeSpan.FromSeconds(30)));
externalEvents.IsCompletedSuccessfully.Should().BeTrue($"Unsuccessful at raising events. Status of events: {externalEvents.IsCompletedSuccessfully}");

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

0 comments on commit feb7039

Please sign in to comment.