Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,14 @@ func TestRethinkStore_AcquireUniqueIntegerPoolExhaustionIntegration(t *testing.T
var wg sync.WaitGroup

for i := rs.VRFPoolRangeMin; i <= rs.VRFPoolRangeMax; i++ {
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
got, err := pool.AcquireRandomUniqueInteger()
if err != nil {
t.Fail()
}
assert.GreaterOrEqual(t, got, uint(rs.VRFPoolRangeMin))
assert.LessOrEqual(t, got, uint(rs.VRFPoolRangeMax))
}()
})
}

wg.Wait()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1004,12 +1004,9 @@ func Test_FindWaitingMachine_NoConcurrentModificationErrors(t *testing.T) {
}

for i := range 100 {
wg.Add(1)

log := root.With("worker", i)

go func() {
defer wg.Done()
wg.Go(func() {

for {
machine, err := sharedDS.FindWaitingMachine(context.Background(), "project", "partition", size, nil, metal.RoleMachine)
Expand Down Expand Up @@ -1052,7 +1049,7 @@ func Test_FindWaitingMachine_NoConcurrentModificationErrors(t *testing.T) {

return
}
}()
})
}

wg.Wait()
Expand Down
15 changes: 6 additions & 9 deletions cmd/metal-api/internal/datastore/shared_mutex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func newLockOptAcquireTimeout(t time.Duration) *lockOptAcquireTimeout {

func Test_sharedMutex_reallyLocking(t *testing.T) {
defer mutexCleanup(t)
ctx := context.Background()
ctx := t.Context()
expiration := 10 * time.Second

err := sharedDS.sharedMutex.lock(ctx, "test", expiration, newLockOptAcquireTimeout(10*time.Millisecond))
Expand Down Expand Up @@ -51,20 +51,17 @@ func Test_sharedMutex_reallyLocking(t *testing.T) {

func Test_sharedMutex_acquireAfterRelease(t *testing.T) {
defer mutexCleanup(t)
ctx := context.Background()
ctx := t.Context()

err := sharedDS.sharedMutex.lock(ctx, "test", 3*time.Second, newLockOptAcquireTimeout(10*time.Millisecond))
require.NoError(t, err)

var wg sync.WaitGroup
wg.Add(1)

go func() {
defer wg.Done()
wg.Go(func() {

err = sharedDS.sharedMutex.lock(ctx, "test", 1*time.Second, newLockOptAcquireTimeout(3*time.Second))
assert.NoError(t, err)
}()
})

time.Sleep(1 * time.Second)

Expand All @@ -75,7 +72,7 @@ func Test_sharedMutex_acquireAfterRelease(t *testing.T) {

func Test_sharedMutex_expires(t *testing.T) {
defer mutexCleanup(t)
ctx := context.Background()
ctx := t.Context()

err := sharedDS.sharedMutex.lock(ctx, "test", 2*time.Second, newLockOptAcquireTimeout(10*time.Millisecond))
require.NoError(t, err)
Expand Down Expand Up @@ -105,7 +102,7 @@ func Test_sharedMutex_expires(t *testing.T) {

func Test_sharedMutex_stop(t *testing.T) {
defer mutexCleanup(t)
ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithCancel(t.Context())

mutex, err := newSharedMutex(context.Background(), slog.Default(), sharedDS.dbsession)
require.NoError(t, err)
Expand Down