aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2015-12-29 12:10:01 -0500
committerRuss Cox <rsc@golang.org>2016-01-04 20:10:17 +0000
commit7f4443d5fa9248c1d0e9d07b2c502a46ca252db2 (patch)
tree5edcb559754542d5564b9ae5b0baa4762ab0f908 /src/testing/testing.go
parent9d549b5b62f3afd9704c66b5e348a976b2614909 (diff)
downloadgo-7f4443d5fa9248c1d0e9d07b2c502a46ca252db2.tar.xz
testing: add clear panic for duplicate call to t.Parallel
Change-Id: I155633b58e1823344a26c3edf11f5626fae080ee Reviewed-on: https://go-review.googlesource.com/18204 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/testing/testing.go')
-rw-r--r--src/testing/testing.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/testing/testing.go b/src/testing/testing.go
index 2081365abf..c33a997372 100644
--- a/src/testing/testing.go
+++ b/src/testing/testing.go
@@ -293,7 +293,8 @@ var _ TB = (*B)(nil)
// may be called simultaneously from multiple goroutines.
type T struct {
common
- name string // Name of test.
+ name string // Name of test.
+ isParallel bool
startParallel chan bool // Parallel tests will wait on this.
}
@@ -430,6 +431,10 @@ func (t *T) Parallel() {
// We don't want to include the time we spend waiting for serial tests
// in the test duration. Record the elapsed time thus far and reset the
// timer afterwards.
+ if t.isParallel {
+ panic("testing: t.Parallel called multiple times")
+ }
+ t.isParallel = true
t.duration += time.Since(t.start)
t.signal <- (*T)(nil) // Release main testing loop
<-t.startParallel // Wait for serial tests to finish