Skip to content

Commit

Permalink
Support returning WorkflowExecutionAlreadyStartedError in tests (#969)
Browse files Browse the repository at this point in the history
Co-authored-by: Liang Mei <meiliang86@gmail.com>
  • Loading branch information
seriousben and meiliang86 committed May 29, 2020
1 parent 73c0dfb commit 6f8baa1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/internal_workflow_testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ func (env *testWorkflowEnvironmentImpl) Complete(result []byte, err error) {

if err != nil {
switch err := err.(type) {
case *CanceledError, *ContinueAsNewError, *TimeoutError:
case *CanceledError, *ContinueAsNewError, *TimeoutError, *shared.WorkflowExecutionAlreadyStartedError:
env.testError = err
case *workflowPanicError:
env.testError = newPanicError(err.value, err.stackTrace)
Expand Down
36 changes: 35 additions & 1 deletion internal/internal_workflow_testsuite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2569,6 +2569,40 @@ func (s *WorkflowTestSuiteUnitTest) Test_SameActivityIDFromDifferentChildWorkflo
s.Equal("hello_child_1 hello_child_2", actualResult)
}

func (s *WorkflowTestSuiteUnitTest) Test_MockChildWorkflowAlreadyRunning() {
childWorkflowFn := func(ctx Context) error {
return nil
}

runID := "run-id"
workflowFn := func(ctx Context) error {
cwo := ChildWorkflowOptions{
ExecutionStartToCloseTimeout: time.Minute,
}
ctx = WithChildWorkflowOptions(ctx, cwo)
err := ExecuteChildWorkflow(ctx, childWorkflowFn).Get(ctx, nil)
s.Error(err)

alreadySytartedErr, ok := err.(*shared.WorkflowExecutionAlreadyStartedError)
s.True(ok)
s.Equal(runID, *alreadySytartedErr.RunId)

return nil
}

env := s.NewTestWorkflowEnvironment()
RegisterWorkflow(childWorkflowFn)
RegisterWorkflow(workflowFn)

env.OnWorkflow(childWorkflowFn, mock.Anything).
Return(&shared.WorkflowExecutionAlreadyStartedError{
RunId: &runID,
})

env.ExecuteWorkflow(workflowFn)
s.NoError(env.GetWorkflowError())
}

func (s *WorkflowTestSuiteUnitTest) Test_ChildWorkflowAlreadyRunning() {
workflowFn := func(ctx Context) (string, error) {
ctx1 := WithChildWorkflowOptions(ctx, ChildWorkflowOptions{
Expand Down Expand Up @@ -2841,7 +2875,7 @@ func (s *WorkflowTestSuiteUnitTest) Test_AwaitWithTimeout() {
workflowFn := func(ctx Context) (bool, error) {
t := NewTimer(ctx, time.Second)
value := false
err := Await(ctx, func() bool { return t.IsReady() || value})
err := Await(ctx, func() bool { return t.IsReady() || value })
return value, err
}

Expand Down

0 comments on commit 6f8baa1

Please sign in to comment.