Skip to content

Commit

Permalink
Merge pull request #21 from pallavJha/master
Browse files Browse the repository at this point in the history
retryIf should be called before onRetry
  • Loading branch information
JaSei authored Oct 23, 2019
2 parents 101acd3 + 639c9f1 commit 0554a4a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

}

Expand Down Expand Up @@ -103,6 +103,7 @@ func TestLastErrorOnly(t *testing.T) {
Delay(time.Nanosecond),
LastErrorOnly(true),
)
assert.Error(t, err)
assert.Equal(t, "9", err.Error())
}

Expand Down

0 comments on commit 0554a4a

Please sign in to comment.