Skip to content

Commit bc13453

Browse files
committed
Fix spurious test timeout
1 parent 846e377 commit bc13453

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

  • library/std/src/sys/process/windows

library/std/src/sys/process/windows/tests.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use super::{Arg, make_command_line};
22
use crate::env;
33
use crate::ffi::{OsStr, OsString};
4-
use crate::process::Command;
4+
use crate::os::windows::io::AsHandle;
5+
use crate::process::{Command, Stdio};
56

67
#[test]
78
fn test_raw_args() {
@@ -29,19 +30,21 @@ fn test_thread_handle() {
2930
use crate::os::windows::process::{ChildExt, CommandExt};
3031
const CREATE_SUSPENDED: u32 = 0x00000004;
3132

32-
let p = Command::new("cmd").args(&["/C", "exit 0"]).creation_flags(CREATE_SUSPENDED).spawn();
33+
let p = Command::new("whoami").stdout(Stdio::null()).creation_flags(CREATE_SUSPENDED).spawn();
3334
assert!(p.is_ok());
3435
let mut p = p.unwrap();
3536

3637
unsafe extern "system" {
37-
fn ResumeThread(_: BorrowedHandle<'_>) -> u32;
38+
unsafe fn ResumeThread(hHandle: BorrowedHandle<'_>) -> u32;
39+
unsafe fn WaitForSingleObject(hHandle: BorrowedHandle<'_>, dwMilliseconds: u32) -> u32;
3840
}
3941
unsafe {
4042
ResumeThread(p.main_thread_handle());
43+
// Wait until the process exits or 1 minute passes.
44+
// We don't bother checking the result here as that's done below using `try_wait`.
45+
WaitForSingleObject(p.as_handle(), 1000 * 60);
4146
}
4247

43-
crate::thread::sleep(crate::time::Duration::from_millis(100));
44-
4548
let res = p.try_wait();
4649
assert!(res.is_ok());
4750
assert!(res.unwrap().is_some());

0 commit comments

Comments
 (0)