Pārlūkot izejas kodu

HttpRetry : do not get stuck on first call, timeout http requests and retry in case of failures

Signed-off-by: Guillaume Tardif <[email protected]>
Guillaume Tardif 5 gadi atpakaļ
vecāks
revīzija
289c83efe2
1 mainītis faili ar 5 papildinājumiem un 2 dzēšanām
  1. 5 2
      tests/framework/e2e.go

+ 5 - 2
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())
 		}