diff options
| author | Chris Denton <chris@chrisdenton.dev> | 2025-08-30 12:07:25 +0000 |
|---|---|---|
| committer | Chris Denton <chris@chrisdenton.dev> | 2025-08-30 18:07:09 +0000 |
| commit | 3516e25eedcf7438e04b6c1f5a7a926ac2c893bc (patch) | |
| tree | af19e80a2c4c223059d737de3d2e6d24d21c2c71 /library/std/src/sys/process | |
| parent | 846e377215c5985b3a0fe7af6bb71bdc45912aae (diff) | |
| download | rust-3516e25eedcf7438e04b6c1f5a7a926ac2c893bc.tar.gz rust-3516e25eedcf7438e04b6c1f5a7a926ac2c893bc.zip | |
Fix spurious test timeout
Diffstat (limited to 'library/std/src/sys/process')
| -rw-r--r-- | library/std/src/sys/process/windows/tests.rs | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/library/std/src/sys/process/windows/tests.rs b/library/std/src/sys/process/windows/tests.rs index 1377e12162f..a21afe3363c 100644 --- a/library/std/src/sys/process/windows/tests.rs +++ b/library/std/src/sys/process/windows/tests.rs @@ -1,7 +1,8 @@ use super::{Arg, make_command_line}; use crate::env; use crate::ffi::{OsStr, OsString}; -use crate::process::Command; +use crate::os::windows::io::AsHandle; +use crate::process::{Command, Stdio}; #[test] fn test_raw_args() { @@ -29,19 +30,30 @@ fn test_thread_handle() { use crate::os::windows::process::{ChildExt, CommandExt}; const CREATE_SUSPENDED: u32 = 0x00000004; - let p = Command::new("cmd").args(&["/C", "exit 0"]).creation_flags(CREATE_SUSPENDED).spawn(); + let p = Command::new("whoami").stdout(Stdio::null()).creation_flags(CREATE_SUSPENDED).spawn(); assert!(p.is_ok()); - let mut p = p.unwrap(); + + // Ensure the process is killed in the event something goes wrong. + struct DropGuard(crate::process::Child); + impl Drop for DropGuard { + fn drop(&mut self) { + let _ = self.0.kill(); + } + } + let mut p = DropGuard(p.unwrap()); + let p = &mut p.0; unsafe extern "system" { - fn ResumeThread(_: BorrowedHandle<'_>) -> u32; + unsafe fn ResumeThread(hHandle: BorrowedHandle<'_>) -> u32; + unsafe fn WaitForSingleObject(hHandle: BorrowedHandle<'_>, dwMilliseconds: u32) -> u32; } unsafe { ResumeThread(p.main_thread_handle()); + // Wait until the process exits or 1 minute passes. + // We don't bother checking the result here as that's done below using `try_wait`. + WaitForSingleObject(p.as_handle(), 1000 * 60); } - crate::thread::sleep(crate::time::Duration::from_millis(100)); - let res = p.try_wait(); assert!(res.is_ok()); assert!(res.unwrap().is_some()); |
