From b37047eadb96389041964d035a908c828f5bd81a Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Wed, 20 Apr 2022 10:38:41 -0400 Subject: [PATCH] Chore: Try to fix flaky reverse proxy test (#47957) (#47966) (cherry picked from commit 0afc542998175c7cf0217c18b1c4cece5ad4203c) Co-authored-by: Marcus Efraimsson --- pkg/util/proxyutil/reverse_proxy_test.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/util/proxyutil/reverse_proxy_test.go b/pkg/util/proxyutil/reverse_proxy_test.go index a886b928d8e..19c7db9144d 100644 --- a/pkg/util/proxyutil/reverse_proxy_test.go +++ b/pkg/util/proxyutil/reverse_proxy_test.go @@ -86,11 +86,12 @@ func TestReverseProxy(t *testing.T) { t.Run("Error handling should convert status codes depending on what kind of error it is", func(t *testing.T) { timedOutTransport := http.DefaultTransport.(*http.Transport) - timedOutTransport.ResponseHeaderTimeout = time.Nanosecond + timedOutTransport.ResponseHeaderTimeout = time.Millisecond testCases := []struct { desc string transport http.RoundTripper + responseWaitTime time.Duration expectedStatusCode int }{ { @@ -101,6 +102,7 @@ func TestReverseProxy(t *testing.T) { { desc: "Timed out request should return 504 Gateway timeout", transport: timedOutTransport, + responseWaitTime: 100 * time.Millisecond, expectedStatusCode: http.StatusGatewayTimeout, }, { @@ -113,6 +115,10 @@ func TestReverseProxy(t *testing.T) { for _, tc := range testCases { t.Run(tc.desc, func(t *testing.T) { upstream := newUpstreamServer(t, http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { + if tc.responseWaitTime > 0 { + time.Sleep(tc.responseWaitTime) + } + w.WriteHeader(http.StatusOK) })) t.Cleanup(upstream.Close)