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:
@@ -429,11 +429,9 @@ func setupTestListener(t *testing.T, l net.Listener, prefix []byte) string {
|
||||
return
|
||||
}
|
||||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
wg.Go(func() {
|
||||
echoIfPrefixed(t, c, prefix)
|
||||
wg.Done()
|
||||
}()
|
||||
})
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
+6
-12
@@ -1360,12 +1360,10 @@ func TestSSH(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
wg.Go(func() {
|
||||
defer fd.Close()
|
||||
agentssh.Bicopy(ctx, fd, fd)
|
||||
}()
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1426,12 +1424,10 @@ func TestSSH(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
wg.Go(func() {
|
||||
defer fd.Close()
|
||||
agentssh.Bicopy(ctx, fd, fd)
|
||||
}()
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1576,12 +1572,10 @@ func TestSSH(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
wg.Go(func() {
|
||||
defer fd.Close()
|
||||
agentssh.Bicopy(ctx, fd, fd)
|
||||
}()
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user