mirror of
https://github.com/golang/go
synced 2024-09-29 13:14:28 -06:00
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>
This commit is contained in:
parent
e3323f57df
commit
7694bf329d
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user