From: Bryan C. Mills Date: Tue, 8 Aug 2023 16:02:02 +0000 (-0400) Subject: cmd/cgo/internal/testplugin: simplify TestForkExec and log stderr output X-Git-Tag: go1.22rc1~1365 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=0c13bd637c87581c9f0f63d9cca57b80b8de2dc0;p=gostls13.git cmd/cgo/internal/testplugin: simplify TestForkExec and log stderr output This test used to run with a separate goroutine for timeout behavior, presumably because it was difficult to set an appropriate timeout. Now that the test is in cmd instead of misc, we can use internal/testenv.Command, which makes adding the test timeout much simpler and eliminates the need for the explicit goroutine. For #61846. Change-Id: I68ea09fcf2aa394bed1e900cf30ef7d143fa249f Reviewed-on: https://go-review.googlesource.com/c/go/+/517095 TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor Run-TryBot: Bryan Mills Auto-Submit: Bryan Mills --- diff --git a/src/cmd/cgo/internal/testplugin/plugin_test.go b/src/cmd/cgo/internal/testplugin/plugin_test.go index 53ccc17a07..22fa35512b 100644 --- a/src/cmd/cgo/internal/testplugin/plugin_test.go +++ b/src/cmd/cgo/internal/testplugin/plugin_test.go @@ -367,25 +367,16 @@ func TestForkExec(t *testing.T) { t.Parallel() goCmd(t, "build", "-o", "forkexec.exe", "./forkexec/main.go") - var cmd *exec.Cmd - done := make(chan int, 1) - - go func() { - for i := 0; i < 100; i++ { - cmd = exec.Command("./forkexec.exe", "1") - err := cmd.Run() - if err != nil { - t.Errorf("running command failed: %v", err) - break + for i := 0; i < 100; i++ { + cmd := testenv.Command(t, "./forkexec.exe", "1") + err := cmd.Run() + if err != nil { + if ee, ok := err.(*exec.ExitError); ok && len(ee.Stderr) > 0 { + t.Logf("stderr:\n%s", ee.Stderr) } + t.Errorf("running command failed: %v", err) + break } - done <- 1 - }() - select { - case <-done: - case <-time.After(5 * time.Minute): - cmd.Process.Kill() - t.Fatalf("subprocess hang") } }