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:
Guillaume Tardif 2020-10-09 14:26:26 +02:00
parent 4f87422a79
commit 289c83efe2
1 changed files with 5 additions and 2 deletions

View File

@ -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())
}