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:
@@ -286,9 +286,7 @@ func TestConcurrencyLimit(t *testing.T) {
|
||||
|
||||
var wg sync.WaitGroup
|
||||
for i := 0; i < maxConcurrency; i++ {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
wg.Go(func() {
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, server.URL+"/", nil)
|
||||
if err != nil {
|
||||
results <- result{err: err}
|
||||
@@ -301,7 +299,7 @@ func TestConcurrencyLimit(t *testing.T) {
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
results <- result{statusCode: resp.StatusCode}
|
||||
}()
|
||||
})
|
||||
}
|
||||
|
||||
// Wait for all requests to enter the handler with a timeout.
|
||||
|
||||
Reference in New Issue
Block a user