diff options
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) +} |