Skip to content

Commit 8b32465

Browse files
authored
Test framework: make sure start listener returns before activity starts (#584)
1 parent 0d11aa0 commit 8b32465

File tree

2 files changed

+96
-14
lines changed

2 files changed

+96
-14
lines changed

Gopkg.lock

Lines changed: 89 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/internal_workflow_testsuite.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,9 +1084,12 @@ func (a *activityExecutorWrapper) Execute(ctx context.Context, input []byte) ([]
10841084
activityInfo := GetActivityInfo(ctx)
10851085
dc := getDataConverterFromActivityCtx(ctx)
10861086
if a.env.onActivityStartedListener != nil {
1087+
waitCh := make(chan struct{})
10871088
a.env.postCallback(func() {
10881089
a.env.onActivityStartedListener(&activityInfo, ctx, newEncodedValues(input, dc))
1090+
close(waitCh)
10891091
}, false)
1092+
<-waitCh // wait until listener returns
10901093
}
10911094

10921095
m := &mockWrapper{env: a.env, name: a.name, fn: a.fn, isWorkflow: false, dataConverter: dc}
@@ -1101,9 +1104,12 @@ func (a *activityExecutorWrapper) Execute(ctx context.Context, input []byte) ([]
11011104
func (a *activityExecutorWrapper) ExecuteWithActualArgs(ctx context.Context, inputArgs []interface{}) ([]byte, error) {
11021105
activityInfo := GetActivityInfo(ctx)
11031106
if a.env.onLocalActivityStartedListener != nil {
1107+
waitCh := make(chan struct{})
11041108
a.env.postCallback(func() {
11051109
a.env.onLocalActivityStartedListener(&activityInfo, ctx, inputArgs)
1110+
close(waitCh)
11061111
}, false)
1112+
<-waitCh
11071113
}
11081114

11091115
m := &mockWrapper{env: a.env, name: a.name, fn: a.fn, isWorkflow: false}
@@ -1118,9 +1124,7 @@ func (a *activityExecutorWrapper) ExecuteWithActualArgs(ctx context.Context, inp
11181124
func (w *workflowExecutorWrapper) Execute(ctx Context, input []byte) (result []byte, err error) {
11191125
env := w.env
11201126
if env.isChildWorkflow() && env.onChildWorkflowStartedListener != nil {
1121-
env.postCallback(func() {
1122-
env.onChildWorkflowStartedListener(GetWorkflowInfo(ctx), ctx, newEncodedValues(input, w.env.GetDataConverter()))
1123-
}, false)
1127+
env.onChildWorkflowStartedListener(GetWorkflowInfo(ctx), ctx, newEncodedValues(input, w.env.GetDataConverter()))
11241128
}
11251129

11261130
if !env.isChildWorkflow() {

0 commit comments

Comments
 (0)