@@ -428,7 +428,11 @@ func (env *testWorkflowEnvironmentImpl) setContinuedExecutionRunID(rid string) {
428
428
env .workflowInfo .ContinuedExecutionRunID = rid
429
429
}
430
430
431
- func (env * testWorkflowEnvironmentImpl ) newTestWorkflowEnvironmentForChild (params * ExecuteWorkflowParams , callback ResultHandler , startedHandler func (r WorkflowExecution , e error )) (* testWorkflowEnvironmentImpl , error ) {
431
+ func (env * testWorkflowEnvironmentImpl ) newTestWorkflowEnvironmentForChild (
432
+ params * ExecuteWorkflowParams ,
433
+ callback ResultHandler ,
434
+ startedHandler func (r WorkflowExecution , e error ),
435
+ ) (* testWorkflowEnvironmentImpl , error ) {
432
436
// create a new test env
433
437
childEnv := newTestWorkflowEnvironmentImpl (env .testSuite , env .registry )
434
438
childEnv .parentEnv = env
@@ -474,15 +478,27 @@ func (env *testWorkflowEnvironmentImpl) newTestWorkflowEnvironmentForChild(param
474
478
475
479
childEnv .runTimeout = params .WorkflowRunTimeout
476
480
if workflowHandler , ok := env .runningWorkflows [params .WorkflowID ]; ok {
481
+ alreadyStartedErr := serviceerror .NewWorkflowExecutionAlreadyStarted (
482
+ "Workflow execution already started" ,
483
+ "" ,
484
+ childEnv .workflowInfo .WorkflowExecution .RunID ,
485
+ )
477
486
// duplicate workflow ID
478
487
if ! workflowHandler .handled {
479
- return nil , serviceerror .NewWorkflowExecutionAlreadyStarted ("Workflow execution already started" , "" , "" )
488
+ if params .WorkflowIDConflictPolicy == enumspb .WORKFLOW_ID_CONFLICT_POLICY_USE_EXISTING {
489
+ if params .OnConflictOptions != nil && params .OnConflictOptions .AttachCompletionCallbacks {
490
+ workflowHandler .callback = workflowHandler .callback .wrap (callback )
491
+ }
492
+ startedHandler (workflowHandler .env .workflowInfo .WorkflowExecution , nil )
493
+ return nil , nil
494
+ }
495
+ return nil , alreadyStartedErr
480
496
}
481
497
if params .WorkflowIDReusePolicy == enumspb .WORKFLOW_ID_REUSE_POLICY_REJECT_DUPLICATE {
482
- return nil , serviceerror . NewWorkflowExecutionAlreadyStarted ( "Workflow execution already started" , "" , "" )
498
+ return nil , alreadyStartedErr
483
499
}
484
500
if workflowHandler .err == nil && params .WorkflowIDReusePolicy == enumspb .WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY {
485
- return nil , serviceerror . NewWorkflowExecutionAlreadyStarted ( "Workflow execution already started" , "" , "" )
501
+ return nil , alreadyStartedErr
486
502
}
487
503
}
488
504
@@ -2380,16 +2396,20 @@ func (env *testWorkflowEnvironmentImpl) executeChildWorkflowWithDelay(delayStart
2380
2396
childEnv , err := env .newTestWorkflowEnvironmentForChild (& params , callback , startedHandler )
2381
2397
if err != nil {
2382
2398
env .logger .Info ("ExecuteChildWorkflow failed" , tagError , err )
2383
- callback (nil , err )
2384
2399
startedHandler (WorkflowExecution {}, err )
2400
+ callback (nil , err )
2385
2401
return
2386
2402
}
2387
2403
2388
- env .logger .Info ("ExecuteChildWorkflow" , tagWorkflowType , params .WorkflowType .Name )
2389
- env .runningCount ++
2404
+ // childEnv can be nil when WorkflowIDConflictPolicy is USE_EXISTING and there's already a running
2405
+ // workflow. This is only possible in the test environment for running Nexus handler workflow.
2406
+ if childEnv != nil {
2407
+ env .logger .Info ("ExecuteChildWorkflow" , tagWorkflowType , params .WorkflowType .Name )
2408
+ env .runningCount ++
2390
2409
2391
- // run child workflow in separate goroutinue
2392
- go childEnv .executeWorkflowInternal (delayStart , params .WorkflowType .Name , params .Input )
2410
+ // run child workflow in separate goroutinue
2411
+ go childEnv .executeWorkflowInternal (delayStart , params .WorkflowType .Name , params .Input )
2412
+ }
2393
2413
}
2394
2414
2395
2415
func (env * testWorkflowEnvironmentImpl ) newTestNexusTaskHandler (
0 commit comments