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 | |
parent | 705e7da14a6cda9a90539eb6a66659998dd9921b (diff) |
Refactor test ping to use healthcheck path
Diffstat (limited to 'test/acceptance')
-rw-r--r-- | test/acceptance/helpers_test.go | 42 | ||||
-rw-r--r-- | test/acceptance/ratelimiter_test.go | 22 | ||||
-rw-r--r-- | test/acceptance/status_test.go | 3 |
3 files changed, 30 insertions, 37 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" { diff --git a/test/acceptance/ratelimiter_test.go b/test/acceptance/ratelimiter_test.go index ef49aa19..85e0f6aa 100644 --- a/test/acceptance/ratelimiter_test.go +++ b/test/acceptance/ratelimiter_test.go @@ -16,19 +16,14 @@ var ratelimitedListeners = map[string]struct { listener ListenSpec header http.Header clientIP string - // We perform requests to server while we're waiting for it to boot up, - // successful request gets counted in IP rate limit - includeWaitRequest bool }{ "http_listener": { - listener: httpListener, - clientIP: "127.0.0.1", - includeWaitRequest: true, + listener: httpListener, + clientIP: "127.0.0.1", }, "https_listener": { - listener: httpsListener, - clientIP: "127.0.0.1", - includeWaitRequest: true, + listener: httpsListener, + clientIP: "127.0.0.1", }, "proxy_listener": { listener: proxyListener, @@ -39,9 +34,8 @@ var ratelimitedListeners = map[string]struct { clientIP: "172.16.123.1", }, "proxyv2_listener": { - listener: httpsProxyv2Listener, - clientIP: "10.1.1.1", - includeWaitRequest: true, + listener: httpsProxyv2Listener, + clientIP: "10.1.1.1", }, } @@ -57,10 +51,6 @@ func TestIPRateLimits(t *testing.T) { withExtraArgument("rate-limit-source-ip-burst", fmt.Sprint(rateLimit)), ) - if tc.includeWaitRequest { - rateLimit-- // we've already used one of requests while checking if server is up - } - for i := 0; i < 10; i++ { rsp, err := GetPageFromListenerWithHeaders(t, tc.listener, "group.gitlab-example.com", "project/", tc.header) require.NoError(t, err) diff --git a/test/acceptance/status_test.go b/test/acceptance/status_test.go index c48aaff7..a57ae043 100644 --- a/test/acceptance/status_test.go +++ b/test/acceptance/status_test.go @@ -12,10 +12,9 @@ import ( func TestStatusPage(t *testing.T) { RunPagesProcess(t, withListeners([]ListenSpec{httpListener}), - withExtraArgument("pages-status", "/@statuscheck"), ) - rsp, err := GetPageFromListener(t, httpListener, "group.gitlab-example.com", "@statuscheck") + rsp, err := GetPageFromListener(t, httpListener, "group.gitlab-example.com", "@healthcheck") require.NoError(t, err) testhelpers.Close(t, rsp.Body) require.Equal(t, http.StatusOK, rsp.StatusCode) |