From feb70396fa0fe45d3482a8bb37214ad12aa451f8 Mon Sep 17 00:00:00 2001 From: Ryan Lettieri <67934986+RyanLettieri@users.noreply.github.com> Date: Fri, 6 Oct 2023 12:37:38 -0600 Subject: [PATCH] Adding in new test for parallel raise events in workflow (#1155) * Adding in new test for parallel raise events in workflow Signed-off-by: Ryan Lettieri --- test/Dapr.E2E.Test.App/Startup.cs | 5 +++++ test/Dapr.E2E.Test/Workflows/WorkflowTest.cs | 12 ++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/test/Dapr.E2E.Test.App/Startup.cs b/test/Dapr.E2E.Test.App/Startup.cs index 34e1b2eb8..d1f291bf9 100644 --- a/test/Dapr.E2E.Test.App/Startup.cs +++ b/test/Dapr.E2E.Test.App/Startup.cs @@ -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("ChangePurchaseItem"); + await context.WaitForExternalEventAsync("ChangePurchaseItem"); + await context.WaitForExternalEventAsync("ChangePurchaseItem"); + await context.WaitForExternalEventAsync("ChangePurchaseItem"); itemToPurchase = await context.WaitForExternalEventAsync("ChangePurchaseItem"); // In real life there are other steps related to placing an order, like reserving diff --git a/test/Dapr.E2E.Test/Workflows/WorkflowTest.cs b/test/Dapr.E2E.Test/Workflows/WorkflowTest.cs index ae30a9151..971d04098 100644 --- a/test/Dapr.E2E.Test/Workflows/WorkflowTest.cs +++ b/test/Dapr.E2E.Test/Workflows/WorkflowTest.cs @@ -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));