Skip to content

Commit 4ff5fa6

Browse files
authored
clarify README (#134)
someone at Uber unfortunately spent cycles trying to convert VerifyTestMain call to VerifyNone(t) for individual cases only to find out that it doesn't work well with t.Parallel(). Even though VerifyNone(t)'s documentation already says this, it might be worth clarifying this in the README since the wording can make it sound like calling VerifyTestMain() vs calling VerifyNone() at the end of every single test case is completely identical in behavior.
1 parent 79b1d32 commit 4ff5fa6

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,33 @@ func TestMain(m *testing.M) {
3434
}
3535
```
3636

37+
### Note
38+
39+
For tests that use [t.Parallel](https://pkg.go.dev/testing#T.Parallel), `goleak` does
40+
not know how to distinguish a leaky goroutine from tests that have not finished running.
41+
42+
43+
```go
44+
func TestA(t *testing.T) {
45+
tt := struct{
46+
name string
47+
input SomeType
48+
expected string
49+
}{
50+
// ...
51+
}
52+
53+
for _, t := range tt {
54+
t.Run(t.name, func(t *testing.T) {
55+
t.Parallel() // <- goleak gets confused here!
56+
57+
// ...
58+
}
59+
}
60+
}
61+
```
62+
For such cases you should also defer to using `goleak.VerifyTestMain` as shown above.
63+
3764
## Determine Source of Package Leaks
3865

3966
When verifying leaks using `TestMain`, the leak test is only run once after all tests

0 commit comments

Comments
 (0)