mirror of
https://github.com/docker/compose.git
synced 2025-07-31 01:24:15 +02:00
Merge pull request #591 from docker/flaky-aci
Attempt to fix flaky ACI tests
This commit is contained in:
commit
7545485f78
@ -198,7 +198,7 @@ func TestContainerRunVolume(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("http get", func(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.NilError(t, err)
|
||||||
assert.Equal(t, r.StatusCode, http.StatusOK)
|
assert.Equal(t, r.StatusCode, http.StatusOK)
|
||||||
b, err := ioutil.ReadAll(r.Body)
|
b, err := ioutil.ReadAll(r.Body)
|
||||||
@ -434,7 +434,7 @@ func TestComposeUpUpdate(t *testing.T) {
|
|||||||
assert.Assert(t, is.Len(containerInspect.Ports, 1))
|
assert.Assert(t, is.Len(containerInspect.Ports, 1))
|
||||||
endpoint := fmt.Sprintf("http://%s:%d", containerInspect.Ports[0].HostIP, containerInspect.Ports[0].HostPort)
|
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.NilError(t, err)
|
||||||
assert.Equal(t, r.StatusCode, http.StatusOK)
|
assert.Equal(t, r.StatusCode, http.StatusOK)
|
||||||
b, err := ioutil.ReadAll(r.Body)
|
b, err := ioutil.ReadAll(r.Body)
|
||||||
|
@ -22,12 +22,14 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"gotest.tools/v3/assert"
|
"gotest.tools/v3/assert"
|
||||||
is "gotest.tools/v3/assert/cmp"
|
is "gotest.tools/v3/assert/cmp"
|
||||||
@ -192,3 +194,21 @@ func ParseContainerInspect(stdout string) (*containers.Container, error) {
|
|||||||
}
|
}
|
||||||
return &res, nil
|
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
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user