mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
refactor: use sync.WaitGroup.Go in tests (#26671)
Migrate `wg.Add(1); go func() { defer wg.Done(); ... }()` to
`wg.Go(func() { ... })` in tests.
Where the prior pattern passed the loop variable explicitly via a
closure parameter (`go func(id int) { ... }(i)`), drop the parameter and
reference the loop variable directly. Per-iteration loop variables since
Go 1.22 make this safe.
This commit is contained in:
@@ -1974,9 +1974,7 @@ func TestReconciliationLock(t *testing.T) {
|
||||
wg := sync.WaitGroup{}
|
||||
mutex := sync.Mutex{}
|
||||
for i := 0; i < 5; i++ {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
wg.Go(func() {
|
||||
cache := files.New(prometheus.NewRegistry(), &coderdtest.FakeAuthorizer{})
|
||||
reconciler := prebuilds.NewStoreReconciler(
|
||||
db,
|
||||
@@ -2002,7 +2000,7 @@ func TestReconciliationLock(t *testing.T) {
|
||||
defer mutex.Unlock()
|
||||
return nil
|
||||
})
|
||||
}()
|
||||
})
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
@@ -152,13 +152,11 @@ func TestWorkspaceQuota(t *testing.T) {
|
||||
// Spin up three workspaces fine
|
||||
var wg sync.WaitGroup
|
||||
for i := 0; i < 4; i++ {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
wg.Go(func() {
|
||||
workspace := coderdtest.CreateWorkspace(t, client, template.ID)
|
||||
build := coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID)
|
||||
assert.Equal(t, codersdk.WorkspaceStatusRunning, build.Status)
|
||||
}()
|
||||
})
|
||||
}
|
||||
wg.Wait()
|
||||
verifyQuota(ctx, t, client, user.OrganizationID.String(), 4, 4)
|
||||
|
||||
Reference in New Issue
Block a user