Skip to content

Commit

Permalink
Revert "Change backoff semantics in case of initialBackoff (palantir#186
Browse files Browse the repository at this point in the history
)"

This reverts commit 3788375.
  • Loading branch information
willdeuschle authored Jun 9, 2020
1 parent 3788375 commit 0c54651
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 29 deletions.
10 changes: 0 additions & 10 deletions retry/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ func WithMaxAttempts(maxAttempts int) Option {
// WithInitialBackoff sets initial backoff.
//
// If initial backoff option is not used, then default value of 50 milliseconds is used.
// If initial backoff is larger than max backoff, it takes precedence.
func WithInitialBackoff(initialBackoff time.Duration) Option {
return func(o *options) {
o.initialBackoff = initialBackoff
Expand Down Expand Up @@ -181,8 +180,6 @@ func Start(ctx context.Context, opts ...Option) Retrier {
for _, option := range opts {
option(&r.options)
}
// If initial backoff is larger than max backoff, it takes precedence.
r.options.maxBackoff = max(r.options.maxBackoff, r.options.initialBackoff)
r.Reset()
return r
}
Expand Down Expand Up @@ -262,10 +259,3 @@ func (r retrier) retryIn() time.Duration {
func (r retrier) CurrentAttempt() int {
return r.currentAttempt
}

func max(a, b time.Duration) time.Duration {
if a > b {
return a
}
return b
}
19 changes: 0 additions & 19 deletions retry/retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,6 @@ func TestRetrier_Next_WithMaxBackoff(t *testing.T) {
}
}

func TestRetrier_Next_WithInitialBackoffLargerThanMax(t *testing.T) {
const initialBackoff = time.Second * 5
const maxBackoff = time.Second * 2

options := []Option{
WithInitialBackoff(initialBackoff),
WithMaxBackoff(maxBackoff),
WithMultiplier(2),
WithMaxAttempts(11),
WithRandomizationFactor(0),
}

r := Start(context.Background(), options...).(*retrier)
d := r.retryIn()
if d != initialBackoff {
t.Fatalf("expected initial backoff to be used: %s vs %s", d, initialBackoff)
}
}

func TestRetrier_Next_WithMaxAttempts(t *testing.T) {
const maxAttempts = 2

Expand Down

0 comments on commit 0c54651

Please sign in to comment.