Skip to content

Run go test -race in CI

Alessio Caiazza requested to merge nolith/gitlab-pages:race-test into master

This MR adds a new CI job that will run go test -race to avoid shipping data races

We have 3 data races: 2 in test code, and 1 in the package but only triggered by a test behavior.

=== RUN   TestResolve/when_item_is_in_long_cache_only
 ==================
 WARNING: DATA RACE
 Read at 0x00c00010a968 by goroutine 28:
   gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.TestResolve.func5.1.1()
       /builds/nolith/gitlab-pages/internal/source/gitlab/cache/cache_test.go:177 +0x201
   gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.(*Cache).withTestEntry()
       /builds/nolith/gitlab-pages/internal/source/gitlab/cache/cache_test.go:83 +0xde
   gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.TestResolve.func5.1()
       /builds/nolith/gitlab-pages/internal/source/gitlab/cache/cache_test.go:170 +0x8d
   gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.withTestCache()
       /builds/nolith/gitlab-pages/internal/source/gitlab/cache/cache_test.go:63 +0x17d
   gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.TestResolve.func5()
       /builds/nolith/gitlab-pages/internal/source/gitlab/cache/cache_test.go:169 +0x60
   testing.tRunner()
       /usr/local/go/src/testing/testing.go:827 +0x162
 Previous write at 0x00c00010a968 by goroutine 32:
   sync/atomic.AddInt64()
       /usr/local/go/src/runtime/race_amd64.s:276 +0xb
   gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.(*client).GetLookup()
       /builds/nolith/gitlab-pages/internal/source/gitlab/cache/cache_test.go:43 +0x124
   gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.(*Retriever).resolveWithBackoff.func1()
       /builds/nolith/gitlab-pages/internal/source/gitlab/cache/retriever.go:43 +0x10e
 Goroutine 28 (running) created at:
   testing.(*T).Run()
       /usr/local/go/src/testing/testing.go:878 +0x659
   gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.TestResolve()
       /builds/nolith/gitlab-pages/internal/source/gitlab/cache/cache_test.go:168 +0x119
   testing.tRunner()
       /usr/local/go/src/testing/testing.go:827 +0x162
 Goroutine 32 (finished) created at:
   gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.(*Retriever).resolveWithBackoff()
       /builds/nolith/gitlab-pages/internal/source/gitlab/cache/retriever.go:39 +0xa0
   gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.(*Retriever).Retrieve()
       /builds/nolith/gitlab-pages/internal/source/gitlab/cache/retriever.go:29 +0x142
   gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.(*Entry).retrieveWithClient()
       /builds/nolith/gitlab-pages/internal/source/gitlab/cache/entry.go:92 +0xc5
 ==================
 === RUN   TestResolve/when_item_in_long_cache_is_requested_multiple_times
 ==================
 WARNING: DATA RACE
 Read at 0x00c00010aa88 by goroutine 33:
   gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.TestResolve.func6.1.1()
       /builds/nolith/gitlab-pages/internal/source/gitlab/cache/cache_test.go:192 +0x224
   gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.(*Cache).withTestEntry()
       /builds/nolith/gitlab-pages/internal/source/gitlab/cache/cache_test.go:83 +0xde
   gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.TestResolve.func6.1()
       /builds/nolith/gitlab-pages/internal/source/gitlab/cache/cache_test.go:184 +0x8d
   gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.withTestCache()
       /builds/nolith/gitlab-pages/internal/source/gitlab/cache/cache_test.go:63 +0x17d
   gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.TestResolve.func6()
       /builds/nolith/gitlab-pages/internal/source/gitlab/cache/cache_test.go:183 +0x60
   testing.tRunner()
       /usr/local/go/src/testing/testing.go:827 +0x162
 Previous write at 0x00c00010aa88 by goroutine 37:
   sync/atomic.AddInt64()
       /usr/local/go/src/runtime/race_amd64.s:276 +0xb
   gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.(*client).GetLookup()
       /builds/nolith/gitlab-pages/internal/source/gitlab/cache/cache_test.go:43 +0x124
   gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.(*Retriever).resolveWithBackoff.func1()
       /builds/nolith/gitlab-pages/internal/source/gitlab/cache/retriever.go:43 +0x10e
 Goroutine 33 (running) created at:
   testing.(*T).Run()
       /usr/local/go/src/testing/testing.go:878 +0x659
   gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.TestResolve()
       /builds/nolith/gitlab-pages/internal/source/gitlab/cache/cache_test.go:182 +0x148
   testing.tRunner()
       /usr/local/go/src/testing/testing.go:827 +0x162
 Goroutine 37 (finished) created at:
   gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.(*Retriever).resolveWithBackoff()
       /builds/nolith/gitlab-pages/internal/source/gitlab/cache/retriever.go:39 +0xa0
   gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.(*Retriever).Retrieve()
       /builds/nolith/gitlab-pages/internal/source/gitlab/cache/retriever.go:29 +0x142
   gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.(*Entry).retrieveWithClient()
       /builds/nolith/gitlab-pages/internal/source/gitlab/cache/entry.go:92 +0xc5
 ==================
 === RUN   TestResolve/when_retrieval_failed_with_an_error
 === RUN   TestResolve/when_retrieval_failed_because_of_an_external_context_being_canceled
 === RUN   TestResolve/when_retrieval_failed_because_of_an_internal_retriever_context_timeout
 ==================
 WARNING: DATA RACE
 Write at 0x000000e0d4f0 by goroutine 46:
   gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.TestResolve.func9()
       /builds/nolith/gitlab-pages/internal/source/gitlab/cache/cache_test.go:221 +0x3e
   testing.tRunner()
       /usr/local/go/src/testing/testing.go:827 +0x162
 Previous read at 0x000000e0d4f0 by goroutine 44:
   gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.(*Retriever).Retrieve()
       /builds/nolith/gitlab-pages/internal/source/gitlab/cache/retriever.go:22 +0x8d
   gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.(*Entry).retrieveWithClient()
       /builds/nolith/gitlab-pages/internal/source/gitlab/cache/entry.go:92 +0xc5
 Goroutine 46 (running) created at:
   testing.(*T).Run()
       /usr/local/go/src/testing/testing.go:878 +0x659
   gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.TestResolve()
       /builds/nolith/gitlab-pages/internal/source/gitlab/cache/cache_test.go:220 +0x1d5
   testing.tRunner()
       /usr/local/go/src/testing/testing.go:827 +0x162
 Goroutine 44 (running) created at:
   gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.(*Entry).Retrieve.func1()
       /builds/nolith/gitlab-pages/internal/source/gitlab/cache/entry.go:64 +0x67
   sync.(*Once).Do()
       /usr/local/go/src/sync/once.go:44 +0xde
   gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.(*Entry).Retrieve()
       /builds/nolith/gitlab-pages/internal/source/gitlab/cache/entry.go:64 +0xad
   gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.(*Cache).Resolve()
       /builds/nolith/gitlab-pages/internal/source/gitlab/cache/cache.go:89 +0x1ea
   gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.TestResolve.func8.1()
       /builds/nolith/gitlab-pages/internal/source/gitlab/cache/cache_test.go:213 +0x76
   gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.withTestCache()
       /builds/nolith/gitlab-pages/internal/source/gitlab/cache/cache_test.go:63 +0x17d
   gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.TestResolve.func8()
       /builds/nolith/gitlab-pages/internal/source/gitlab/cache/cache_test.go:212 +0xc7
   testing.tRunner()
       /usr/local/go/src/testing/testing.go:827 +0x162
 ==================
Edited by Alessio Caiazza

Merge request reports