|
| 1 | +use super::child_pipe::{Pipes, child_pipe}; |
1 | 2 | use super::{Arg, make_command_line}; |
2 | | -use crate::env; |
3 | 3 | use crate::ffi::{OsStr, OsString}; |
4 | 4 | use crate::os::windows::io::AsHandle; |
5 | 5 | use crate::process::{Command, Stdio}; |
| 6 | +use crate::time::Duration; |
| 7 | +use crate::{env, thread}; |
6 | 8 |
|
7 | 9 | #[test] |
8 | 10 | fn test_raw_args() { |
@@ -233,3 +235,26 @@ fn windows_exe_resolver() { |
233 | 235 | ); |
234 | 236 | } |
235 | 237 | } |
| 238 | + |
| 239 | +/// Test the synchronous fallback for overlapped I/O. |
| 240 | +/// |
| 241 | +/// While technically testing `Handle` functionality, this is situated in this |
| 242 | +/// module to allow easier access to `ChildPipe`. |
| 243 | +#[test] |
| 244 | +fn overlapped_handle_fallback() { |
| 245 | + // Create some pipes. `ours` will be asynchronous. |
| 246 | + let Pipes { ours, theirs } = child_pipe(true, false).unwrap(); |
| 247 | + |
| 248 | + let async_readable = ours.into_handle(); |
| 249 | + let sync_writeable = theirs.into_handle(); |
| 250 | + |
| 251 | + thread::scope(|_| { |
| 252 | + thread::sleep(Duration::from_millis(100)); |
| 253 | + sync_writeable.write(b"hello world!").unwrap(); |
| 254 | + }); |
| 255 | + |
| 256 | + // The pipe buffer starts empty so reading won't complete synchronously unless |
| 257 | + // our fallback path works. |
| 258 | + let mut buffer = [0u8; 1024]; |
| 259 | + async_readable.read(&mut buffer).unwrap(); |
| 260 | +} |
0 commit comments