Skip to content

Commit

Permalink
Ignore t.Parallel goroutines, they represent queued tests (#25)
Browse files Browse the repository at this point in the history
When t.Parallel is used, tests are queued to run after all serially
executed tests are run. This causes issues if the serial test tries to
verify goroutines.
  • Loading branch information
prashantv authored Jun 11, 2018
1 parent d13b03e commit b12bb1e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 10 additions & 0 deletions leaks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,13 @@ func TestVerifyNoLeaks(t *testing.T) {
require.NotEmpty(t, ft.errors, "Expect errors from VerifyNoLeaks on leaked goroutine")
bg.unblock()
}

func TestVerifyParallel(t *testing.T) {
t.Run("parallel", func(t *testing.T) {
t.Parallel()
})

t.Run("serial", func(t *testing.T) {
VerifyNoLeaks(t)
})
}
4 changes: 3 additions & 1 deletion options.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ func isTestStack(s stack.Stack) bool {
// the test in a separate goroutine and waited for that test goroutine
// to end by waiting on a channel.
// Since go1.7, a separate goroutine is started to wait for signals.
// T.Parallel is for parallel tests, which are blocked until all serial
// tests have run with T.Parallel at the top of the stack.
switch s.FirstFunction() {
case "testing.RunTests", "testing.(*T).Run":
case "testing.RunTests", "testing.(*T).Run", "testing.(*T).Parallel":
// In pre1.7 and post-1.7, background goroutines started by the testing
// package are blocked waiting on a channel.
return strings.HasPrefix(s.State(), "chan receive")
Expand Down

0 comments on commit b12bb1e

Please sign in to comment.