]> Cypherpunks repositories - gostls13.git/commitdiff
testing: stop timeout-timer after running tests
authorAlberto Donizetti <alb.donizetti@gmail.com>
Sun, 29 Jan 2017 19:53:35 +0000 (20:53 +0100)
committerIan Lance Taylor <iant@golang.org>
Tue, 31 Jan 2017 17:36:49 +0000 (17:36 +0000)
Fixes #18845

Change-Id: Icdc3e2067807781e42f2ffc94d1824aed94d3713
Reviewed-on: https://go-review.googlesource.com/35956
Run-TryBot: Alberto Donizetti <alb.donizetti@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/go/go_test.go
src/cmd/go/testdata/timeoutbench_test.go [new file with mode: 0644]
src/testing/testing.go

index f26c3660e4b809a1ea76d13b4d1a2176fdf419d4..ef5348bba40ff8844911e57dce951ad904086cf9 100644 (file)
@@ -3744,6 +3744,13 @@ func TestMatchesOnlySubtestParallelIsOK(t *testing.T) {
        tg.grepBoth(okPattern, "go test did not say ok")
 }
 
+// Issue 18845
+func TestBenchTimeout(t *testing.T) {
+       tg := testgo(t)
+       defer tg.cleanup()
+       tg.run("test", "-bench", ".", "-timeout", "750ms", "testdata/timeoutbench_test.go")
+}
+
 func TestLinkXImportPathEscape(t *testing.T) {
        // golang.org/issue/16710
        tg := testgo(t)
diff --git a/src/cmd/go/testdata/timeoutbench_test.go b/src/cmd/go/testdata/timeoutbench_test.go
new file mode 100644 (file)
index 0000000..57a8888
--- /dev/null
@@ -0,0 +1,10 @@
+package timeoutbench_test
+
+import (
+       "testing"
+       "time"
+)
+
+func BenchmarkSleep1s(b *testing.B) {
+       time.Sleep(1 * time.Second)
+}
index ddbdc25bf11d5d7d69d5443ec68b74cad413d12d..bd19a31c27c85ad61e3e378d00641ec615accf21 100644 (file)
@@ -821,6 +821,7 @@ func (m *M) Run() int {
        haveExamples = len(m.examples) > 0
        testRan, testOk := runTests(m.deps.MatchString, m.tests)
        exampleRan, exampleOk := runExamples(m.deps.MatchString, m.examples)
+       stopAlarm()
        if !testRan && !exampleRan && *matchBenchmarks == "" {
                fmt.Fprintln(os.Stderr, "testing: warning: no tests to run")
        }