Skip to content

Commit 7d8bfdd

Browse files
ALTreeianlancetaylor
authored andcommitted
testing: stop timeout-timer after running tests
Fixes #18845 Change-Id: Icdc3e2067807781e42f2ffc94d1824aed94d3713 Reviewed-on: https://go-review.googlesource.com/35956 Run-TryBot: Alberto Donizetti <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 3e55059 commit 7d8bfdd

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

src/cmd/go/go_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3744,6 +3744,13 @@ func TestMatchesOnlySubtestParallelIsOK(t *testing.T) {
37443744
tg.grepBoth(okPattern, "go test did not say ok")
37453745
}
37463746

3747+
// Issue 18845
3748+
func TestBenchTimeout(t *testing.T) {
3749+
tg := testgo(t)
3750+
defer tg.cleanup()
3751+
tg.run("test", "-bench", ".", "-timeout", "750ms", "testdata/timeoutbench_test.go")
3752+
}
3753+
37473754
func TestLinkXImportPathEscape(t *testing.T) {
37483755
// golang.org/issue/16710
37493756
tg := testgo(t)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package timeoutbench_test
2+
3+
import (
4+
"testing"
5+
"time"
6+
)
7+
8+
func BenchmarkSleep1s(b *testing.B) {
9+
time.Sleep(1 * time.Second)
10+
}

src/testing/testing.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,7 @@ func (m *M) Run() int {
821821
haveExamples = len(m.examples) > 0
822822
testRan, testOk := runTests(m.deps.MatchString, m.tests)
823823
exampleRan, exampleOk := runExamples(m.deps.MatchString, m.examples)
824+
stopAlarm()
824825
if !testRan && !exampleRan && *matchBenchmarks == "" {
825826
fmt.Fprintln(os.Stderr, "testing: warning: no tests to run")
826827
}

0 commit comments

Comments
 (0)