Skip to content

Commit 8603acf

Browse files
committed
std: update pipe tests
1 parent 5ca6fb6 commit 8603acf

File tree

4 files changed

+28
-38
lines changed

4 files changed

+28
-38
lines changed

library/std/src/sys/pal/unix/kernel_copy/tests.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,8 @@ fn dont_splice_pipes_from_files() -> Result<()> {
8888

8989
use crate::io::SeekFrom;
9090
use crate::os::unix::fs::FileExt;
91-
use crate::process::{ChildStdin, ChildStdout};
92-
use crate::sys_common::FromInner;
9391

94-
let (read_end, write_end) = crate::sys::pipe::anon_pipe()?;
95-
96-
let mut read_end = ChildStdout::from_inner(read_end);
97-
let mut write_end = ChildStdin::from_inner(write_end);
92+
let (mut read_end, mut write_end) = crate::io::pipe()?;
9893

9994
let tmp_path = tmpdir();
10095
let file = tmp_path.join("to_be_modified");
@@ -220,13 +215,8 @@ fn bench_file_to_uds_copy(b: &mut test::Bencher) {
220215
fn bench_socket_pipe_socket_copy(b: &mut test::Bencher) {
221216
use super::CopyResult;
222217
use crate::io::ErrorKind;
223-
use crate::process::{ChildStdin, ChildStdout};
224-
use crate::sys_common::FromInner;
225-
226-
let (read_end, write_end) = crate::sys::pipe::anon_pipe().unwrap();
227218

228-
let mut read_end = ChildStdout::from_inner(read_end);
229-
let write_end = ChildStdin::from_inner(write_end);
219+
let (mut read_end, write_end) = crate::io::pipe().unwrap();
230220

231221
let acceptor = crate::net::TcpListener::bind("localhost:0").unwrap();
232222
let mut remote_end = crate::net::TcpStream::connect(acceptor.local_addr().unwrap()).unwrap();

library/std/src/sys/pal/windows/handle.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#![unstable(issue = "none", feature = "windows_handle")]
22

3-
#[cfg(test)]
4-
mod tests;
5-
63
use core::ffi::c_void;
74
use core::{cmp, mem, ptr};
85

library/std/src/sys/pal/windows/handle/tests.rs

Lines changed: 0 additions & 22 deletions
This file was deleted.

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
use super::child_pipe::{Pipes, child_pipe};
12
use super::{Arg, make_command_line};
2-
use crate::env;
33
use crate::ffi::{OsStr, OsString};
44
use crate::os::windows::io::AsHandle;
55
use crate::process::{Command, Stdio};
6+
use crate::time::Duration;
7+
use crate::{env, thread};
68

79
#[test]
810
fn test_raw_args() {
@@ -233,3 +235,26 @@ fn windows_exe_resolver() {
233235
);
234236
}
235237
}
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

Comments
 (0)