about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-03-09 06:23:18 +0000
committerbors <bors@rust-lang.org>2024-03-09 06:23:18 +0000
commit48a15aa2c496db70e14db62d6a477b23fc316e3c (patch)
treebf583b6e43a14d5d0fc1d61ba156cc4b3335b72d
parent1b427b3bf79c2cd48c75915301be3b009b82dea3 (diff)
parent9abe47e3720d8fc236464a9295389fc0b21f67e5 (diff)
downloadrust-48a15aa2c496db70e14db62d6a477b23fc316e3c.tar.gz
rust-48a15aa2c496db70e14db62d6a477b23fc316e3c.zip
Auto merge of #122095 - lukas-code:windows-shutdown-test, r=ChrisDenton
fix `close_read_wakes_up` test

On windows, `shutdown` does not interrupt `read`, even though we document that it does (see https://github.com/rust-lang/rust/issues/121594).

The `close_read_wakes_up` test has a race condition and only passes on windows if the `shutdown` happens before the `read`. This PR ignores the test on windows adds a sleep to make it more likely that the `read` happens before the `shutdown` and the test actually tests what it is supposed to test on other platforms.

I'm submitting this before any docs changes, so that we can find out on what platforms `shutdown` actually works as documented.

r? `@ChrisDenton`
-rw-r--r--library/std/src/net/tcp/tests.rs33
1 files changed, 18 insertions, 15 deletions
diff --git a/library/std/src/net/tcp/tests.rs b/library/std/src/net/tcp/tests.rs
index b24b851a645..ec8b62f9687 100644
--- a/library/std/src/net/tcp/tests.rs
+++ b/library/std/src/net/tcp/tests.rs
@@ -544,30 +544,33 @@ fn close_readwrite_smoke() {
 }
 
 #[test]
+// FIXME: https://github.com/fortanix/rust-sgx/issues/110
 #[cfg_attr(target_env = "sgx", ignore)]
+// On windows, shutdown will not wake up blocking I/O operations.
+#[cfg_attr(windows, ignore)]
 fn close_read_wakes_up() {
     each_ip(&mut |addr| {
-        let a = t!(TcpListener::bind(&addr));
-        let (tx1, rx) = channel::<()>();
+        let listener = t!(TcpListener::bind(&addr));
         let _t = thread::spawn(move || {
-            let _s = t!(a.accept());
-            let _ = rx.recv();
+            let (stream, _) = t!(listener.accept());
+            stream
         });
 
-        let s = t!(TcpStream::connect(&addr));
-        let s2 = t!(s.try_clone());
-        let (tx, rx) = channel();
+        let mut stream = t!(TcpStream::connect(&addr));
+        let stream2 = t!(stream.try_clone());
+
         let _t = thread::spawn(move || {
-            let mut s2 = s2;
-            assert_eq!(t!(s2.read(&mut [0])), 0);
-            tx.send(()).unwrap();
+            let stream2 = stream2;
+
+            // to make it more likely that `read` happens before `shutdown`
+            thread::sleep(Duration::from_millis(1000));
+
+            // this should wake up the reader up
+            t!(stream2.shutdown(Shutdown::Read));
         });
-        // this should wake up the child thread
-        t!(s.shutdown(Shutdown::Read));
 
-        // this test will never finish if the child doesn't wake up
-        rx.recv().unwrap();
-        drop(tx1);
+        // this `read` should get interrupted by `shutdown`
+        assert_eq!(t!(stream.read(&mut [0])), 0);
     })
 }