diff options
author | Jaime Martinez <jmartinez@gitlab.com> | 2021-12-07 08:19:30 +0300 |
---|---|---|
committer | Jaime Martinez <jmartinez@gitlab.com> | 2021-12-08 04:21:29 +0300 |
commit | d7c9431546fc48a02f1e176b2ac21a6c8927542c (patch) | |
tree | 3d595a00a9fb4a257d21ee5425354995fc9a6434 /test | |
parent | c57f28159a32b325ec54f190b0f13c4676600d42 (diff) |
test: add slow req acceptance test
Diffstat (limited to 'test')
-rw-r--r-- | test/acceptance/helpers_test.go | 5 | ||||
-rw-r--r-- | test/acceptance/serving_test.go | 30 |
2 files changed, 35 insertions, 0 deletions
diff --git a/test/acceptance/helpers_test.go b/test/acceptance/helpers_test.go index ce2d47d3..769b0467 100644 --- a/test/acceptance/helpers_test.go +++ b/test/acceptance/helpers_test.go @@ -449,6 +449,7 @@ type stubOpts struct { pagesHandler http.HandlerFunc pagesStatusResponse int pagesRoot string + delay time.Duration } func NewGitlabDomainsSourceStub(t *testing.T, opts *stubOpts) *httptest.Server { @@ -529,6 +530,10 @@ func defaultAPIHandler(t *testing.T, opts *stubOpts) http.HandlerFunc { w.WriteHeader(http.StatusNoContent) return } + // to test slow responses from the API + if opts.delay > 0 { + time.Sleep(opts.delay) + } opts.setAPICalled(true) diff --git a/test/acceptance/serving_test.go b/test/acceptance/serving_test.go index c79894f4..8b01f5b2 100644 --- a/test/acceptance/serving_test.go +++ b/test/acceptance/serving_test.go @@ -1,6 +1,7 @@ package acceptance_test import ( + "context" "fmt" "io" "net/http" @@ -551,3 +552,32 @@ func TestDiskDisabledFailsToServeFileAndLocalContent(t *testing.T) { }, time.Second, 10*time.Millisecond) } } + +func TestSlowRequests(t *testing.T) { + opts := &stubOpts{ + delay: 250 * time.Millisecond, + } + logBuf := RunPagesProcess(t, + withStubOptions(opts), + withExtraArgument("gitlab-retrieval-timeout", "1s"), + withListeners([]ListenSpec{httpListener}), + ) + + ctx, cancel := context.WithTimeout(context.Background(), opts.delay/2) + defer cancel() + + url := httpListener.URL("/index.html") + req, err := http.NewRequestWithContext(ctx, "GET", url, nil) + require.NoError(t, err) + + req.Host = "group.gitlab-example.com" + + _, err = DoPagesRequest(t, httpListener, req) + require.Error(t, err, "cancelling the context should trigger this error") + + require.Eventually(t, func() bool { + require.Contains(t, logBuf.String(), "context done: context canceled", "error mismatch") + require.Contains(t, logBuf.String(), "\"status\":404", "status mismatch") + return true + }, time.Second, time.Millisecond) +} |