Skip to content

Commit 798747e

Browse files
committed
Tests for unsound Windows file methods
1 parent 6ce408c commit 798747e

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

std/src/sys/windows/handle.rs

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

3+
#[cfg(test)]
4+
mod tests;
5+
36
use crate::cmp;
47
use crate::io::{self, ErrorKind, IoSlice, IoSliceMut, Read, ReadBuf};
58
use crate::mem;

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

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use crate::sys::pipe::{anon_pipe, Pipes};
2+
use crate::{thread, time};
3+
4+
/// Test the synchronous fallback for overlapped I/O.
5+
#[test]
6+
fn overlapped_handle_fallback() {
7+
// Create some pipes. `ours` will be asynchronous.
8+
let Pipes { ours, theirs } = anon_pipe(true, false).unwrap();
9+
10+
let async_readable = ours.into_handle();
11+
let sync_writeable = theirs.into_handle();
12+
13+
thread::scope(|_| {
14+
thread::sleep(time::Duration::from_millis(100));
15+
sync_writeable.write(b"hello world!").unwrap();
16+
});
17+
18+
// The pipe buffer starts empty so reading won't complete synchronously unless
19+
// our fallback path works.
20+
let mut buffer = [0u8; 1024];
21+
async_readable.read(&mut buffer).unwrap();
22+
}

0 commit comments

Comments
 (0)