Skip to content

Commit fefad1d

Browse files
committed
test: fix timeout code for invoking compiler
When running go tool compile, go tool is running compile as a subprocess. Killing go tool with Process.Kill leaves the subprocess behind. Send an interrupt signal first, which it can forward on to the compile subprocess. Also report the timeout in errorcheck -t. Change-Id: I7ae0029bbe543ed7e60e0fea790dd0739d10bcaa Reviewed-on: https://go-review.googlesource.com/c/go/+/282313 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
1 parent 6728118 commit fefad1d

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

test/run.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,8 @@ func goGcflagsIsEmpty() bool {
467467
return "" == os.Getenv("GO_GCFLAGS")
468468
}
469469

470+
var errTimeout = errors.New("command exceeded time limit")
471+
470472
// run runs a test.
471473
func (t *test) run() {
472474
start := time.Now()
@@ -642,16 +644,18 @@ func (t *test) run() {
642644
case err = <-done:
643645
// ok
644646
case <-tick.C:
647+
cmd.Process.Signal(os.Interrupt)
648+
time.Sleep(1 * time.Second)
645649
cmd.Process.Kill()
646-
err = <-done
647-
// err = errors.New("Test timeout")
650+
<-done
651+
err = errTimeout
648652
}
649653
tick.Stop()
650654
}
651655
} else {
652656
err = cmd.Run()
653657
}
654-
if err != nil {
658+
if err != nil && err != errTimeout {
655659
err = fmt.Errorf("%s\n%s", err, buf.Bytes())
656660
}
657661
return buf.Bytes(), err
@@ -731,6 +735,10 @@ func (t *test) run() {
731735
t.err = fmt.Errorf("compilation succeeded unexpectedly\n%s", out)
732736
return
733737
}
738+
if err == errTimeout {
739+
t.err = fmt.Errorf("compilation timed out")
740+
return
741+
}
734742
} else {
735743
if err != nil {
736744
t.err = err

0 commit comments

Comments
 (0)