Skip to content

Commit

Permalink
proxy: fix flaky TestResponseHeaderTimeout (#2542)
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Yastrebov <[email protected]>
  • Loading branch information
AlexanderYastrebov authored Aug 23, 2023
1 parent c39bb88 commit 7cb9c95
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down

0 comments on commit 7cb9c95

Please sign in to comment.