about summary refs log tree commit diff
path: root/library/std/src/sys/windows
diff options
context:
space:
mode:
authorChris Denton <christophersdenton@gmail.com>2022-07-06 16:39:06 +0100
committerChris Denton <christophersdenton@gmail.com>2022-07-06 17:40:21 +0100
commita8ffc7fd45592fd423d44852383efb3c6c1a7264 (patch)
tree2c8eb8b1fc6740aae59310ea6aabb9348293575d /library/std/src/sys/windows
parent3ae47e76a84baaa4d35f641c237649944fa8fb58 (diff)
downloadrust-a8ffc7fd45592fd423d44852383efb3c6c1a7264.tar.gz
rust-a8ffc7fd45592fd423d44852383efb3c6c1a7264.zip
Tests for unsound Windows file methods
Diffstat (limited to 'library/std/src/sys/windows')
-rw-r--r--library/std/src/sys/windows/handle.rs3
-rw-r--r--library/std/src/sys/windows/handle/tests.rs22
2 files changed, 25 insertions, 0 deletions
diff --git a/library/std/src/sys/windows/handle.rs b/library/std/src/sys/windows/handle.rs
index 6dd022b0806..e24b09cc96e 100644
--- a/library/std/src/sys/windows/handle.rs
+++ b/library/std/src/sys/windows/handle.rs
@@ -1,5 +1,8 @@
 #![unstable(issue = "none", feature = "windows_handle")]
 
+#[cfg(test)]
+mod tests;
+
 use crate::cmp;
 use crate::io::{self, ErrorKind, IoSlice, IoSliceMut, Read, ReadBuf};
 use crate::mem;
diff --git a/library/std/src/sys/windows/handle/tests.rs b/library/std/src/sys/windows/handle/tests.rs
new file mode 100644
index 00000000000..d836dae4c30
--- /dev/null
+++ b/library/std/src/sys/windows/handle/tests.rs
@@ -0,0 +1,22 @@
+use crate::sys::pipe::{anon_pipe, Pipes};
+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();
+}