Skip to content

Commit

Permalink
add jitter test
Browse files Browse the repository at this point in the history
  • Loading branch information
jharley committed Aug 1, 2024
1 parent f9e4e78 commit 8ce7164
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions client/v2/limits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ func TestClient_rateLimitBackoff(t *testing.T) {
time.Second,
)
})

t.Run("reset value is fuzzed with jitter", func(t *testing.T) {
w := httptest.NewRecorder()
w.Header().Add(HeaderRateLimit, "limit=100, remaining=50, reset=60")
w.Header().Add(HeaderRetryAfter, now.Add(2*time.Minute).UTC().Format(time.RFC3339))
w.WriteHeader(http.StatusTooManyRequests)

reset := 60 * time.Second
min = 100 * time.Millisecond
max = 500 * time.Millisecond
r := rateLimitBackoff(min, max, w.Result())

assert.Greater(t, r, reset+min, "expected backoff to be greater than min")
assert.LessOrEqual(t, r, reset+max, "expected backoff to be less or equal to max")
})
}

func TestClient_parseRateLimitHeader(t *testing.T) {
Expand Down

0 comments on commit 8ce7164

Please sign in to comment.