Skip to content

Commit 4e06a49

Browse files
seriousbenmeiliang86
authored andcommitted
Support returning WorkflowExecutionAlreadyStartedError in tests (#969)
Co-authored-by: Liang Mei <meiliang86@gmail.com>
1 parent ffd73d9 commit 4e06a49

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

internal/internal_workflow_testsuite.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ func (env *testWorkflowEnvironmentImpl) Complete(result []byte, err error) {
764764

765765
if err != nil {
766766
switch err := err.(type) {
767-
case *CanceledError, *ContinueAsNewError, *TimeoutError:
767+
case *CanceledError, *ContinueAsNewError, *TimeoutError, *shared.WorkflowExecutionAlreadyStartedError:
768768
env.testError = err
769769
case *workflowPanicError:
770770
env.testError = newPanicError(err.value, err.stackTrace)

internal/internal_workflow_testsuite_test.go

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2569,6 +2569,40 @@ func (s *WorkflowTestSuiteUnitTest) Test_SameActivityIDFromDifferentChildWorkflo
25692569
s.Equal("hello_child_1 hello_child_2", actualResult)
25702570
}
25712571

2572+
func (s *WorkflowTestSuiteUnitTest) Test_MockChildWorkflowAlreadyRunning() {
2573+
childWorkflowFn := func(ctx Context) error {
2574+
return nil
2575+
}
2576+
2577+
runID := "run-id"
2578+
workflowFn := func(ctx Context) error {
2579+
cwo := ChildWorkflowOptions{
2580+
ExecutionStartToCloseTimeout: time.Minute,
2581+
}
2582+
ctx = WithChildWorkflowOptions(ctx, cwo)
2583+
err := ExecuteChildWorkflow(ctx, childWorkflowFn).Get(ctx, nil)
2584+
s.Error(err)
2585+
2586+
alreadySytartedErr, ok := err.(*shared.WorkflowExecutionAlreadyStartedError)
2587+
s.True(ok)
2588+
s.Equal(runID, *alreadySytartedErr.RunId)
2589+
2590+
return nil
2591+
}
2592+
2593+
env := s.NewTestWorkflowEnvironment()
2594+
RegisterWorkflow(childWorkflowFn)
2595+
RegisterWorkflow(workflowFn)
2596+
2597+
env.OnWorkflow(childWorkflowFn, mock.Anything).
2598+
Return(&shared.WorkflowExecutionAlreadyStartedError{
2599+
RunId: &runID,
2600+
})
2601+
2602+
env.ExecuteWorkflow(workflowFn)
2603+
s.NoError(env.GetWorkflowError())
2604+
}
2605+
25722606
func (s *WorkflowTestSuiteUnitTest) Test_ChildWorkflowAlreadyRunning() {
25732607
workflowFn := func(ctx Context) (string, error) {
25742608
ctx1 := WithChildWorkflowOptions(ctx, ChildWorkflowOptions{
@@ -2841,7 +2875,7 @@ func (s *WorkflowTestSuiteUnitTest) Test_AwaitWithTimeout() {
28412875
workflowFn := func(ctx Context) (bool, error) {
28422876
t := NewTimer(ctx, time.Second)
28432877
value := false
2844-
err := Await(ctx, func() bool { return t.IsReady() || value})
2878+
err := Await(ctx, func() bool { return t.IsReady() || value })
28452879
return value, err
28462880
}
28472881

0 commit comments

Comments
 (0)