Skip to content

Commit

Permalink
cmd/go: terminate TestScript commands more aggressively when the test…
Browse files Browse the repository at this point in the history
… 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 golang#38797

Change-Id: I767898cf551dca45579bf01a9d1bb312e12d6193
Reviewed-on: https://go-review.googlesource.com/c/go/+/233526
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Jay Conrod <jayconrod@google.com>
  • Loading branch information
Bryan C. Mills committed May 14, 2020
1 parent a88c26e commit e3ccf40
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 113 deletions.
20 changes: 0 additions & 20 deletions src/cmd/go/go_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package main_test

import (
"bytes"
"context"
"debug/elf"
"debug/macho"
"debug/pe"
Expand Down Expand Up @@ -114,12 +113,6 @@ var testGo string
var testTmpDir string
var testBin string

// testCtx is canceled when the test binary is about to time out.
//
// If https://golang.org/issue/28135 is accepted, uses of this variable in test
// functions should be replaced by t.Context().
var testCtx = context.Background()

// The TestMain function creates a go command for testing purposes and
// deletes it after the tests have been run.
func TestMain(m *testing.M) {
Expand All @@ -135,19 +128,6 @@ func TestMain(m *testing.M) {

flag.Parse()

timeoutFlag := flag.Lookup("test.timeout")
if timeoutFlag != nil {
// TODO(golang.org/issue/28147): The go command does not pass the
// test.timeout flag unless either -timeout or -test.timeout is explicitly
// set on the command line.
if d := timeoutFlag.Value.(flag.Getter).Get().(time.Duration); d != 0 {
aBitShorter := d * 95 / 100
var cancel context.CancelFunc
testCtx, cancel = context.WithTimeout(testCtx, aBitShorter)
defer cancel()
}
}

if *proxyAddr != "" {
StartProxy()
select {}
Expand Down
Loading

0 comments on commit e3ccf40

Please sign in to comment.