os/exec: avoid leaking a process in TestDoubleStartLeavesPipesOpen

Updates #52580.
For #50436.

Change-Id: I0929055ffca1ca429f6ebec7d877f4268bd1fda2
Reviewed-on: https://go-review.googlesource.com/c/go/+/436656
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
This commit is contained in:
Bryan C. Mills 2022-09-29 09:33:07 -04:00 committed by Gopher Robot
parent 4a0a2b33df
commit ce3a5c0d10

View file

@ -1108,9 +1108,16 @@ func TestDoubleStartLeavesPipesOpen(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if err := cmd.Start(); err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
if err := cmd.Wait(); err != nil {
t.Error(err)
}
})
if err := cmd.Start(); err == nil || !strings.HasSuffix(err.Error(), "already started") {
t.Fatalf("second call to Start returned a nil; want an 'already started' error")
}