diff --git a/tests/aci-e2e/e2e-aci_test.go b/tests/aci-e2e/e2e-aci_test.go index 13e32a49..d78d1459 100644 --- a/tests/aci-e2e/e2e-aci_test.go +++ b/tests/aci-e2e/e2e-aci_test.go @@ -198,7 +198,7 @@ func TestContainerRunVolume(t *testing.T) { }) t.Run("http get", func(t *testing.T) { - r, err := http.Get(endpoint) + r, err := HTTPGetWithRetry(endpoint, 3) assert.NilError(t, err) assert.Equal(t, r.StatusCode, http.StatusOK) b, err := ioutil.ReadAll(r.Body) @@ -434,7 +434,7 @@ func TestComposeUpUpdate(t *testing.T) { assert.Assert(t, is.Len(containerInspect.Ports, 1)) endpoint := fmt.Sprintf("http://%s:%d", containerInspect.Ports[0].HostIP, containerInspect.Ports[0].HostPort) - r, err := http.Get(endpoint + "/words/noun") + r, err := HTTPGetWithRetry(endpoint+"/words/noun", 3) assert.NilError(t, err) assert.Equal(t, r.StatusCode, http.StatusOK) b, err := ioutil.ReadAll(r.Body) diff --git a/tests/framework/e2e.go b/tests/framework/e2e.go index 91234fe5..a865fde8 100644 --- a/tests/framework/e2e.go +++ b/tests/framework/e2e.go @@ -22,12 +22,14 @@ import ( "errors" "fmt" "io/ioutil" + "net/http" "os" "os/exec" "path/filepath" "runtime" "strings" "testing" + "time" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" @@ -192,3 +194,21 @@ func ParseContainerInspect(stdout string) (*containers.Container, error) { } return &res, nil } + +// HTTPGetWithRetry performs an HTTP GET on an `endpoint`. +// In the case of an error it retries the same request after a 5 second sleep, +// returning the error if count of `tries` is reached +func HTTPGetWithRetry(endpoint string, tries int) (*http.Response, error) { + var ( + r *http.Response + err error + ) + for t := 0; t < tries; t++ { + r, err = http.Get(endpoint) + if err == nil || t == tries-1 { + break + } + time.Sleep(5 * time.Second) + } + return r, err +}