From 019268ddedd2a212a8da54c3d0c9cad7c3e12e26 Mon Sep 17 00:00:00 2001 From: Ulysses Souza Date: Fri, 9 Oct 2020 09:39:00 +0200 Subject: [PATCH 1/3] Fix e2e tests on comparing with empty string Signed-off-by: Ulysses Souza --- tests/aci-e2e/e2e-aci_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/aci-e2e/e2e-aci_test.go b/tests/aci-e2e/e2e-aci_test.go index 572aa7a31..c7f32e078 100644 --- a/tests/aci-e2e/e2e-aci_test.go +++ b/tests/aci-e2e/e2e-aci_test.go @@ -404,7 +404,7 @@ func TestContainerRunAttached(t *testing.T) { assert.Assert(t, is.Len(containerInspect.Ports, 1)) port := containerInspect.Ports[0] - assert.Assert(t, len(port.HostIP) > 0) + assert.Assert(t, port.HostIP != "") assert.Equal(t, port.ContainerPort, uint32(80)) assert.Equal(t, port.HostPort, uint32(80)) assert.Equal(t, containerInspect.Config.FQDN, fqdn) From 4f87422a794411276be012c02f8583fbf0ba1f4c Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Fri, 9 Oct 2020 12:28:48 +0200 Subject: [PATCH 2/3] more debug info when ports available but hostIP is empty ; Seems to be a race where container has status running but not yet an IP allocated Signed-off-by: Guillaume Tardif --- tests/aci-e2e/e2e-aci_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/aci-e2e/e2e-aci_test.go b/tests/aci-e2e/e2e-aci_test.go index c7f32e078..98544f19b 100644 --- a/tests/aci-e2e/e2e-aci_test.go +++ b/tests/aci-e2e/e2e-aci_test.go @@ -384,7 +384,7 @@ func TestContainerRunAttached(t *testing.T) { checkRunning := func(t poll.LogT) poll.Result { res := c.RunDockerOrExitError("inspect", container) - if res.ExitCode == 0 && strings.Contains(res.Stdout(), `"Status": "Running"`) { + if res.ExitCode == 0 && strings.Contains(res.Stdout(), `"Status": "Running"`) && !strings.Contains(res.Stdout(), `"HostIP": ""`) { return poll.Success() } return poll.Continue("waiting for container to be running, current inspect result: \n%s", res.Combined()) @@ -404,7 +404,7 @@ func TestContainerRunAttached(t *testing.T) { assert.Assert(t, is.Len(containerInspect.Ports, 1)) port := containerInspect.Ports[0] - assert.Assert(t, port.HostIP != "") + assert.Assert(t, port.HostIP != "", "empty hostIP, inspect: \n"+inspectRes.Stdout()) assert.Equal(t, port.ContainerPort, uint32(80)) assert.Equal(t, port.HostPort, uint32(80)) assert.Equal(t, containerInspect.Config.FQDN, fqdn) From 289c83efe23c1557bee151a699c829b7b0a8dcc3 Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Fri, 9 Oct 2020 14:26:26 +0200 Subject: [PATCH 3/3] HttpRetry : do not get stuck on first call, timeout http requests and retry in case of failures Signed-off-by: Guillaume Tardif --- tests/framework/e2e.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/framework/e2e.go b/tests/framework/e2e.go index 4216e93b0..4380fc3f9 100644 --- a/tests/framework/e2e.go +++ b/tests/framework/e2e.go @@ -207,7 +207,7 @@ func ParseContainerInspect(stdout string) (*containers.Container, error) { return &res, nil } -// HTTPGetWithRetry performs an HTTP GET on an `endpoint`. +// HTTPGetWithRetry performs an HTTP GET on an `endpoint`, using retryDelay also as a request timeout. // In the case of an error or the response status is not the expeted one, it retries the same request, // returning the response body as a string (empty if we could not reach it) func HTTPGetWithRetry(t *testing.T, endpoint string, expectedStatus int, retryDelay time.Duration, timeout time.Duration) string { @@ -215,8 +215,11 @@ func HTTPGetWithRetry(t *testing.T, endpoint string, expectedStatus int, retryDe r *http.Response err error ) + client := &http.Client{ + Timeout: retryDelay * time.Second, + } checkUp := func(t poll.LogT) poll.Result { - r, err = http.Get(endpoint) + r, err = client.Get(endpoint) if err != nil { return poll.Continue("reaching %q: Error %s", endpoint, err.Error()) }