Skip to content

Commit 1deae0b

Browse files
author
Bryan C. Mills
committed
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 <[email protected]> Trust: Jason A. Donenfeld <[email protected]> Reviewed-by: Jason A. Donenfeld <[email protected]> Run-TryBot: Jason A. Donenfeld <[email protected]> TryBot-Result: Go Bot <[email protected]>
1 parent ff196c3 commit 1deae0b

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/os/os_test.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -2298,21 +2298,23 @@ func TestLongPath(t *testing.T) {
22982298

22992299
func testKillProcess(t *testing.T, processKiller func(p *Process)) {
23002300
testenv.MustHaveExec(t)
2301+
t.Parallel()
23012302

23022303
// Re-exec the test binary itself to emulate "sleep 1".
23032304
cmd := osexec.Command(Args[0], "-test.run", "TestSleep")
23042305
err := cmd.Start()
23052306
if err != nil {
23062307
t.Fatalf("Failed to start test process: %v", err)
23072308
}
2308-
go func() {
2309-
time.Sleep(100 * time.Millisecond)
2310-
processKiller(cmd.Process)
2309+
2310+
defer func() {
2311+
if err := cmd.Wait(); err == nil {
2312+
t.Errorf("Test process succeeded, but expected to fail")
2313+
}
23112314
}()
2312-
err = cmd.Wait()
2313-
if err == nil {
2314-
t.Errorf("Test process succeeded, but expected to fail")
2315-
}
2315+
2316+
time.Sleep(100 * time.Millisecond)
2317+
processKiller(cmd.Process)
23162318
}
23172319

23182320
// TestSleep emulates "sleep 1". It is a helper for testKillProcess, so we

0 commit comments

Comments
 (0)