Skip to content

Commit 6328e44

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
log: avoid leaking goroutines in TestOutputRace
Leaked goroutines are the only explanation I can think of for excess allocs in TestDiscard, and TestOutputRace is the only place I can see where the log package leaks goroutines. Let's fix that leak and see if it eliminates the TestDiscard flakes. Fixes #58797 (maybe). Change-Id: I2d54dcba3eb52bd10a62cd1c380131add6a2f651 Reviewed-on: https://go-review.googlesource.com/c/go/+/487356 TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Bryan Mills <[email protected]> Run-TryBot: Bryan Mills <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 87272bd commit 6328e44

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/log/log_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,16 @@ func TestNonNewLogger(t *testing.T) {
109109
func TestOutputRace(t *testing.T) {
110110
var b bytes.Buffer
111111
l := New(&b, "", 0)
112+
var wg sync.WaitGroup
113+
wg.Add(100)
112114
for i := 0; i < 100; i++ {
113115
go func() {
116+
defer wg.Done()
114117
l.SetFlags(0)
115118
l.Output(0, "")
116119
}()
117120
}
121+
wg.Wait()
118122
}
119123

120124
func TestFlagAndPrefixSetting(t *testing.T) {

0 commit comments

Comments
 (0)