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
@@ -416,12 +416,10 @@ func TestConfigCache_Singleflight(t *testing.T) {
var wg sync.WaitGroup
start := make(chan struct{})
for i := 0; i < callers; i++ {
wg.Add(1)
go func(i int) {
defer wg.Done()
wg.Go(func() {
<-start
results[i], errs[i] = cache.EnabledProviders(ctx)
}(i)
})
}
close(start)
+2 -4
View File
@@ -139,11 +139,9 @@ func TestPubsub(t *testing.T) {
var first, second error
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
first = ps.Close()
}()
})
wg.Wait()
second = ps.Close()
assert.NoError(t, first)