testing: are T.Run and B.Run safe for concurrent use? #18603

tombergan opened this Issue Jan 11, 2017 · 3 comments


None yet

4 participants

tombergan commented Jan 11, 2017 edited

I do not see any documentation specifying if T.Run is safe for concurrent use. I see the following doc for testing.T, which does not mention T.Run:

A test ends when its Test function returns or calls any of the methods FailNow, Fatal, Fatalf, SkipNow, Skip, or Skipf. Those methods, as well as the Parallel method, must be called only from the goroutine running the Test function.

The other reporting methods, such as the variations of Log and Error, may be called simultaneously from multiple goroutines.

There is a similar doc for testing.B.

I ask because I believe T.Run was safe for concurrent use in go 1.7. Then, this line was added in go 1.8, which made T.Run no longer safe for concurrent use. I don't particularly care whether T.Run is safe for concurrent use, but I think the semantics should be clarified.

Optimistically labeling this go1.8.

/cc @dsnet

@tombergan tombergan added this to the Go1.8 milestone Jan 11, 2017
dsnet commented Jan 11, 2017 edited

If T.Run was safe concurrently in Go1.7, even if it was ambiguous whether it should be, it's worth considering whether it should continue to be concurrent safe in Go1.8.

\cc @mpvl

(moving to Go1.8Maybe; I don't think this is a release blocker at this point)

@dsnet dsnet modified the milestone: Go1.8Maybe, Go1.8 Jan 11, 2017
@dsnet dsnet added the NeedsDecision label Jan 11, 2017
rsc commented Jan 18, 2017

Not sure whether @mpvl is around. Sent https://go-review.googlesource.com/35354.
/cc @bradfitz


CL https://golang.org/cl/35354 mentions this issue.

@gopherbot gopherbot pushed a commit that closed this issue Jan 18, 2017
@rsc @dsnet rsc + dsnet testing: make parallel t.Run safe again
Fixes #18603.

Change-Id: I5760c0a9f862200b7e943058a672eb559ac1b9d9
Reviewed-on: https://go-review.googlesource.com/35354
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
@gopherbot gopherbot closed this in d10eddc Jan 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment