|
|
|
@ -88,6 +88,7 @@ func TestClientRetryAfter(t *testing.T) {
|
|
|
|
|
setupServer := func(statusCode int) *httptest.Server { |
|
|
|
|
return httptest.NewServer( |
|
|
|
|
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
|
|
|
|
w.Header().Set("Retry-After", "5") |
|
|
|
|
http.Error(w, longErrMessage, statusCode) |
|
|
|
|
}), |
|
|
|
|
) |
|
|
|
@ -114,9 +115,11 @@ func TestClientRetryAfter(t *testing.T) {
|
|
|
|
|
statusCode int |
|
|
|
|
retryOnRateLimit bool |
|
|
|
|
expectedRecoverable bool |
|
|
|
|
expectedRetryAfter model.Duration |
|
|
|
|
}{ |
|
|
|
|
{"TooManyRequests - No Retry", http.StatusTooManyRequests, false, false}, |
|
|
|
|
{"TooManyRequests - With Retry", http.StatusTooManyRequests, true, true}, |
|
|
|
|
{"TooManyRequests - No Retry", http.StatusTooManyRequests, false, false, 0}, |
|
|
|
|
{"TooManyRequests - With Retry", http.StatusTooManyRequests, true, true, 5 * model.Duration(time.Second)}, |
|
|
|
|
{"InternalServerError", http.StatusInternalServerError, false, true, 5 * model.Duration(time.Second)}, // HTTP 5xx errors do not depend on retryOnRateLimit.
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for _, tc := range testCases { |
|
|
|
@ -132,6 +135,9 @@ func TestClientRetryAfter(t *testing.T) {
|
|
|
|
|
var recErr RecoverableError |
|
|
|
|
err = c.Store(context.Background(), []byte{}, 0) |
|
|
|
|
require.Equal(t, tc.expectedRecoverable, errors.As(err, &recErr), "Mismatch in expected recoverable error status.") |
|
|
|
|
if tc.expectedRecoverable { |
|
|
|
|
require.Equal(t, tc.expectedRetryAfter, err.(RecoverableError).retryAfter) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|