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:
@@ -445,11 +445,9 @@ func TestSMTP(t *testing.T) {
|
||||
|
||||
// Start mock SMTP server in the background.
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
wg.Go(func() {
|
||||
assert.NoError(t, srv.Serve(listen))
|
||||
}()
|
||||
})
|
||||
|
||||
// Wait for the server to become pingable.
|
||||
require.Eventually(t, func() bool {
|
||||
@@ -590,11 +588,9 @@ func TestSMTPEnvelopeAndHeaders(t *testing.T) {
|
||||
handler := dispatch.NewSMTPHandler(cfg, logger.Named("smtp"))
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
wg.Go(func() {
|
||||
assert.NoError(t, srv.Serve(listen))
|
||||
}()
|
||||
})
|
||||
|
||||
require.Eventually(t, func() bool {
|
||||
cl, err := smtptest.PingClient(listen, false, false)
|
||||
|
||||
Reference in New Issue
Block a user