Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ func BackOffDelay(n uint, _ error, config *Config) time.Duration {
config.maxBackOffN = max - uint(math.Floor(math.Log2(float64(config.delay))))
}

n--

if n > config.maxBackOffN {
n = config.maxBackOffN
}
Expand Down
11 changes: 9 additions & 2 deletions retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func TestBackOffDelay(t *testing.T) {
delay: -1,
expectedMaxN: 62,
n: 2,
expectedDelay: 4,
expectedDelay: 2,
},
{
label: "zero-delay",
Expand All @@ -310,6 +310,13 @@ func TestBackOffDelay(t *testing.T) {
n: 62,
expectedDelay: time.Second << 33,
},
{
label: "one-second-n",
delay: time.Second,
expectedMaxN: 33,
n: 1,
expectedDelay: time.Second,
},
} {
t.Run(
c.label,
Expand Down Expand Up @@ -489,7 +496,7 @@ func TestContext(t *testing.T) {
})

t.Run("timed out on retry infinte attempts - wraps context error with last retried function error", func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*500)
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*200)
defer cancel()

retrySum := 0
Expand Down