Skip to content

Commit

Permalink
Use unsigned integer for shift count type (bazelbuild#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
changlan authored Aug 13, 2021
1 parent 0f006d8 commit 4dbbe54
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion httputil/httputil.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func getWaitPeriod(res *http.Response, attempt int) (time.Duration, error) {
}
}
// Let's just use exponential backoff: 1s + d1, 2s + d2, 4s + d3, 8s + d4 with dx being a random value in [0ms, 500ms]
return time.Duration(1 << attempt) * time.Second + time.Duration(rand.Intn(500)) * time.Millisecond, nil
return time.Duration(1 << uint(attempt)) * time.Second + time.Duration(rand.Intn(500)) * time.Millisecond, nil
}

func parseRetryHeader(value string) (time.Duration, error) {
Expand Down
2 changes: 1 addition & 1 deletion httputil/httputil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func TestShouldUseExponentialBackoffIfNoRetryHeader(t *testing.T) {
}

delta := time.Millisecond * 100
lower := (1 << retries) * time.Second
lower := (1 << uint(retries)) * time.Second
upper := lower + time.Duration(retries*500)*time.Millisecond
if total < lower-delta || upper+delta < total {
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)
Expand Down

0 comments on commit 4dbbe54

Please sign in to comment.