From 71df0685f4a4081856b0a6387bb1eeef16adb10b Mon Sep 17 00:00:00 2001 From: Anton Zadvorny Date: Mon, 25 Dec 2023 03:54:34 +0300 Subject: [PATCH] Remove retry after test for the throttle middleware --- throttle/throttle.go | 2 +- throttle/throttle_test.go | 51 --------------------------------------- 2 files changed, 1 insertion(+), 52 deletions(-) diff --git a/throttle/throttle.go b/throttle/throttle.go index 3465e94..23db557 100644 --- a/throttle/throttle.go +++ b/throttle/throttle.go @@ -112,7 +112,7 @@ func (s *throttle) setRetryAfterHeader(w http.ResponseWriter, ctxDone bool) { // Middleware is a throttle middleware that limits number of currently processed requests // at a time across all users. Note: Throttle is not a rate-limiter per user, -// instead it just puts a ceiling on the number of currentl in-flight requests +// instead it just puts a ceiling on the number of currently in-flight requests // being processed from the point from where the Throttle middleware is mounted func Middleware(opts ...Option) func(http.Handler) http.Handler { t := &throttle{} diff --git a/throttle/throttle_test.go b/throttle/throttle_test.go index 5b42e5a..3e69d6e 100644 --- a/throttle/throttle_test.go +++ b/throttle/throttle_test.go @@ -192,54 +192,3 @@ func TestThrottleMaximum(t *testing.T) { wg.Wait() } - -func TestThrottleRetryAfter(t *testing.T) { - throttle := Middleware( - SetLimit(10), - SetRetryAfterFn(func(_ bool) time.Duration { return time.Hour * 1 }), - ) - - handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(http.StatusOK) - time.Sleep(time.Second * 3) - - _, err := w.Write([]byte("resp")) - require.NoError(t, err) - }) - - server := httptest.NewServer(throttle(handler)) - defer server.Close() - - client := http.Client{Timeout: time.Second * 60} - - var wg sync.WaitGroup - - for i := 0; i < 10; i++ { - wg.Add(1) - go func() { - defer wg.Done() - - res, err := client.Get(server.URL) - assert.NoError(t, err) - defer res.Body.Close() - assert.Equal(t, http.StatusOK, res.StatusCode) - }() - } - - time.Sleep(time.Second * 1) - - for i := 0; i < 10; i++ { - wg.Add(1) - go func() { - defer wg.Done() - - res, err := client.Get(server.URL) - assert.NoError(t, err) - defer res.Body.Close() - assert.Equal(t, http.StatusTooManyRequests, res.StatusCode) - assert.Equal(t, res.Header.Get("Retry-After"), "3600") - }() - } - - wg.Wait() -}