diff --git a/cmd/metal-api/internal/datastore/integer_integration_test.go b/cmd/metal-api/internal/datastore/integer_integration_test.go index daf8b0a8..13da7a46 100644 --- a/cmd/metal-api/internal/datastore/integer_integration_test.go +++ b/cmd/metal-api/internal/datastore/integer_integration_test.go @@ -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() diff --git a/cmd/metal-api/internal/datastore/machine_integration_test.go b/cmd/metal-api/internal/datastore/machine_integration_test.go index a7fd82ea..2ba4f849 100644 --- a/cmd/metal-api/internal/datastore/machine_integration_test.go +++ b/cmd/metal-api/internal/datastore/machine_integration_test.go @@ -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) @@ -1052,7 +1049,7 @@ func Test_FindWaitingMachine_NoConcurrentModificationErrors(t *testing.T) { return } - }() + }) } wg.Wait() diff --git a/cmd/metal-api/internal/datastore/shared_mutex_test.go b/cmd/metal-api/internal/datastore/shared_mutex_test.go index 3dd620b3..bd043ece 100644 --- a/cmd/metal-api/internal/datastore/shared_mutex_test.go +++ b/cmd/metal-api/internal/datastore/shared_mutex_test.go @@ -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)) @@ -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) @@ -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) @@ -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)