Skip to content

Commit

Permalink
Fix TestActivityRetryOnTimeoutStableError integration test (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexshtin committed Jun 5, 2020
1 parent 36b7562 commit b0f9abe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
3 changes: 1 addition & 2 deletions test/activity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ func newActivities() *Activities {
}

func (a *Activities) RetryTimeoutStableErrorActivity() error {
// TODO (shtin): Sleep used to be 3s here. Check https://github.com/temporalio/temporal-go-sdk/issues/120 for details.
time.Sleep(1 * time.Second)
time.Sleep(1*time.Second + 100*time.Millisecond)
return errFailOnPurpose
}

Expand Down
29 changes: 19 additions & 10 deletions test/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (w *Workflows) ActivityRetryOnHBTimeout(ctx workflow.Context) ([]string, er

elapsed := workflow.Now(ctx).Sub(startTime)
if elapsed < 5*time.Second {
return nil, fmt.Errorf("expected activity to be retried on failure, but it was not")
return nil, fmt.Errorf("expected activity to be retried on failure, but it was not. Elapsed time: %d", elapsed.Milliseconds())
}

var timeoutErr *temporal.TimeoutError
Expand Down Expand Up @@ -438,15 +438,12 @@ func (w *Workflows) ConsistentQueryWorkflow(ctx workflow.Context, delay time.Dur
func (w *Workflows) RetryTimeoutStableErrorWorkflow(ctx workflow.Context) ([]string, error) {
ao := workflow.ActivityOptions{
ScheduleToStartTimeout: 1 * time.Second,
StartToCloseTimeout: 2 * time.Second,
ScheduleToCloseTimeout: 10 * time.Second,
StartToCloseTimeout: 1 * time.Second,
ScheduleToCloseTimeout: 5 * time.Second,
RetryPolicy: &temporal.RetryPolicy{
InitialInterval: 1 * time.Second,
BackoffCoefficient: 1.0,
MaximumInterval: 1 * time.Second,
// TODO (shtin): This is sort of workarounds to make TestActivityRetryOnTimeoutStableError test works. But it should fail on ScheduleToCloseTimeout not on MaximumAttempts.
// https://github.com/temporalio/temporal-go-sdk/issues/120 is to fix it.
MaximumAttempts: 3,
},
}
ctx = workflow.WithActivityOptions(ctx, ao)
Expand All @@ -455,14 +452,26 @@ func (w *Workflows) RetryTimeoutStableErrorWorkflow(ctx workflow.Context) ([]str
var a *Activities
err := workflow.ExecuteActivity(ctx, a.RetryTimeoutStableErrorActivity).Get(ctx, nil)

var applicationErr *temporal.ApplicationError
ok := errors.As(err, &applicationErr)
var timeoutErr *temporal.TimeoutError
ok := errors.As(err, &timeoutErr)
if !ok {
return []string{}, fmt.Errorf("activity failed with unexpected error: %v", err)
}
if applicationErr.Error() != errFailOnPurpose.Error() {
return []string{}, fmt.Errorf("activity failed with unexpected error message: %v", applicationErr.Error())

if timeoutErr.TimeoutType() != commonpb.TimeoutType_ScheduleToClose {
return []string{}, fmt.Errorf("activity timed out with unexpected timeout type: %v", timeoutErr.TimeoutType())
}

err = errors.Unwrap(timeoutErr)
var previousTimeoutErr *temporal.TimeoutError
if !errors.As(err, &previousTimeoutErr) {
return []string{}, fmt.Errorf("activity timed out with unexpected last error %v", err)
}

if previousTimeoutErr.TimeoutType() != commonpb.TimeoutType_StartToClose {
return []string{}, fmt.Errorf("activity timed out with unexpected timeout type of last timeout: %v", previousTimeoutErr.TimeoutType())
}

return []string{}, nil
}

Expand Down

0 comments on commit b0f9abe

Please sign in to comment.