Skip to content

Commit

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

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

Fixes golang#28147
  • Loading branch information
okamotoyuki committed Mar 6, 2019
1 parent 0ff0df8 commit ae998de
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/cmd/go/internal/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,9 @@ func runTest(cmd *base.Command, args []string) {
testKillTimeout = 100 * 365 * 24 * time.Hour
}

// Pass timeout flag to tests.
testArgs = append(testArgs, "-test.timeout="+testKillTimeout.String())

// show passing test output (after buffering) with -v flag.
// must buffer because tests are running in parallel, and
// otherwise the output will get mixed.
Expand Down
21 changes: 21 additions & 0 deletions src/cmd/go/testdata/script/test_timeout.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
env GO111MODULE=off
cd a

# No timeout is passed via 'go test' command.
go test -v
stdout '10m0s'

# Timeout is passed via 'go test' command.
go test -v -timeout 30m
stdout '31m0s'

-- a/timeout_test.go --
package t
import (
"flag"
"fmt"
"testing"
)
func TestTimeout(t *testing.T) {
fmt.Println(flag.Lookup("test.timeout").Value.String())
}

0 comments on commit ae998de

Please sign in to comment.