Skip to content

Commit

Permalink
add e2e test of workflow parallel execution (dapr#7237)
Browse files Browse the repository at this point in the history
* original e2e test about workflow parallel execution

Signed-off-by: MregXN <[email protected]>

* fix conlicts

Signed-off-by: MregXN <[email protected]>

---------

Signed-off-by: MregXN <[email protected]>
Signed-off-by: MregXN <46479059 [email protected]>
Co-authored-by: Mukundan Sundararajan <65565396 [email protected]>
  • Loading branch information
MregXN and mukundansundar authored Nov 30, 2023
1 parent d51d17f commit 2fd6f5b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
12 changes: 11 additions & 1 deletion tests/apps/workflowsapp/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 57,17 @@ public void ConfigureServices(IServiceCollection services)
var itemToPurchase = input;
itemToPurchase = await context.WaitForExternalEventAsync<string>("ChangePurchaseItem");
// Parallel Execution - Waiting for all tasks to finish
Task<string> t1 = context.WaitForExternalEventAsync<string>("ConfirmSize", TimeSpan.FromSeconds(10));
Task<string> t2 = context.WaitForExternalEventAsync<string>("ConfirmColor", TimeSpan.FromSeconds(10));
Task<string> t3 = context.WaitForExternalEventAsync<string>("ConfirmAddress", TimeSpan.FromSeconds(10));
await Task.WhenAll(t1, t2, t3);
// Parallel Execution - Waiting for any task to finish
Task<string> e1 = context.WaitForExternalEventAsync<string>("PayInCash", TimeSpan.FromSeconds(10));
Task<string> e2 = context.WaitForExternalEventAsync<string>("PayByCard", TimeSpan.FromSeconds(10));
Task<string> e3 = context.WaitForExternalEventAsync<string>("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<string>("ShipProduct", itemToPurchase);
Expand Down
16 changes: 16 additions & 0 deletions tests/e2e/workflows/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 2fd6f5b

Please sign in to comment.