Skip to content

Commit

Permalink
Enrich E2E test logic of workflow (#7285)
Browse files Browse the repository at this point in the history
* modify e2e workflow purge test

Signed-off-by: MregXN <mregxn@gmail.com>

* modify pauseResumeTest

Signed-off-by: MregXN <mregxn@gmail.com>

---------

Signed-off-by: MregXN <mregxn@gmail.com>
Co-authored-by: Loong Dai <long.dai@intel.com>
Co-authored-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com>
  • Loading branch information
3 people committed Jan 9, 2024
1 parent 3ddf46a commit 328b4b3
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion tests/e2e/workflows/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ func pauseResumeTest(url string, instanceID string) func(t *testing.T) {
assert.Equalf(t, "Running", string(resp), "expected workflow to be Running, actual workflow state is: %s", string(resp))
}, 5*time.Second, 100*time.Millisecond)

// Raise an event on the workflow
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")

// Pause the workflow
resp, err = utils.HTTPPost(fmt.Sprintf("%s/PauseWorkflow/dapr/%s", url, instanceID), nil)
require.NoError(t, err, "failure pausing workflow")
Expand All @@ -121,10 +135,16 @@ func pauseResumeTest(url string, instanceID string) func(t *testing.T) {
resp, err = utils.HTTPPost(fmt.Sprintf("%s/ResumeWorkflow/dapr/%s", url, instanceID), nil)
require.NoError(t, err, "failure resuming 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(5 * time.Second)

require.EventuallyWithT(t, func(t *assert.CollectT) {
resp, err = utils.HTTPGet(getString)
require.NoError(t, err, "failure getting info on workflow")
assert.Equalf(t, "Running", string(resp), "expected workflow to be Running, actual workflow state is: %s", string(resp))
assert.Equalf(t, "Completed", string(resp), "expected workflow to be Running, actual workflow state is: %s", string(resp))
}, 5*time.Second, 100*time.Millisecond)
}
}
Expand Down Expand Up @@ -186,6 +206,20 @@ func purgeTest(url string, instanceID string) func(t *testing.T) {
assert.Equalf(t, "Running", string(resp), "expected workflow to be Running, actual workflow state is: %s", string(resp))
}, 5*time.Second, 100*time.Millisecond)

// Raise an event on the workflow
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")

// Terminate the workflow
resp, err = utils.HTTPPost(fmt.Sprintf("%s/TerminateWorkflow/dapr/%s", url, instanceID), nil)
require.NoError(t, err, "failure terminating workflow")
Expand All @@ -211,6 +245,19 @@ func purgeTest(url string, instanceID string) func(t *testing.T) {
require.NoError(t, err, "failure getting info on workflow")
assert.Equalf(t, "Running", string(resp), "expected workflow to be Running, actual workflow state is: %s", string(resp))
}, 5*time.Second, 100*time.Millisecond)

// 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(5 * time.Second)

// Purge will clear the instance data. There are insufficient triggered events which lead to the failure.
require.EventuallyWithT(t, func(t *assert.CollectT) {
resp, err = utils.HTTPGet(getString)
require.NoError(t, err, "failure getting info on workflow")
assert.NotEqualf(t, "Completed", string(resp), "expected workflow not to be Completed, actual workflow state is: %s", string(resp))
}, 5*time.Second, 100*time.Millisecond)
}
}

Expand Down

0 comments on commit 328b4b3

Please sign in to comment.