From 7694bf329d89c15d34e9b58d48de472ec50d537a Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 7 Apr 2020 16:39:42 -0700 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Bryan C. Mills --- src/os/exec/exec_test.go | 17 ++++++++++++++--- 1 file 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 -- 2.50.0