From 2fd6f5b2e835058a6dcb123387e565ab9ec99480 Mon Sep 17 00:00:00 2001 From: MregXN <46479059+MregXN@users.noreply.github.com> Date: Thu, 30 Nov 2023 14:52:52 +0800 Subject: [PATCH] add e2e test of workflow parallel execution (#7237) * original e2e test about workflow parallel execution Signed-off-by: MregXN * fix conlicts Signed-off-by: MregXN --------- Signed-off-by: MregXN Signed-off-by: MregXN <46479059+MregXN@users.noreply.github.com> Co-authored-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com> --- tests/apps/workflowsapp/Startup.cs | 12 +++++++++++- tests/e2e/workflows/workflow_test.go | 16 ++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/apps/workflowsapp/Startup.cs b/tests/apps/workflowsapp/Startup.cs index db7a7c7a438..de1496def8c 100644 --- a/tests/apps/workflowsapp/Startup.cs +++ b/tests/apps/workflowsapp/Startup.cs @@ -57,7 +57,17 @@ public void ConfigureServices(IServiceCollection services) var itemToPurchase = input; itemToPurchase = await context.WaitForExternalEventAsync("ChangePurchaseItem"); - + // Parallel Execution - Waiting for all tasks to finish + Task t1 = context.WaitForExternalEventAsync("ConfirmSize", TimeSpan.FromSeconds(10)); + Task t2 = context.WaitForExternalEventAsync("ConfirmColor", TimeSpan.FromSeconds(10)); + Task t3 = context.WaitForExternalEventAsync("ConfirmAddress", TimeSpan.FromSeconds(10)); + await Task.WhenAll(t1, t2, t3); + // Parallel Execution - Waiting for any task to finish + Task e1 = context.WaitForExternalEventAsync("PayInCash", TimeSpan.FromSeconds(10)); + Task e2 = context.WaitForExternalEventAsync("PayByCard", TimeSpan.FromSeconds(10)); + Task e3 = context.WaitForExternalEventAsync("PayOnline", TimeSpan.FromSeconds(10)); + await Task.WhenAny(e1, e2, e3); + // In real life there are other steps related to placing an order, like reserving // inventory and charging the customer credit card etc. But let's keep it simple ;) await context.CallActivityAsync("ShipProduct", itemToPurchase); diff --git a/tests/e2e/workflows/workflow_test.go b/tests/e2e/workflows/workflow_test.go index 00ed176d919..a304bb65849 100644 --- a/tests/e2e/workflows/workflow_test.go +++ b/tests/e2e/workflows/workflow_test.go @@ -147,6 +147,22 @@ func raiseEventTest(url string, instanceID string) func(t *testing.T) { resp, err = utils.HTTPPost(fmt.Sprintf("%s/RaiseWorkflowEvent/dapr/%s/ChangePurchaseItem/1", url, instanceID), nil) require.NoError(t, err, "failure raising event on workflow") + // Raise parallel events on the workflow + resp, err = utils.HTTPPost(fmt.Sprintf("%s/RaiseWorkflowEvent/dapr/%s/ConfirmSize/1", url, instanceID), nil) + require.NoError(t, err, "failure raising event on workflow") + + resp, err = utils.HTTPPost(fmt.Sprintf("%s/RaiseWorkflowEvent/dapr/%s/ConfirmColor/1", url, instanceID), nil) + require.NoError(t, err, "failure raising event on workflow") + + resp, err = utils.HTTPPost(fmt.Sprintf("%s/RaiseWorkflowEvent/dapr/%s/ConfirmAddress/1", url, instanceID), nil) + require.NoError(t, err, "failure raising event on workflow") + + // Raise a parallel event on the workflow + resp, err = utils.HTTPPost(fmt.Sprintf("%s/RaiseWorkflowEvent/dapr/%s/PayByCard/1", url, instanceID), nil) + require.NoError(t, err, "failure raising event on workflow") + + time.Sleep(10 * time.Second) + require.EventuallyWithT(t, func(t *assert.CollectT) { resp, err = utils.HTTPGet(getString) assert.NoError(t, err, "failure getting info on workflow")