From: Alberto Donizetti Date: Sun, 29 Jan 2017 19:53:35 +0000 (+0100) Subject: [release-branch.go1.8] testing: stop timeout-timer after running tests X-Git-Tag: go1.8~20 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=470704531d93d1bcc24493abea882f99593bcac6;p=gostls13.git [release-branch.go1.8] testing: stop timeout-timer after running tests Fixes #18845 Fixes #18870 (Go 1.8 backport) Change-Id: Icdc3e2067807781e42f2ffc94d1824aed94d3713 Reviewed-on: https://go-review.googlesource.com/35956 Run-TryBot: Alberto Donizetti TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor (cherry picked from commit 7d8bfdde453445affb50fcaeacc050938ec98467) Reviewed-on: https://go-review.googlesource.com/36125 --- diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index f26c3660e4..ef5348bba4 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -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 index 0000000000..57a8888299 --- /dev/null +++ b/src/cmd/go/testdata/timeoutbench_test.go @@ -0,0 +1,10 @@ +package timeoutbench_test + +import ( + "testing" + "time" +) + +func BenchmarkSleep1s(b *testing.B) { + time.Sleep(1 * time.Second) +} diff --git a/src/testing/testing.go b/src/testing/testing.go index ddbdc25bf1..bd19a31c27 100644 --- a/src/testing/testing.go +++ b/src/testing/testing.go @@ -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") }