From bd0a14fe4090ae2deb5dfe004ff5413ac259dc35 Mon Sep 17 00:00:00 2001 From: Dmitriy Vyukov Date: Thu, 1 Aug 2013 17:24:24 +0400 Subject: [PATCH] testing: say what was the timeout if it fires It looks reasonable here and may be useful. R=golang-dev, r CC=golang-dev https://golang.org/cl/12252043 --- src/pkg/testing/testing.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/pkg/testing/testing.go b/src/pkg/testing/testing.go index 330f3bdb80..85e751048e 100644 --- a/src/pkg/testing/testing.go +++ b/src/pkg/testing/testing.go @@ -371,12 +371,12 @@ func Main(matchString func(pat, str string) (bool, error), tests []InternalTest, haveExamples = len(examples) > 0 testOk := RunTests(matchString, tests) exampleOk := RunExamples(matchString, examples) + stopAlarm() if !testOk || !exampleOk { fmt.Println("FAIL") os.Exit(1) } fmt.Println("PASS") - stopAlarm() RunBenchmarks(matchString, benchmarks) after() } @@ -561,7 +561,9 @@ var timer *time.Timer // startAlarm starts an alarm if requested. func startAlarm() { if *timeout > 0 { - timer = time.AfterFunc(*timeout, alarm) + timer = time.AfterFunc(*timeout, func() { + panic(fmt.Sprintf("test timed out after %v", *timeout)) + }) } } @@ -572,11 +574,6 @@ func stopAlarm() { } } -// alarm is called if the timeout expires. -func alarm() { - panic("test timed out") -} - func parseCpuList() { if len(*cpuListStr) == 0 { cpuList = append(cpuList, runtime.GOMAXPROCS(-1)) -- 2.48.1