1
0
mirror of https://github.com/golang/go synced 2024-11-17 13:54:46 -07:00

net/http: use testenv.Command instead of exec.Command in tests

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>
This commit is contained in:
Bryan C. Mills 2023-08-22 11:01:29 -04:00 committed by Gopher Robot
parent 282cd561bb
commit 5dda490372
4 changed files with 10 additions and 10 deletions

View 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" {

View 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

View 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)
}

View 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),