Skip to content

Commit

Permalink
all: fix flaky tests (#2555)
Browse files Browse the repository at this point in the history
Increase delays in flaky tests.

Fixes #2544

Signed-off-by: Alexander Yastrebov <[email protected]>
  • Loading branch information
AlexanderYastrebov authored Aug 31, 2023
1 parent 430106d commit ff6afc5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
11 changes: 5 additions & 6 deletions dataclients/routestring/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,18 @@ func Example() {
CustomDataClients: []routing.DataClient{rs},
})
}()
time.Sleep(10 * time.Millisecond)
// Wait for Skipper to start
time.Sleep(100 * time.Millisecond)

rsp, err := http.Get("http://localhost:9999")
if err != nil {
log.Println(err)
return
log.Fatal(err)
}

defer rsp.Body.Close()

content, err := io.ReadAll(rsp.Body)
if err != nil {
log.Println(err)
return
log.Fatal(err)
}

fmt.Println(string(content))
Expand Down
24 changes: 12 additions & 12 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("10ms") -> "%s"`, service.URL)
doc := fmt.Sprintf(`* -> backendTimeout("100ms") -> "%s"`, service.URL)
tp, err := newTestProxy(doc, FlagsNone)
if err != nil {
t.Fatal(err)
Expand All @@ -47,7 +47,7 @@ func TestFastService(t *testing.T) {
}))
defer service.Close()

doc := fmt.Sprintf(`* -> backendTimeout("10ms") -> "%s"`, service.URL)
doc := fmt.Sprintf(`* -> backendTimeout("100ms") -> "%s"`, service.URL)
tp, err := newTestProxy(doc, FlagsNone)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -79,13 +79,13 @@ func TestBackendTimeoutInTheMiddleOfServiceResponse(t *testing.T) {
f := w.(http.Flusher)
f.Flush()

time.Sleep(20 * time.Millisecond)
time.Sleep(200 * time.Millisecond)

w.Write([]byte(" Were Here"))
}))
defer service.Close()

doc := fmt.Sprintf(`* -> backendTimeout("10ms") -> "%s"`, service.URL)
doc := fmt.Sprintf(`* -> backendTimeout("100ms") -> "%s"`, service.URL)
tp, err := newTestProxy(doc, FlagsNone)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -149,16 +149,16 @@ func newUnstable(timeout time.Duration) func(r http.RoundTripper) http.RoundTrip
}

// Retryable request, dial timeout on first attempt, load balanced backend
// dial timeout (10ms) + service latency (10ms) > backendTimeout("15ms") => Gateway Timeout
// dial timeout (100ms) + service latency (100ms) > backendTimeout("150ms") => Gateway Timeout
func TestRetryAndSlowService(t *testing.T) {
service := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
time.Sleep(10 * time.Millisecond)
time.Sleep(100 * time.Millisecond)
}))
defer service.Close()

doc := fmt.Sprintf(`* -> backendTimeout("15ms") -> <"%s", "%s">`, service.URL, service.URL)
doc := fmt.Sprintf(`* -> backendTimeout("150ms") -> <"%s", "%s">`, service.URL, service.URL)
tp, err := newTestProxyWithParams(doc, Params{
CustomHttpRoundTripperWrap: newUnstable(10 * time.Millisecond),
CustomHttpRoundTripperWrap: newUnstable(100 * time.Millisecond),
})
if err != nil {
t.Fatal(err)
Expand All @@ -180,16 +180,16 @@ func TestRetryAndSlowService(t *testing.T) {
}

// Retryable request, dial timeout on first attempt, load balanced backend
// dial timeout (10ms) + service latency (10ms) < backendTimeout("25ms") => OK
// dial timeout (100ms) + service latency (100ms) < backendTimeout("250ms") => OK
func TestRetryAndFastService(t *testing.T) {
service := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
time.Sleep(10 * time.Millisecond)
time.Sleep(100 * time.Millisecond)
}))
defer service.Close()

doc := fmt.Sprintf(`* -> backendTimeout("25ms") -> <"%s", "%s">`, service.URL, service.URL)
doc := fmt.Sprintf(`* -> backendTimeout("250ms") -> <"%s", "%s">`, service.URL, service.URL)
tp, err := newTestProxyWithParams(doc, Params{
CustomHttpRoundTripperWrap: newUnstable(10 * time.Millisecond),
CustomHttpRoundTripperWrap: newUnstable(100 * time.Millisecond),
})
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit ff6afc5

Please sign in to comment.