build: modernize with "go fix -waitgroupgo": use WaitGroup.Go

This commit is contained in:
Nick Craig-Wood
2026-08-21 12:23:31 +01:00
parent 2d1a3386a8
commit a017a54bef
2 changed files with 14 additions and 28 deletions
+12 -24
View File
@@ -288,22 +288,18 @@ func TestOutputHandlerConcurrency(t *testing.T) {
// Goroutines calling Handle (text format)
for range goroutines {
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
for range iterations {
r := slog.NewRecord(t0, slog.LevelInfo, "concurrent text", 0)
r.AddAttrs(slog.String("object", "obj"))
_ = h.Handle(ctx, r)
}
}()
})
}
// Goroutines calling setFormat (switching between text and JSON)
for range 2 {
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
for j := range iterations {
if j%2 == 0 {
h.setFormat(logFormatDate | logFormatTime)
@@ -311,23 +307,19 @@ func TestOutputHandlerConcurrency(t *testing.T) {
h.setFormat(logFormatJSON)
}
}
}()
})
}
// Goroutines calling setFormatFlags / clearFormatFlags
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
for range iterations {
h.setFormatFlags(logFormatPid | logFormatMicroseconds)
h.clearFormatFlags(logFormatPid | logFormatMicroseconds)
}
}()
})
// Goroutines calling SetLevel
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
for j := range iterations {
if j%2 == 0 {
h.SetLevel(slog.LevelDebug)
@@ -335,28 +327,24 @@ func TestOutputHandlerConcurrency(t *testing.T) {
h.SetLevel(slog.LevelInfo)
}
}
}()
})
// Goroutines calling SetOutput / ResetOutput
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
noop := func(_ slog.Level, _ string) {}
for range iterations {
h.SetOutput(noop)
h.ResetOutput()
}
}()
})
// Goroutines calling WithAttrs / WithGroup (reads format)
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
for range iterations {
_ = h.WithAttrs(nil)
_ = h.WithGroup("g")
}
}()
})
// Use a channel with a timeout to detect deadlocks
done := make(chan struct{})
+2 -4
View File
@@ -58,16 +58,14 @@ func TestAuxConcurrent(t *testing.T) {
wg sync.WaitGroup
)
for i := range owners {
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
owner := &i
for j := range iterations {
value := fmt.Sprintf("%d-%d", i, j)
a.SetAux(owner, value)
assert.Equal(t, value, a.Aux(owner))
}
}()
})
}
wg.Wait()
}