From 9f2b12c624a4a07c6662d1a5f1bced28b6eb86da Mon Sep 17 00:00:00 2001 From: Andrei Vagin Date: Mon, 13 May 2019 00:49:32 -0700 Subject: gvisor/runsc/tests: set timeout for http.Get() WaitForHTTP tries GET requests on a port until the call succeeds or timeout. But we want to be sure that one of our attempts will not stuck for the whole timeout. All timeouts are increased to 30 seconds, because test cases with smaller timeouts fail sometimes even for the native container runtime (runc). PiperOrigin-RevId: 247888467 Change-Id: I03cfd3275286bc686a78fd26da43231d20667851 --- runsc/test/testutil/testutil.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'runsc/test/testutil/testutil.go') diff --git a/runsc/test/testutil/testutil.go b/runsc/test/testutil/testutil.go index 6a4c045a8..9efb1ba8e 100644 --- a/runsc/test/testutil/testutil.go +++ b/runsc/test/testutil/testutil.go @@ -23,6 +23,7 @@ import ( "fmt" "io" "io/ioutil" + "log" "math/rand" "net/http" "os" @@ -266,8 +267,14 @@ func Poll(cb func() error, timeout time.Duration) error { // WaitForHTTP tries GET requests on a port until the call succeeds or timeout. func WaitForHTTP(port int, timeout time.Duration) error { cb := func() error { - resp, err := http.Get(fmt.Sprintf("http://localhost:%d/", port)) + c := &http.Client{ + // Calculate timeout to be able to do minimum 5 attempts. + Timeout: timeout / 5, + } + url := fmt.Sprintf("http://localhost:%d/", port) + resp, err := c.Get(url) if err != nil { + log.Printf("Waiting %s: %v", url, err) return err } resp.Body.Close() -- cgit v1.2.3