Skip to content

Commit 5f8f0e0

Browse files
committed
integration: fix race in embedded DB setup
Signed-off-by: Hank Donnay <[email protected]>
1 parent 2ff15e4 commit 5f8f0e0

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

test/integration/embedded.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"regexp"
1616
"runtime"
1717
"strings"
18+
"sync/atomic"
1819
"testing"
1920
"time"
2021

@@ -54,7 +55,7 @@ type fetchDescriptor struct {
5455
Arch string
5556
Version string
5657
RealVersion string
57-
cached *bool
58+
cached atomic.Bool
5859
}
5960

6061
var embedDB = fetchDescriptor{
@@ -125,17 +126,16 @@ var versionRE = regexp.MustCompile(`^[0-9]+((\.[0-9]+){2})?$`)
125126

126127
func (a *fetchDescriptor) DiscoverVersion(t testing.TB) {
127128
skip := skip() || testing.Short()
128-
if a.cached != nil && (!*a.cached && skip) {
129+
if !a.cached.Load() && skip {
129130
t.Skip("skipping integration test: would need to fetch bom & binaries")
130131
}
131132
shouldFetch := false
132133
defer func() {
133-
a.cached = new(bool)
134134
if t.Failed() || t.Skipped() {
135-
*a.cached = false
135+
a.cached.Store(false)
136136
return
137137
}
138-
*a.cached = !shouldFetch
138+
a.cached.Store(!shouldFetch)
139139
if !shouldFetch {
140140
// If it does exist, wait until we can grab a shared lock. If this blocks,
141141
// it's because another process has the exclusive (write) lock. Any error
@@ -248,7 +248,7 @@ func (a *fetchDescriptor) DiscoverVersion(t testing.TB) {
248248
}
249249

250250
func (a *fetchDescriptor) FetchArchive(t testing.TB) {
251-
if *a.cached {
251+
if a.cached.Load() {
252252
return
253253
}
254254
p := a.Realpath(t)

0 commit comments

Comments
 (0)