diff options
author | Ian Lance Taylor <iant@golang.org> | 2020-04-07 16:39:42 -0700 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2020-04-08 21:34:49 +0000 |
commit | 7694bf329d89c15d34e9b58d48de472ec50d537a (patch) | |
tree | 1754beae1777aeac5a1a64a055937c768d3a67e4 /src/os/exec/exec_test.go | |
parent | e3323f57df1f4a44093a2d25fee33513325cbb86 (diff) | |
download | go-7694bf329d89c15d34e9b58d48de472ec50d537a.tar.gz go-7694bf329d89c15d34e9b58d48de472ec50d537a.zip |
os/exec: use subprocess deadline in TestExtraFiles
Try to get some output even if the subprocess hangs.
For #25628
Change-Id: I4cc0a8f2c52b03a322b8fd0a620cba37b06ff10a
Reviewed-on: https://go-review.googlesource.com/c/go/+/227517
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/os/exec/exec_test.go')
-rw-r--r-- | src/os/exec/exec_test.go | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/os/exec/exec_test.go b/src/os/exec/exec_test.go index 9d6069093e..8609b28bd4 100644 --- a/src/os/exec/exec_test.go +++ b/src/os/exec/exec_test.go @@ -82,8 +82,12 @@ func helperCommandContext(t *testing.T, ctx context.Context, s ...string) (cmd * // Temporary code to try to resolve #25628. // TODO(iant): Remove this when we no longer need it. - if runtime.GOARCH == "386" && runtime.GOOS == "linux" && testenv.Builder() != "" && len(s) == 1 && s[0] == "read3" && ctx == nil { - cmd = exec.Command("/usr/bin/strace", append([]string{"-f", os.Args[0]}, cs...)...) + if runtime.GOARCH == "386" && runtime.GOOS == "linux" && testenv.Builder() != "" && len(s) == 1 && s[0] == "read3" { + sctx := ctx + if sctx == nil { + sctx = context.Background() + } + cmd = exec.CommandContext(sctx, "/usr/bin/strace", append([]string{"-f", os.Args[0]}, cs...)...) } cmd.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=1") @@ -683,7 +687,14 @@ func TestExtraFiles(t *testing.T) { t.Fatalf("Seek: %v", err) } - c := helperCommand(t, "read3") + // Use a deadline to try to get some output even if the program hangs. + ctx := context.Background() + if deadline, ok := t.Deadline(); ok { + var cancel context.CancelFunc + ctx, cancel = context.WithDeadline(ctx, deadline.Add(-time.Second)) + defer cancel() + } + c := helperCommandContext(t, ctx, "read3") var stdout, stderr bytes.Buffer c.Stdout = &stdout c.Stderr = &stderr |