From ce6ad15422c597bf4a14a74f560d143aadafe50a Mon Sep 17 00:00:00 2001 From: William Dumont Date: Thu, 7 Sep 2023 16:42:00 +0200 Subject: [PATCH] remote-write: TestClientRetryAfter status code 500 and compare the retryAfter values. Signed-off-by: William Dumont --- storage/remote/client_test.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/storage/remote/client_test.go b/storage/remote/client_test.go index 45bd7ee04..9217e1c7e 100644 --- a/storage/remote/client_test.go +++ b/storage/remote/client_test.go @@ -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) + } }) } }