Skip to content

Commit 1550a25

Browse files
committed
fs/tests: Explicitly kill the zombie rather than sleeping until it dies
1 parent ba4dd46 commit 1550a25

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

library/std/src/fs/tests.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -1572,16 +1572,18 @@ fn test_eq_direntry_metadata() {
15721572
#[test]
15731573
#[cfg(target_os = "linux")]
15741574
fn test_read_dir_infinite_loop() {
1575+
use crate::io::ErrorKind;
15751576
use crate::process::Command;
1576-
use crate::thread::sleep;
1577-
use crate::time::Duration;
15781577

1579-
// Create a child process
1580-
let Ok(child) = Command::new("echo").spawn() else { return };
1578+
// Create a zombie child process
1579+
let Ok(mut child) = Command::new("echo").spawn() else { return };
15811580

1582-
// Wait for it to (probably) become a zombie. We can't use wait() because
1583-
// that will reap the process.
1584-
sleep(Duration::from_millis(10));
1581+
// Make sure the process is (un)dead
1582+
match child.kill() {
1583+
// InvalidInput means the child already exited
1584+
Err(e) if e.kind() != ErrorKind::InvalidInput => return,
1585+
_ => {}
1586+
}
15851587

15861588
// open() on this path will succeed, but readdir() will fail
15871589
let id = child.id();

0 commit comments

Comments
 (0)