]> Cypherpunks repositories - gostls13.git/commitdiff
testing: pause the test timer while waiting in T.Parallel
authorCaleb Spare <cespare@gmail.com>
Tue, 17 Nov 2015 03:34:54 +0000 (19:34 -0800)
committerRuss Cox <rsc@golang.org>
Tue, 24 Nov 2015 17:07:45 +0000 (17:07 +0000)
Before, we reset the timer at the end of T.Parallel, which is okay
assuming that T.Parallel is the first thing in the test.

Snapshot the elapsed time at the beginning of Parallel and include it in
the total duration so that any time spent in the test before calling
Parallel is reported in the test duration as well.

Updates #12243.

Change-Id: Ieca553e1f801e16b9b6416463fa8f7fa65425185
Reviewed-on: https://go-review.googlesource.com/16989
Reviewed-by: Russ Cox <rsc@golang.org>
src/testing/testing.go

index 6237da9abd3a1685b4fd728128fa4760c12ec28c..c478adea9f92085e0de74b198ab0c2adbce5b2d2 100644 (file)
@@ -418,10 +418,12 @@ func (c *common) Skipped() bool {
 // Parallel signals that this test is to be run in parallel with (and only with)
 // other parallel tests.
 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.
+       t.duration += time.Since(t.start)
        t.signal <- (*T)(nil) // Release main testing loop
        <-t.startParallel     // Wait for serial tests to finish
-       // Assuming Parallel is the first thing a test does, which is reasonable,
-       // reinitialize the test's start time because it's actually starting now.
        t.start = time.Now()
 }
 
@@ -438,7 +440,7 @@ func tRunner(t *T, test *InternalTest) {
        // a call to runtime.Goexit, record the duration and send
        // a signal saying that the test is done.
        defer func() {
-               t.duration = time.Now().Sub(t.start)
+               t.duration += time.Now().Sub(t.start)
                // If the test panicked, print any test output before dying.
                err := recover()
                if !t.finished && err == nil {