Skip to content

Commit 577ec3e

Browse files
authored
Fix TestShouldUseExponentialBackoffIfNoRetryHeader bounds (#530)
The lower bound has an off-by-one error: 2^0 + 2^1 + ... + 2^(n-1) sums up to 2^n-1. Verified with: go test -count=1000 -run TestShouldUseExponentialBackoffIfNoRetryHeader ./httputil -v
1 parent 9d3fc7d commit 577ec3e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

httputil/httputil_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ func TestShouldUseExponentialBackoffIfNoRetryHeader(t *testing.T) {
176176
}
177177

178178
delta := time.Millisecond * 100
179-
lower := (1 << uint(retries)) * time.Second
179+
// exponential backoff: 1s + d1, 2s + d2, 4s + d3, 8s + d4 with dx being a random value in [0ms, 500ms]
180+
lower := (1<<uint(retries))*time.Second - time.Second
180181
upper := lower + time.Duration(retries*500)*time.Millisecond
181182
if total < lower-delta || upper+delta < total {
182183
t.Fatalf("Expected a total sleep time between %s and %s (%d retries, exponential backoff with fuzzing), but waited %s instead", lower, upper, retries, total)

0 commit comments

Comments
 (0)