Skip to content

Commit

Permalink
cmd/go/internal/test: pass default timeout to test programs if it is …
Browse files Browse the repository at this point in the history
…not given from command line

Make 'go test' command to pass the default timeout (10m) to test programs if the value is not given from command line.

Fixes golang#28147
  • Loading branch information
okamotoyuki committed Mar 3, 2019
1 parent fc42cf8 commit 8d5fff1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/cmd/go/go_test.go
Expand Up @@ -6272,3 +6272,11 @@ func TestCoverpkgTestOnly(t *testing.T) {
tg.grepStderrNot("no packages being tested depend on matches", "bad match message")
tg.grepStdout("coverage: 100", "no coverage")
}

// Issue 28147.
func TestGoTestWithoutTimeout(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.run("test", "-v", "testdata/src/testtimeout/testtimeout_test.go")
tg.grepStdout("10m0s", "default timeout was not set")
}
10 changes: 9 additions & 1 deletion src/cmd/go/internal/test/test.go
Expand Up @@ -1122,7 +1122,15 @@ func (c *runCache) builderRunTest(b *work.Builder, a *work.Action) error {
}
}

cmd := exec.Command(args[0], args[1:]...)
var cmd *exec.Cmd

// If a test timeout was not given, pass the default timeout (10s) to test programs.
if len(testTimeout) == 0 {
cmd = exec.Command(args[0], append(args[1:], "-test.timeout=10m")...)
} else {
cmd = exec.Command(args[0], args[1:]...)
}

cmd.Dir = a.Package.Dir
cmd.Env = base.EnvForDir(cmd.Dir, cfg.OrigEnv)
cmd.Stdout = stdout
Expand Down
11 changes: 11 additions & 0 deletions src/cmd/go/testdata/src/testtimeout/testtimeout_test.go
@@ -0,0 +1,11 @@
package testtimeout

import (
"flag"
"fmt"
"testing"
)

func TestTimeout(t *testing.T) {
fmt.Println(flag.Lookup("test.timeout").Value)
}

0 comments on commit 8d5fff1

Please sign in to comment.