Skip to content

Commit

Permalink
Test framework: make sure start listener returns before activity star…
Browse files Browse the repository at this point in the history
…ts (#584)
  • Loading branch information
yiminc authored Sep 28, 2018
1 parent 0d11aa0 commit 8b32465
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 14 deletions.
100 changes: 89 additions & 11 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions internal/internal_workflow_testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -1084,9 +1084,12 @@ func (a *activityExecutorWrapper) Execute(ctx context.Context, input []byte) ([]
activityInfo := GetActivityInfo(ctx)
dc := getDataConverterFromActivityCtx(ctx)
if a.env.onActivityStartedListener != nil {
waitCh := make(chan struct{})
a.env.postCallback(func() {
a.env.onActivityStartedListener(&activityInfo, ctx, newEncodedValues(input, dc))
close(waitCh)
}, false)
<-waitCh // wait until listener returns
}

m := &mockWrapper{env: a.env, name: a.name, fn: a.fn, isWorkflow: false, dataConverter: dc}
Expand All @@ -1101,9 +1104,12 @@ func (a *activityExecutorWrapper) Execute(ctx context.Context, input []byte) ([]
func (a *activityExecutorWrapper) ExecuteWithActualArgs(ctx context.Context, inputArgs []interface{}) ([]byte, error) {
activityInfo := GetActivityInfo(ctx)
if a.env.onLocalActivityStartedListener != nil {
waitCh := make(chan struct{})
a.env.postCallback(func() {
a.env.onLocalActivityStartedListener(&activityInfo, ctx, inputArgs)
close(waitCh)
}, false)
<-waitCh
}

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

if !env.isChildWorkflow() {
Expand Down

0 comments on commit 8b32465

Please sign in to comment.