diff options
author | Jaime Martinez <jmartinez@gitlab.com> | 2021-03-23 08:05:25 +0300 |
---|---|---|
committer | Jaime Martinez <jmartinez@gitlab.com> | 2021-03-23 08:10:39 +0300 |
commit | 2b0d654d661e4ad031b652760f56c9d086d62c90 (patch) | |
tree | b767c84d49c00486ed8884e2663f23ef64ac89a5 | |
parent | c07661daf1c4d5ac64d25d67e8f707bbfe36ea54 (diff) |
Fix data race in test
-rw-r--r-- | .gitlab/ci/test.yml | 2 | ||||
-rw-r--r-- | Makefile.util.mk | 2 | ||||
-rw-r--r-- | test/acceptance/serving_test.go | 12 |
3 files changed, 14 insertions, 2 deletions
diff --git a/.gitlab/ci/test.yml b/.gitlab/ci/test.yml index 74d49ee6..b4f1eefd 100644 --- a/.gitlab/ci/test.yml +++ b/.gitlab/ci/test.yml @@ -53,7 +53,9 @@ race: extends: .tests-common script: - echo "Running race detector" + - make setup - make race + - make junit-report cover: extends: .tests-common diff --git a/Makefile.util.mk b/Makefile.util.mk index 5d5355e4..8d470564 100644 --- a/Makefile.util.mk +++ b/Makefile.util.mk @@ -14,7 +14,7 @@ test: .GOPATH/.ok gitlab-pages go test $(if $V,-v) $(allpackages) 2>&1 | tee tests.out race: .GOPATH/.ok gitlab-pages - CGO_ENABLED=1 go test -race $(if $V,-v) $(allpackages) + CGO_ENABLED=1 go test -race $(if $V,-v) $(allpackages) 2>&1 | tee tests.out acceptance: .GOPATH/.ok gitlab-pages go test $(if $V,-v) ./test/acceptance ${ARGS} 2>&1 | tee tests.out diff --git a/test/acceptance/serving_test.go b/test/acceptance/serving_test.go index 07dc0345..b3098912 100644 --- a/test/acceptance/serving_test.go +++ b/test/acceptance/serving_test.go @@ -8,6 +8,7 @@ import ( "os" "path" "strings" + "sync" "testing" "time" @@ -615,6 +616,8 @@ func TestDomainResolverError(t *testing.T) { }, } + m := sync.RWMutex{} + for name, test := range tests { t.Run(name, func(t *testing.T) { // handler setup @@ -624,6 +627,9 @@ func TestDomainResolverError(t *testing.T) { return } + m.Lock() + defer m.Unlock() + opts.apiCalled = true if test.panic { panic("server failed") @@ -639,7 +645,8 @@ func TestDomainResolverError(t *testing.T) { pagesArgs := []string{"-gitlab-server", source.URL, "-api-secret-key", gitLabAPISecretKey, "-domain-config-source", "gitlab"} if test.timeout != 0 { - pagesArgs = append(pagesArgs, "-gitlab-client-http-timeout", test.timeout.String()) + pagesArgs = append(pagesArgs, "-gitlab-client-http-timeout", test.timeout.String(), + "-gitlab-retrieval-timeout", "200ms", "-gitlab-retrieval-interval", "200ms", "-gitlab-retrieval-retries", "1") } teardown := RunPagesProcessWithEnvs(t, true, *pagesBinary, listeners, "", []string{}, pagesArgs...) @@ -649,7 +656,10 @@ func TestDomainResolverError(t *testing.T) { require.NoError(t, err) defer response.Body.Close() + m.RLock() require.True(t, opts.apiCalled, "api must have been called") + m.RUnlock() + require.Equal(t, http.StatusBadGateway, response.StatusCode) body, err := ioutil.ReadAll(response.Body) |