Skip to content

Commit

Permalink
proxy: fix flaky TestSlowService (#2528)
Browse files Browse the repository at this point in the history
backendTimeout("1ms") in TestSlowService may cancel context during
dialing which results in `i/o timeout` error and 502 response status
```
$ go test ./proxy -run=TestSlowService -count=10000 | grep -F 'FAIL:' -C1
...
time="2023-08-18T20:50:57+02:00" level=error msg="error while proxying after 1.295026ms, route  with backend network http://127.0.0.1:38613, status code 502: dialing failed true: failed to do backend roundtrip to 127.0.0.1:38613: dial tcp 127.0.0.1:38613: i/o timeout, remote host: 127.0.0.1, request: \"GET / HTTP/1.1\", host: 127.0.0.1:36801, user agent: \"Go-http-client/1.1\""
--- FAIL: TestSlowService (0.00s)
    backendtimeout_test.go:40: expected 504, got: &{502 Bad Gateway 502 HTTP/1.1 1 1 map[Content-Length:[12] Content-Type:[text/plain; charset=utf-8] Date:[Fri, 18 Aug 2023 18:50:57 GMT] Server:[Skipper] X-Content-Type-Options:[nosniff]] 0xc00068e100 12 [] false false map[] 0xc000255600 <nil>}
```

Increase TestSlowService filter parameter to 10ms.
Also make requests using test proxy client.

Signed-off-by: Alexander Yastrebov <[email protected]>
  • Loading branch information
AlexanderYastrebov authored Aug 21, 2023
1 parent dbb456d commit 394e77c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions proxy/backendtimeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestSlowService(t *testing.T) {
service.Close()
}()

doc := fmt.Sprintf(`* -> backendTimeout("1ms") -> "%s"`, service.URL)
doc := fmt.Sprintf(`* -> backendTimeout("10ms") -> "%s"`, service.URL)
tp, err := newTestProxy(doc, FlagsNone)
if err != nil {
t.Fatal(err)
Expand All @@ -30,7 +30,7 @@ func TestSlowService(t *testing.T) {
ps := httptest.NewServer(tp.proxy)
defer ps.Close()

rsp, err := http.Get(ps.URL)
rsp, err := ps.Client().Get(ps.URL)
if err != nil {
t.Fatal(err)
}
Expand All @@ -57,7 +57,7 @@ func TestFastService(t *testing.T) {
ps := httptest.NewServer(tp.proxy)
defer ps.Close()

rsp, err := http.Get(ps.URL)
rsp, err := ps.Client().Get(ps.URL)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -95,7 +95,7 @@ func TestBackendTimeoutInTheMiddleOfServiceResponse(t *testing.T) {
ps := httptest.NewServer(tp.proxy)
defer ps.Close()

rsp, err := http.Get(ps.URL)
rsp, err := ps.Client().Get(ps.URL)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -168,7 +168,7 @@ func TestRetryAndSlowService(t *testing.T) {
ps := httptest.NewServer(tp.proxy)
defer ps.Close()

rsp, err := http.Get(ps.URL)
rsp, err := ps.Client().Get(ps.URL)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -199,7 +199,7 @@ func TestRetryAndFastService(t *testing.T) {
ps := httptest.NewServer(tp.proxy)
defer ps.Close()

rsp, err := http.Get(ps.URL)
rsp, err := ps.Client().Get(ps.URL)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 394e77c

Please sign in to comment.