From 7cb9c95d59c76a32682a6b0d2c76a2bb2700a4e4 Mon Sep 17 00:00:00 2001 From: Alexander Yastrebov Date: Wed, 23 Aug 2023 16:35:48 +0200 Subject: [PATCH] proxy: fix flaky TestResponseHeaderTimeout (#2542) Signed-off-by: Alexander Yastrebov --- proxy/proxy_test.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/proxy/proxy_test.go b/proxy/proxy_test.go index 50caf272e8..096423ee81 100644 --- a/proxy/proxy_test.go +++ b/proxy/proxy_test.go @@ -1549,12 +1549,17 @@ func TestRoundtripperRetry(t *testing.T) { } func TestResponseHeaderTimeout(t *testing.T) { + const timeout = 10 * time.Millisecond + s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - time.Sleep(5 * time.Microsecond) + time.Sleep(2 * timeout) })) defer s.Close() - p, err := newTestProxyWithParams(fmt.Sprintf(`* -> "%s"`, s.URL), Params{ResponseHeaderTimeout: 1 * time.Microsecond}) + params := Params{ + ResponseHeaderTimeout: timeout, + } + p, err := newTestProxyWithParams(fmt.Sprintf(`* -> "%s"`, s.URL), params) if err != nil { t.Fatal(err) } @@ -1563,8 +1568,8 @@ func TestResponseHeaderTimeout(t *testing.T) { ps := httptest.NewServer(p.proxy) defer ps.Close() - // Prevent retry - rsp, err := http.Post(ps.URL, "text/plain", strings.NewReader("payload")) + // Prevent retry by using POST + rsp, err := ps.Client().Post(ps.URL, "text/plain", strings.NewReader("payload")) if err != nil { t.Fatal(err) }