Skip to content

Commit 19df4b8

Browse files
yycpttyux0
authored andcommitted
Fix testsuite race condition during activity retry (#914)
1 parent 8b5a4e5 commit 19df4b8

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

internal/internal_workflow_testsuite.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,9 @@ func (env *testWorkflowEnvironmentImpl) executeActivityWithRetryForTest(
987987
if backoff > 0 {
988988
// need a retry
989989
waitCh := make(chan struct{})
990-
env.postCallback(func() { env.runningCount-- }, false)
990+
991+
// register the delayed call back first, otherwise other timers may be fired before the retry timer
992+
// is enqueued.
991993
env.registerDelayedCallback(func() {
992994
env.runningCount++
993995
task.Attempt = common.Int32Ptr(task.GetAttempt() + 1)
@@ -997,6 +999,7 @@ func (env *testWorkflowEnvironmentImpl) executeActivityWithRetryForTest(
997999
}
9981000
close(waitCh)
9991001
}, backoff)
1002+
env.postCallback(func() { env.runningCount-- }, false)
10001003

10011004
<-waitCh
10021005
continue

internal/internal_workflow_testsuite_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2152,6 +2152,10 @@ func (s *WorkflowTestSuiteUnitTest) Test_ActivityRetry() {
21522152
RegisterWorkflow(workflowFn)
21532153
RegisterActivity(activityFailedFn)
21542154
RegisterActivity(activityFn)
2155+
2156+
// set a workflow timeout timer to test
2157+
// if the timer will fire during activity retry
2158+
env.SetWorkflowTimeout(10 * time.Second)
21552159
env.ExecuteWorkflow(workflowFn)
21562160

21572161
s.True(env.IsWorkflowCompleted())

0 commit comments

Comments
 (0)