mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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>
This commit is contained in:
parent
9d549b5b62
commit
7f4443d5fa
1 changed files with 6 additions and 1 deletions
|
|
@ -293,7 +293,8 @@ var _ TB = (*B)(nil)
|
||||||
// may be called simultaneously from multiple goroutines.
|
// may be called simultaneously from multiple goroutines.
|
||||||
type T struct {
|
type T struct {
|
||||||
common
|
common
|
||||||
name string // Name of test.
|
name string // Name of test.
|
||||||
|
isParallel bool
|
||||||
startParallel chan bool // Parallel tests will wait on this.
|
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
|
// 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
|
// in the test duration. Record the elapsed time thus far and reset the
|
||||||
// timer afterwards.
|
// timer afterwards.
|
||||||
|
if t.isParallel {
|
||||||
|
panic("testing: t.Parallel called multiple times")
|
||||||
|
}
|
||||||
|
t.isParallel = true
|
||||||
t.duration += time.Since(t.start)
|
t.duration += time.Since(t.start)
|
||||||
t.signal <- (*T)(nil) // Release main testing loop
|
t.signal <- (*T)(nil) // Release main testing loop
|
||||||
<-t.startParallel // Wait for serial tests to finish
|
<-t.startParallel // Wait for serial tests to finish
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue