Skip to content

Commit e3ccf40

Browse files
author
Bryan C. Mills
committed
cmd/go: terminate TestScript commands more aggressively when the test times out
- Avoid starting subprocesses when the test is already very close to timing out. The overhead of starting and stopping processes may cause the test to exceed its deadline even if each individual process is signaled soon after it is started. - If a command does not shut down quickly enough after receiving os.Interrupt, send it os.Kill using the same style of grace period as in CL 228438. - Fail the test if a background command whose exit status is not ignored is left running at the end of the test. We have no reliable way to distinguish a failure due to the termination signal from an unexpected failure, and the termination signal varies across platforms (so may cause failure on one platform but success on another). For #38797 Change-Id: I767898cf551dca45579bf01a9d1bb312e12d6193 Reviewed-on: https://go-review.googlesource.com/c/go/+/233526 Run-TryBot: Bryan C. Mills <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent a88c26e commit e3ccf40

File tree

4 files changed

+202
-113
lines changed

4 files changed

+202
-113
lines changed

src/cmd/go/go_test.go

-20
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package main_test
66

77
import (
88
"bytes"
9-
"context"
109
"debug/elf"
1110
"debug/macho"
1211
"debug/pe"
@@ -114,12 +113,6 @@ var testGo string
114113
var testTmpDir string
115114
var testBin string
116115

117-
// testCtx is canceled when the test binary is about to time out.
118-
//
119-
// If https://golang.org/issue/28135 is accepted, uses of this variable in test
120-
// functions should be replaced by t.Context().
121-
var testCtx = context.Background()
122-
123116
// The TestMain function creates a go command for testing purposes and
124117
// deletes it after the tests have been run.
125118
func TestMain(m *testing.M) {
@@ -135,19 +128,6 @@ func TestMain(m *testing.M) {
135128

136129
flag.Parse()
137130

138-
timeoutFlag := flag.Lookup("test.timeout")
139-
if timeoutFlag != nil {
140-
// TODO(golang.org/issue/28147): The go command does not pass the
141-
// test.timeout flag unless either -timeout or -test.timeout is explicitly
142-
// set on the command line.
143-
if d := timeoutFlag.Value.(flag.Getter).Get().(time.Duration); d != 0 {
144-
aBitShorter := d * 95 / 100
145-
var cancel context.CancelFunc
146-
testCtx, cancel = context.WithTimeout(testCtx, aBitShorter)
147-
defer cancel()
148-
}
149-
}
150-
151131
if *proxyAddr != "" {
152132
StartProxy()
153133
select {}

0 commit comments

Comments
 (0)