diff --git a/retry.go b/retry.go index 098c6dd..5ef4f69 100644 --- a/retry.go +++ b/retry.go @@ -97,13 +97,14 @@ func Do(retryableFunc RetryableFunc, opts ...Option) error { err := retryableFunc() if err != nil { - config.onRetry(n, err) errorLog[n] = unpackUnrecoverable(err) if !config.retryIf(err) { break } + config.onRetry(n, err) + // if this is last attempt - don't wait if n == config.attempts-1 { break diff --git a/retry_test.go b/retry_test.go index 0145cf9..8a33d74 100644 --- a/retry_test.go +++ b/retry_test.go @@ -68,7 +68,7 @@ func TestRetryIf(t *testing.T) { #2: test #3: special` assert.Equal(t, expectedErrorFormat, err.Error(), "retry error format") - assert.Equal(t, uint(3), retryCount, "right count of retry") + assert.Equal(t, uint(2), retryCount, "right count of retry") } @@ -103,6 +103,7 @@ func TestLastErrorOnly(t *testing.T) { Delay(time.Nanosecond), LastErrorOnly(true), ) + assert.Error(t, err) assert.Equal(t, "9", err.Error()) }