Skip to content

Commit

Permalink
Fix an empty retry interval in unit tests causing no retries to happen (
Browse files Browse the repository at this point in the history
#446)

Fix unit test framework to apply a default initial interval to retry policies for activities
  • Loading branch information
Sushisource authored May 18, 2021
1 parent d33f799 commit 13f5d7a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/internal_workflow_testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,11 @@ func (env *testWorkflowEnvironmentImpl) executeActivityWithRetryForTest(
if parameters.ScheduleToCloseTimeout > 0 {
expireTime = env.Now().Add(parameters.ScheduleToCloseTimeout)
}
if parameters.RetryPolicy != nil {
if *parameters.RetryPolicy.InitialInterval == 0 {
*parameters.RetryPolicy.InitialInterval = time.Second
}
}

for {
var err error
Expand Down
40 changes: 40 additions & 0 deletions internal/internal_workflow_testsuite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2551,6 +2551,46 @@ func (s *WorkflowTestSuiteUnitTest) Test_ActivityRetry() {
s.Equal(4, attempt2Count)
}

func (s *WorkflowTestSuiteUnitTest) Test_ActivityRetry_NoInitialInterval() {
var attempts = 0

activityFn := func(ctx context.Context) (bool, error) {
info := GetActivityInfo(ctx)
if info.Attempt < 2 {
attempts++
return false, errors.New("first attempt fails")
}
attempts++
return true, nil
}

workflowFn := func(ctx Context) (bool, error) {
ctx = WithActivityOptions(
ctx,
ActivityOptions{
StartToCloseTimeout: 10 * time.Second,
ScheduleToCloseTimeout: 10 * time.Second,
RetryPolicy: &RetryPolicy{
BackoffCoefficient: 2,
MaximumAttempts: 3,
},
})
activityExecution := ExecuteActivity(ctx, activityFn)
var result bool
err := activityExecution.Get(ctx, &result)
println(result)
return result, err
}

env := s.NewTestWorkflowEnvironment()
env.RegisterActivity(activityFn)
env.ExecuteWorkflow(workflowFn)
s.NoError(env.GetWorkflowError())
s.True(env.IsWorkflowCompleted())
s.Equal(2, attempts)

}

func (s *WorkflowTestSuiteUnitTest) Test_ActivityRetry_NoRetries() {
maxRetryAttempts := int32(1)
fakeError := fmt.Errorf("fake network error")
Expand Down

0 comments on commit 13f5d7a

Please sign in to comment.