mirror of https://github.com/golang/go.git
os: invoke processKiller synchronously in testKillProcess
Previously, testKillProcess needlessly invoked processKiller in a separate goroutine and failed to wait for that goroutine to complete, causing the calls to t.Fatalf in that goroutine to potentially occur after the test function had already returned. Fixes #43722 Change-Id: I5d03cb24af51bb73f0ff96419dac57ec39776967 Reviewed-on: https://go-review.googlesource.com/c/go/+/284153 Trust: Bryan C. Mills <bcmills@google.com> Trust: Jason A. Donenfeld <Jason@zx2c4.com> Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com> Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com> TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
parent
ff196c3e84
commit
1deae0b597
|
|
@ -2298,6 +2298,7 @@ func TestLongPath(t *testing.T) {
|
||||||
|
|
||||||
func testKillProcess(t *testing.T, processKiller func(p *Process)) {
|
func testKillProcess(t *testing.T, processKiller func(p *Process)) {
|
||||||
testenv.MustHaveExec(t)
|
testenv.MustHaveExec(t)
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
// Re-exec the test binary itself to emulate "sleep 1".
|
// Re-exec the test binary itself to emulate "sleep 1".
|
||||||
cmd := osexec.Command(Args[0], "-test.run", "TestSleep")
|
cmd := osexec.Command(Args[0], "-test.run", "TestSleep")
|
||||||
|
|
@ -2305,14 +2306,15 @@ func testKillProcess(t *testing.T, processKiller func(p *Process)) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to start test process: %v", err)
|
t.Fatalf("Failed to start test process: %v", err)
|
||||||
}
|
}
|
||||||
go func() {
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
defer func() {
|
||||||
processKiller(cmd.Process)
|
if err := cmd.Wait(); err == nil {
|
||||||
|
t.Errorf("Test process succeeded, but expected to fail")
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
err = cmd.Wait()
|
|
||||||
if err == nil {
|
time.Sleep(100 * time.Millisecond)
|
||||||
t.Errorf("Test process succeeded, but expected to fail")
|
processKiller(cmd.Process)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestSleep emulates "sleep 1". It is a helper for testKillProcess, so we
|
// TestSleep emulates "sleep 1". It is a helper for testKillProcess, so we
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue