Skip to content

Commit 1edd76a

Browse files
committed
Move onChildWorkflowCanceledListener logic into new dispatcher coroutine as well
1 parent ae6d39a commit 1edd76a

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

internal/internal_workflow_testsuite.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2281,20 +2281,24 @@ func (env *testWorkflowEnvironmentImpl) RequestCancelChildWorkflow(_, workflowID
22812281

22822282
func (env *testWorkflowEnvironmentImpl) RequestCancelExternalWorkflow(namespace, workflowID, runID string, callback ResultHandler) {
22832283
if env.workflowInfo.WorkflowExecution.ID == workflowID {
2284+
cancelFunc := func() {
2285+
env.workflowCancelHandler()
2286+
2287+
if env.isChildWorkflow() && env.onChildWorkflowCanceledListener != nil {
2288+
env.postCallback(func() {
2289+
env.onChildWorkflowCanceledListener(env.workflowInfo)
2290+
}, false)
2291+
}
2292+
}
22842293
// The way testWorkflowEnvironment is setup today, we close the child workflow dispatcher before calling
22852294
// the workflowCancelHandler. A larger refactor would be needed to handle this similar to non-test code.
22862295
// Maybe worth doing when https://github.com/temporalio/go-sdk/issues/50 is tackled.
22872296
if sd, ok := env.workflowDef.(*syncWorkflowDefinition); ok && env.isChildWorkflow() {
22882297
sd.dispatcher.NewCoroutine(sd.rootCtx, "cancel-self", true, func(ctx Context) {
2289-
env.workflowCancelHandler()
2298+
cancelFunc()
22902299
})
22912300
} else {
2292-
env.workflowCancelHandler()
2293-
}
2294-
if env.isChildWorkflow() && env.onChildWorkflowCanceledListener != nil {
2295-
env.postCallback(func() {
2296-
env.onChildWorkflowCanceledListener(env.workflowInfo)
2297-
}, false)
2301+
cancelFunc()
22982302
}
22992303
return
23002304
} else if childHandle, ok := env.runningWorkflows[workflowID]; ok && !childHandle.handled {

0 commit comments

Comments
 (0)