]> Cypherpunks.ru repositories - gostls13.git/commitdiff
net/http: use testenv.Command instead of exec.Command in tests
authorBryan C. Mills <bcmills@google.com>
Tue, 22 Aug 2023 15:01:29 +0000 (11:01 -0400)
committerGopher Robot <gobot@golang.org>
Tue, 22 Aug 2023 18:18:19 +0000 (18:18 +0000)
On Unix platforms, testenv.Command sends SIGQUIT to stuck commands
before the test times out. For subprocesses that are written in Go,
that causes the runtime to dump running goroutines, and in other
languages it triggers similar behavior (such as a core dump).
If the subprocess is stuck due to a bug (such as #57999), that may
help to diagnose it.

For #57999.

Change-Id: Ia2e9d14718a26001e030e162c69892497a8ebb21
Reviewed-on: https://go-review.googlesource.com/c/go/+/521816
Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>

src/net/http/cgi/host_test.go
src/net/http/fs_test.go
src/net/http/http_test.go
src/net/http/serve_test.go

index 860e9b3e8f1b8f67a1b125b7b38e8fe2b5f8c3f5..707af71dd7969703433b7cb85f1ba87c14448d62 100644 (file)
@@ -9,6 +9,7 @@ package cgi
 import (
        "bufio"
        "fmt"
+       "internal/testenv"
        "io"
        "net"
        "net/http"
@@ -93,7 +94,7 @@ var cgiTested, cgiWorks bool
 func check(t *testing.T) {
        if !cgiTested {
                cgiTested = true
-               cgiWorks = exec.Command("./testdata/test.cgi").Run() == nil
+               cgiWorks = testenv.Command(t, "./testdata/test.cgi").Run() == nil
        }
        if !cgiWorks {
                // No Perl on Windows, needed by test.cgi
@@ -462,7 +463,7 @@ func findPerl(t *testing.T) string {
        }
        perl, _ = filepath.Abs(perl)
 
-       cmd := exec.Command(perl, "-e", "print 123")
+       cmd := testenv.Command(t, perl, "-e", "print 123")
        cmd.Env = []string{"PATH=/garbage"}
        out, err := cmd.Output()
        if err != nil || string(out) != "123" {
index bb96d2ca689cf81ff587d8929a3506342ff53cfc..2e1577365264618f98385e432e19d99ab10dae2b 100644 (file)
@@ -9,6 +9,7 @@ import (
        "bytes"
        "errors"
        "fmt"
+       "internal/testenv"
        "io"
        "io/fs"
        "mime"
@@ -1266,7 +1267,7 @@ func TestLinuxSendfile(t *testing.T) {
        defer ln.Close()
 
        // Attempt to run strace, and skip on failure - this test requires SYS_PTRACE.
-       if err := exec.Command("strace", "-f", "-q", os.Args[0], "-test.run=^$").Run(); err != nil {
+       if err := testenv.Command(t, "strace", "-f", "-q", os.Args[0], "-test.run=^$").Run(); err != nil {
                t.Skipf("skipping; failed to run strace: %v", err)
        }
 
@@ -1279,7 +1280,7 @@ func TestLinuxSendfile(t *testing.T) {
        defer os.Remove(filepath)
 
        var buf strings.Builder
-       child := exec.Command("strace", "-f", "-q", os.Args[0], "-test.run=TestLinuxSendfileChild")
+       child := testenv.Command(t, "strace", "-f", "-q", os.Args[0], "-test.run=TestLinuxSendfileChild")
        child.ExtraFiles = append(child.ExtraFiles, lnf)
        child.Env = append([]string{"GO_WANT_HELPER_PROCESS=1"}, os.Environ()...)
        child.Stdout = &buf
index 91bb1b2620ab2e936703189cf60340e8d523a00b..2e7e024e2057f39ada5778752ce4ae78d96fa043 100644 (file)
@@ -12,7 +12,6 @@ import (
        "io/fs"
        "net/url"
        "os"
-       "os/exec"
        "reflect"
        "regexp"
        "strings"
@@ -55,7 +54,7 @@ func TestForeachHeaderElement(t *testing.T) {
 func TestCmdGoNoHTTPServer(t *testing.T) {
        t.Parallel()
        goBin := testenv.GoToolPath(t)
-       out, err := exec.Command(goBin, "tool", "nm", goBin).CombinedOutput()
+       out, err := testenv.Command(t, goBin, "tool", "nm", goBin).CombinedOutput()
        if err != nil {
                t.Fatalf("go tool nm: %v: %s", err, out)
        }
@@ -89,7 +88,7 @@ func TestOmitHTTP2(t *testing.T) {
        }
        t.Parallel()
        goTool := testenv.GoToolPath(t)
-       out, err := exec.Command(goTool, "test", "-short", "-tags=nethttpomithttp2", "net/http").CombinedOutput()
+       out, err := testenv.Command(t, goTool, "test", "-short", "-tags=nethttpomithttp2", "net/http").CombinedOutput()
        if err != nil {
                t.Fatalf("go test -short failed: %v, %s", err, out)
        }
@@ -101,7 +100,7 @@ func TestOmitHTTP2(t *testing.T) {
 func TestOmitHTTP2Vet(t *testing.T) {
        t.Parallel()
        goTool := testenv.GoToolPath(t)
-       out, err := exec.Command(goTool, "vet", "-tags=nethttpomithttp2", "net/http").CombinedOutput()
+       out, err := testenv.Command(t, goTool, "vet", "-tags=nethttpomithttp2", "net/http").CombinedOutput()
        if err != nil {
                t.Fatalf("go vet failed: %v, %s", err, out)
        }
index bb380cf4a5378d01d6c915b7f2930388e3e79b39..1f215bd84396a27fa20f562e608e5ab1f6d42074 100644 (file)
@@ -30,7 +30,6 @@ import (
        "net/http/internal/testcert"
        "net/url"
        "os"
-       "os/exec"
        "path/filepath"
        "reflect"
        "regexp"
@@ -5005,7 +5004,7 @@ func BenchmarkServer(b *testing.B) {
        defer ts.Close()
        b.StartTimer()
 
-       cmd := exec.Command(os.Args[0], "-test.run=XXXX", "-test.bench=BenchmarkServer$")
+       cmd := testenv.Command(b, os.Args[0], "-test.run=XXXX", "-test.bench=BenchmarkServer$")
        cmd.Env = append([]string{
                fmt.Sprintf("TEST_BENCH_CLIENT_N=%d", b.N),
                fmt.Sprintf("TEST_BENCH_SERVER_URL=%s", ts.URL),