From d318ab22647205c4d6d3aa32bb027a434f7b16d3 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Sun, 12 Feb 2012 23:19:24 -0500 Subject: [PATCH] cmd/go: respect test -timeout flag I thought that -timeout was per-test, but it is for the whole program execution, so cmd/go can adjust its timer (also for whole program execution) accordingly. Fixes #2993. R=golang-dev, r CC=golang-dev https://golang.org/cl/5650070 --- src/cmd/go/test.go | 15 ++++++++++++--- src/cmd/go/testflag.go | 2 ++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/cmd/go/test.go b/src/cmd/go/test.go index bc2af619c2..1633244556 100644 --- a/src/cmd/go/test.go +++ b/src/cmd/go/test.go @@ -198,10 +198,13 @@ var ( testX bool // -x flag testV bool // -v flag testFiles []string // -file flag(s) TODO: not respected + testTimeout string // -timeout flag testArgs []string testBench bool testStreamOutput bool // show output as it is generated testShowPass bool // show passing output + + testKillTimeout = 10 * time.Minute ) func runTest(cmd *Command, args []string) { @@ -217,6 +220,14 @@ func runTest(cmd *Command, args []string) { fatalf("cannot use -c flag with multiple packages") } + // If a test timeout was given and is parseable, set our kill timeout + // to that timeout plus one minute. This is a backup alarm in case + // the test wedges with a goroutine spinning and its background + // timer does not get a chance to fire. + if dt, err := time.ParseDuration(testTimeout); err == nil { + testKillTimeout = dt + 1*time.Minute + } + // show passing test output (after buffering) with -v flag. // must buffer because tests are running in parallel, and // otherwise the output will get mixed. @@ -540,9 +551,7 @@ func (b *builder) runTest(a *action) error { // This is a last-ditch deadline to detect and // stop wedged test binaries, to keep the builders // running. - const deadline = 10 * time.Minute - - tick := time.NewTimer(deadline) + tick := time.NewTimer(testKillTimeout) if err == nil { done := make(chan error) go func() { diff --git a/src/cmd/go/testflag.go b/src/cmd/go/testflag.go index 8913b9b504..7c9b7f16dd 100644 --- a/src/cmd/go/testflag.go +++ b/src/cmd/go/testflag.go @@ -133,6 +133,8 @@ func testFlags(args []string) (packageNames, passToTest []string) { case "bench": // record that we saw the flag; don't care about the value testBench = true + case "timeout": + testTimeout = value } if extraWord { i++ -- 2.50.0