mirror of https://github.com/docker/compose.git
e2e.framework: Add helper to retry HTTP requests
Signed-off-by: Chris Crone <christopher.crone@docker.com>
This commit is contained in:
parent
9545625131
commit
6f0f9e5600
|
@ -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…
Reference in New Issue