MCPcopy
hub / github.com/docker/compose / HTTPGetWithRetry

Function HTTPGetWithRetry

pkg/e2e/framework.go:481–514  ·  pkg/e2e/framework.go::HTTPGetWithRetry

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 expected one, it retries the same request, returning the response body as a string (empty if we could not reach it)

(
	t testing.TB,
	endpoint string,
	expectedStatus int,
	retryDelay time.Duration,
	timeout time.Duration,
)

Source from the content-addressed store, hash-verified

479// In the case of an error or the response status is not the expected one, it retries the same request,
480// returning the response body as a string (empty if we could not reach it)
481func HTTPGetWithRetry(
482 t testing.TB,
483 endpoint string,
484 expectedStatus int,
485 retryDelay time.Duration,
486 timeout time.Duration,
487) string {
488 t.Helper()
489 var (
490 r *http.Response
491 err error
492 )
493 client := &http.Client{
494 Timeout: retryDelay,
495 }
496 fmt.Printf("\t[%s] GET %s\n", t.Name(), endpoint)
497 checkUp := func(t poll.LogT) poll.Result {
498 r, err = client.Get(endpoint)
499 if err != nil {
500 return poll.Continue("reaching %q: Error %s", endpoint, err.Error())
501 }
502 if r.StatusCode == expectedStatus {
503 return poll.Success()
504 }
505 return poll.Continue("reaching %q: %d != %d", endpoint, r.StatusCode, expectedStatus)
506 }
507 poll.WaitOn(t, checkUp, poll.WithDelay(retryDelay), poll.WithTimeout(timeout))
508 if r != nil {
509 b, err := io.ReadAll(r.Body)
510 assert.NilError(t, err)
511 return string(b)
512 }
513 return ""
514}
515
516func (c *CLI) cleanupWithDown(t testing.TB, project string, args ...string) {
517 t.Helper()

Callers 6

TestLocalComposeUpFunction · 0.85
TestLocalComposeVolumeFunction · 0.85
TestNetworksFunction · 0.85
TestPauseFunction · 0.85
TestLocalComposeBuildFunction · 0.85

Calls 2

ErrorMethod · 0.80
NameMethod · 0.45

Tested by 6

TestLocalComposeUpFunction · 0.68
TestLocalComposeVolumeFunction · 0.68
TestNetworksFunction · 0.68
TestPauseFunction · 0.68
TestLocalComposeBuildFunction · 0.68