mirror of
https://github.com/docker/compose.git
synced 2025-07-22 13:14:29 +02:00
HttpRetry : do not get stuck on first call, timeout http requests and retry in case of failures
Signed-off-by: Guillaume Tardif <guillaume.tardif@docker.com>
This commit is contained in:
parent
4f87422a79
commit
289c83efe2
@ -207,7 +207,7 @@ func ParseContainerInspect(stdout string) (*containers.Container, error) {
|
|||||||
return &res, nil
|
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,
|
// 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)
|
// 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 {
|
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
|
r *http.Response
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
client := &http.Client{
|
||||||
|
Timeout: retryDelay * time.Second,
|
||||||
|
}
|
||||||
checkUp := func(t poll.LogT) poll.Result {
|
checkUp := func(t poll.LogT) poll.Result {
|
||||||
r, err = http.Get(endpoint)
|
r, err = client.Get(endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return poll.Continue("reaching %q: Error %s", endpoint, err.Error())
|
return poll.Continue("reaching %q: Error %s", endpoint, err.Error())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user