]> Cypherpunks repositories - gostls13.git/commitdiff
testing: add clear panic for duplicate call to t.Parallel
authorRuss Cox <rsc@golang.org>
Tue, 29 Dec 2015 17:10:01 +0000 (12:10 -0500)
committerRuss Cox <rsc@golang.org>
Mon, 4 Jan 2016 20:10:17 +0000 (20:10 +0000)
Change-Id: I155633b58e1823344a26c3edf11f5626fae080ee
Reviewed-on: https://go-review.googlesource.com/18204
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/testing/testing.go

index 2081365abf3f14b4255a73aa2f07bf5c5e79422a..c33a997372c682f719b8863228c78b948efa20b8 100644 (file)
@@ -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