std: update pipe tests

This commit is contained in:
joboet 2025-09-20 11:39:07 +02:00
parent 860716faa3
commit 653520afb2
No known key found for this signature in database
GPG key ID: 704E0149B0194B3C
4 changed files with 28 additions and 38 deletions

View file

@ -88,13 +88,8 @@ fn dont_splice_pipes_from_files() -> Result<()> {
use crate::io::SeekFrom;
use crate::os::unix::fs::FileExt;
use crate::process::{ChildStdin, ChildStdout};
use crate::sys_common::FromInner;
let (read_end, write_end) = crate::sys::pipe::anon_pipe()?;
let mut read_end = ChildStdout::from_inner(read_end);
let mut write_end = ChildStdin::from_inner(write_end);
let (mut read_end, mut write_end) = crate::io::pipe()?;
let tmp_path = tmpdir();
let file = tmp_path.join("to_be_modified");
@ -220,13 +215,8 @@ fn bench_file_to_uds_copy(b: &mut test::Bencher) {
fn bench_socket_pipe_socket_copy(b: &mut test::Bencher) {
use super::CopyResult;
use crate::io::ErrorKind;
use crate::process::{ChildStdin, ChildStdout};
use crate::sys_common::FromInner;
let (read_end, write_end) = crate::sys::pipe::anon_pipe().unwrap();
let mut read_end = ChildStdout::from_inner(read_end);
let write_end = ChildStdin::from_inner(write_end);
let (mut read_end, write_end) = crate::io::pipe().unwrap();
let acceptor = crate::net::TcpListener::bind("localhost:0").unwrap();
let mut remote_end = crate::net::TcpStream::connect(acceptor.local_addr().unwrap()).unwrap();

View file

@ -1,8 +1,5 @@
#![unstable(issue = "none", feature = "windows_handle")]
#[cfg(test)]
mod tests;
use core::ffi::c_void;
use core::{cmp, mem, ptr};

View file

@ -1,22 +0,0 @@
use crate::sys::pipe::{Pipes, anon_pipe};
use crate::{thread, time};
/// Test the synchronous fallback for overlapped I/O.
#[test]
fn overlapped_handle_fallback() {
// Create some pipes. `ours` will be asynchronous.
let Pipes { ours, theirs } = anon_pipe(true, false).unwrap();
let async_readable = ours.into_handle();
let sync_writeable = theirs.into_handle();
thread::scope(|_| {
thread::sleep(time::Duration::from_millis(100));
sync_writeable.write(b"hello world!").unwrap();
});
// The pipe buffer starts empty so reading won't complete synchronously unless
// our fallback path works.
let mut buffer = [0u8; 1024];
async_readable.read(&mut buffer).unwrap();
}

View file

@ -1,8 +1,10 @@
use super::child_pipe::{Pipes, child_pipe};
use super::{Arg, make_command_line};
use crate::env;
use crate::ffi::{OsStr, OsString};
use crate::os::windows::io::AsHandle;
use crate::process::{Command, Stdio};
use crate::time::Duration;
use crate::{env, thread};
#[test]
fn test_raw_args() {
@ -233,3 +235,26 @@ fn windows_exe_resolver() {
);
}
}
/// Test the synchronous fallback for overlapped I/O.
///
/// While technically testing `Handle` functionality, this is situated in this
/// module to allow easier access to `ChildPipe`.
#[test]
fn overlapped_handle_fallback() {
// Create some pipes. `ours` will be asynchronous.
let Pipes { ours, theirs } = child_pipe(true, false).unwrap();
let async_readable = ours.into_handle();
let sync_writeable = theirs.into_handle();
thread::scope(|_| {
thread::sleep(Duration::from_millis(100));
sync_writeable.write(b"hello world!").unwrap();
});
// The pipe buffer starts empty so reading won't complete synchronously unless
// our fallback path works.
let mut buffer = [0u8; 1024];
async_readable.read(&mut buffer).unwrap();
}