Skip to content

Commit 7f4443d

Browse files
committed
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 <[email protected]>
1 parent 9d549b5 commit 7f4443d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/testing/testing.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@ var _ TB = (*B)(nil)
293293
// may be called simultaneously from multiple goroutines.
294294
type T struct {
295295
common
296-
name string // Name of test.
296+
name string // Name of test.
297+
isParallel bool
297298
startParallel chan bool // Parallel tests will wait on this.
298299
}
299300

@@ -430,6 +431,10 @@ func (t *T) Parallel() {
430431
// We don't want to include the time we spend waiting for serial tests
431432
// in the test duration. Record the elapsed time thus far and reset the
432433
// timer afterwards.
434+
if t.isParallel {
435+
panic("testing: t.Parallel called multiple times")
436+
}
437+
t.isParallel = true
433438
t.duration += time.Since(t.start)
434439
t.signal <- (*T)(nil) // Release main testing loop
435440
<-t.startParallel // Wait for serial tests to finish

0 commit comments

Comments
 (0)