Skip to content

Commit e08f658

Browse files
authored
Merge pull request #5 from codeGROOVE-dev/merge_130
merge: BackOffDelay multiplies attempts from zero avast#130
2 parents 31dfd66 + 2029e17 commit e08f658

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
@@ -295,7 +295,7 @@ func TestBackOffDelay(t *testing.T) {
295295
delay: -1,
296296
expectedMaxN: 62,
297297
n: 2,
298-
expectedDelay: 4,
298+
expectedDelay: 2,
299299
},
300300
{
301301
label: "zero-delay",
@@ -311,6 +311,13 @@ func TestBackOffDelay(t *testing.T) {
311311
n: 62,
312312
expectedDelay: time.Second << 33,
313313
},
314+
{
315+
label: "one-second-n",
316+
delay: time.Second,
317+
expectedMaxN: 33,
318+
n: 1,
319+
expectedDelay: time.Second,
320+
},
314321
} {
315322
t.Run(
316323
c.label,
@@ -490,7 +497,7 @@ func TestContext(t *testing.T) {
490497
})
491498

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

496503
retrySum := 0

0 commit comments

Comments
 (0)