Skip to content

Commit 7e65cc2

Browse files
authored
Minor test enhancement for local activity retries (#1069)
While looking into a user's issue with local activities retrying and not seeming to honor NonRetriableErrorReasons, I noticed that we had no tests for non-retriable local activity errors. So this test now mimics `Test_ActivityRetry`, but with local activities.
1 parent 9daccb2 commit 7e65cc2

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

internal/internal_workflow_testsuite_test.go

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2398,16 +2398,23 @@ func (s *WorkflowTestSuiteUnitTest) Test_ActivityHeartbeatRetry() {
23982398
}
23992399

24002400
func (s *WorkflowTestSuiteUnitTest) Test_LocalActivityRetry() {
2401+
nonretriableCount := 0
2402+
nonretriableFn := func(ctx context.Context) (string, error) {
2403+
nonretriableCount++
2404+
return "", NewCustomError("bad-bug")
2405+
}
24012406

2402-
localActivityFn := func(ctx context.Context) (int32, error) {
2407+
retriableCount := 0
2408+
retriableFn := func(ctx context.Context) (string, error) {
2409+
retriableCount++
24032410
info := GetActivityInfo(ctx)
24042411
if info.Attempt < 2 {
2405-
return int32(-1), NewCustomError("bad-luck")
2412+
return "", NewCustomError("bad-luck")
24062413
}
2407-
return info.Attempt, nil
2414+
return "retry-done", nil
24082415
}
24092416

2410-
workflowFn := func(ctx Context) (int32, error) {
2417+
workflowFn := func(ctx Context) (string, error) {
24112418
lao := LocalActivityOptions{
24122419
ScheduleToCloseTimeout: time.Minute,
24132420
RetryPolicy: &RetryPolicy{
@@ -2421,10 +2428,15 @@ func (s *WorkflowTestSuiteUnitTest) Test_LocalActivityRetry() {
24212428
}
24222429
ctx = WithLocalActivityOptions(ctx, lao)
24232430

2424-
var result int32
2425-
err := ExecuteLocalActivity(ctx, localActivityFn).Get(ctx, &result)
2431+
err := ExecuteLocalActivity(ctx, nonretriableFn).Get(ctx, nil)
2432+
badBug, ok := err.(*CustomError)
2433+
s.True(ok)
2434+
s.Equal("bad-bug", badBug.Reason())
2435+
2436+
var result string
2437+
err = ExecuteLocalActivity(ctx, retriableFn).Get(ctx, &result)
24262438
if err != nil {
2427-
return int32(-1), err
2439+
return "", err
24282440
}
24292441
return result, nil
24302442
}
@@ -2435,9 +2447,11 @@ func (s *WorkflowTestSuiteUnitTest) Test_LocalActivityRetry() {
24352447

24362448
s.True(env.IsWorkflowCompleted())
24372449
s.NoError(env.GetWorkflowError())
2438-
var result int32
2450+
var result string
24392451
s.NoError(env.GetWorkflowResult(&result))
2440-
s.Equal(int32(2), result)
2452+
s.Equal("retry-done", result)
2453+
s.Equal(1, nonretriableCount)
2454+
s.Equal(3, retriableCount)
24412455
}
24422456

24432457
func (s *WorkflowTestSuiteUnitTest) Test_LocalActivityRetryOnCancel() {

0 commit comments

Comments
 (0)