Skip to content

Commit 2029e17

Browse files
committed
merge: BackOffDelay multiplies attempts from zero avast#130
1 parent cbf4dbf commit 2029e17

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

options.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ func BackOffDelay(n uint, _ error, config *Config) time.Duration {
124124
config.maxBackOffN = max - uint(math.Floor(math.Log2(float64(config.delay))))
125125
}
126126

127+
n--
128+
127129
if n > config.maxBackOffN {
128130
n = config.maxBackOffN
129131
}

retry_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ func TestBackOffDelay(t *testing.T) {
294294
delay: -1,
295295
expectedMaxN: 62,
296296
n: 2,
297-
expectedDelay: 4,
297+
expectedDelay: 2,
298298
},
299299
{
300300
label: "zero-delay",
@@ -310,6 +310,13 @@ func TestBackOffDelay(t *testing.T) {
310310
n: 62,
311311
expectedDelay: time.Second << 33,
312312
},
313+
{
314+
label: "one-second-n",
315+
delay: time.Second,
316+
expectedMaxN: 33,
317+
n: 1,
318+
expectedDelay: time.Second,
319+
},
313320
} {
314321
t.Run(
315322
c.label,
@@ -489,7 +496,7 @@ func TestContext(t *testing.T) {
489496
})
490497

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

495502
retrySum := 0

0 commit comments

Comments
 (0)