diff options
author | feistel <6742251-feistel@users.noreply.gitlab.com> | 2022-06-22 21:46:35 +0300 |
---|---|---|
committer | feistel <6742251-feistel@users.noreply.gitlab.com> | 2022-06-29 19:00:27 +0300 |
commit | b8060e2c4a5fbb3e17ffa784f3c74bfee0e8a763 (patch) | |
tree | a91668feaf313e8e784337920293d44cf6cf6ba6 /test/acceptance/helpers_test.go | |
parent | 705e7da14a6cda9a90539eb6a66659998dd9921b (diff) |
Refactor test ping to use healthcheck path
Diffstat (limited to 'test/acceptance/helpers_test.go')
-rw-r--r-- | test/acceptance/helpers_test.go | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/test/acceptance/helpers_test.go b/test/acceptance/helpers_test.go index 4c365c5e..5ee409bf 100644 --- a/test/acceptance/helpers_test.go +++ b/test/acceptance/helpers_test.go @@ -190,33 +190,36 @@ func (l ListenSpec) QuickTimeoutClient() *http.Client { // Returns only once this spec points at a working TCP server func (l ListenSpec) WaitUntilRequestSucceeds(done chan struct{}) error { timeout := 5 * time.Second - for start := time.Now(); time.Since(start) < timeout; { + + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + + ticker := time.NewTicker(100 * time.Millisecond) + defer ticker.Stop() + + for { select { case <-done: return fmt.Errorf("server has shut down already") - default: - } + case <-ctx.Done(): + return fmt.Errorf("ctx done: %w for listener %v", ctx.Err(), l) + case <-ticker.C: + req, err := http.NewRequestWithContext(ctx, http.MethodGet, l.URL("/@healthcheck"), nil) + if err != nil { + return err + } - req, err := http.NewRequest("GET", l.URL("/"), nil) - if err != nil { - return err - } + response, err := l.QuickTimeoutClient().Transport.RoundTrip(req) - response, err := l.QuickTimeoutClient().Transport.RoundTrip(req) - if err != nil { - time.Sleep(100 * time.Millisecond) - continue - } - response.Body.Close() + if err == nil { + response.Body.Close() - if code := response.StatusCode; code >= 200 && code < 500 { - return nil + if code := response.StatusCode; code >= 200 && code < 500 { + return nil + } + } } - - time.Sleep(100 * time.Millisecond) } - - return fmt.Errorf("timed out after %v waiting for listener %v", timeout, l) } func (l ListenSpec) JoinHostPort() string { @@ -339,6 +342,7 @@ func runPagesProcess(t *testing.T, wait bool, pagesBinary string, listeners []Li func getPagesArgs(t *testing.T, listeners []ListenSpec, promPort string, extraArgs []string) (args []string) { var hasHTTPS bool args = append(args, "-log-verbose=true") + args = append(args, "-pages-status=/@healthcheck") for _, spec := range listeners { if spec.Type == "unix" { |