Skip to content

Commit

Permalink
integration: fix race in embedded DB setup
Browse files Browse the repository at this point in the history
Signed-off-by: Hank Donnay <[email protected]>
  • Loading branch information
hdonnay committed Jan 10, 2024
1 parent 2ff15e4 commit 5f8f0e0
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions test/integration/embedded.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"regexp"
"runtime"
"strings"
"sync/atomic"
"testing"
"time"

Expand Down Expand Up @@ -54,7 +55,7 @@ type fetchDescriptor struct {
Arch string
Version string
RealVersion string
cached *bool
cached atomic.Bool
}

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

func (a *fetchDescriptor) DiscoverVersion(t testing.TB) {
skip := skip() || testing.Short()
if a.cached != nil && (!*a.cached && skip) {
if !a.cached.Load() && skip {
t.Skip("skipping integration test: would need to fetch bom & binaries")
}
shouldFetch := false
defer func() {
a.cached = new(bool)
if t.Failed() || t.Skipped() {
*a.cached = false
a.cached.Store(false)
return
}
*a.cached = !shouldFetch
a.cached.Store(!shouldFetch)
if !shouldFetch {
// If it does exist, wait until we can grab a shared lock. If this blocks,
// it's because another process has the exclusive (write) lock. Any error
Expand Down Expand Up @@ -248,7 +248,7 @@ func (a *fetchDescriptor) DiscoverVersion(t testing.TB) {
}

func (a *fetchDescriptor) FetchArchive(t testing.TB) {
if *a.cached {
if a.cached.Load() {
return
}
p := a.Realpath(t)
Expand Down

0 comments on commit 5f8f0e0

Please sign in to comment.