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:
Zach
2026-06-25 15:41:09 -06:00
committed by GitHub
parent b95f2531b5
commit 953091c7bc
24 changed files with 100 additions and 180 deletions
+2 -4
View File
@@ -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
View File
@@ -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)
}()
})
}
})