Skip to content

Commit

Permalink
Fix testsuite race condition during activity retry (#914)
Browse files Browse the repository at this point in the history
  • Loading branch information
yycptt authored and yux0 committed Dec 18, 2019
1 parent 8b5a4e5 commit 19df4b8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion internal/internal_workflow_testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,9 @@ func (env *testWorkflowEnvironmentImpl) executeActivityWithRetryForTest(
if backoff > 0 {
// need a retry
waitCh := make(chan struct{})
env.postCallback(func() { env.runningCount-- }, false)

// register the delayed call back first, otherwise other timers may be fired before the retry timer
// is enqueued.
env.registerDelayedCallback(func() {
env.runningCount++
task.Attempt = common.Int32Ptr(task.GetAttempt() + 1)
Expand All @@ -997,6 +999,7 @@ func (env *testWorkflowEnvironmentImpl) executeActivityWithRetryForTest(
}
close(waitCh)
}, backoff)
env.postCallback(func() { env.runningCount-- }, false)

<-waitCh
continue
Expand Down
4 changes: 4 additions & 0 deletions internal/internal_workflow_testsuite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2152,6 +2152,10 @@ func (s *WorkflowTestSuiteUnitTest) Test_ActivityRetry() {
RegisterWorkflow(workflowFn)
RegisterActivity(activityFailedFn)
RegisterActivity(activityFn)

// set a workflow timeout timer to test
// if the timer will fire during activity retry
env.SetWorkflowTimeout(10 * time.Second)
env.ExecuteWorkflow(workflowFn)

s.True(env.IsWorkflowCompleted())
Expand Down

0 comments on commit 19df4b8

Please sign in to comment.