]> Cypherpunks repositories - gostls13.git/commitdiff
os/exec: use subprocess deadline in TestExtraFiles
authorIan Lance Taylor <iant@golang.org>
Tue, 7 Apr 2020 23:39:42 +0000 (16:39 -0700)
committerIan Lance Taylor <iant@golang.org>
Wed, 8 Apr 2020 21:34:49 +0000 (21:34 +0000)
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>
src/os/exec/exec_test.go

index 9d6069093e7d5a23b6ca795ef5b231d51288a3d3..8609b28bd4923a533545832ed2164ea9ab8c24b7 100644 (file)
@@ -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