Skip to content

Commit 48a15aa

Browse files
committed
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 #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`
2 parents 1b427b3 + 9abe47e commit 48a15aa

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

library/std/src/net/tcp/tests.rs

+18-15
Original file line numberDiff line numberDiff line change
@@ -544,30 +544,33 @@ fn close_readwrite_smoke() {
544544
}
545545

546546
#[test]
547+
// FIXME: https://github.com/fortanix/rust-sgx/issues/110
547548
#[cfg_attr(target_env = "sgx", ignore)]
549+
// On windows, shutdown will not wake up blocking I/O operations.
550+
#[cfg_attr(windows, ignore)]
548551
fn close_read_wakes_up() {
549552
each_ip(&mut |addr| {
550-
let a = t!(TcpListener::bind(&addr));
551-
let (tx1, rx) = channel::<()>();
553+
let listener = t!(TcpListener::bind(&addr));
552554
let _t = thread::spawn(move || {
553-
let _s = t!(a.accept());
554-
let _ = rx.recv();
555+
let (stream, _) = t!(listener.accept());
556+
stream
555557
});
556558

557-
let s = t!(TcpStream::connect(&addr));
558-
let s2 = t!(s.try_clone());
559-
let (tx, rx) = channel();
559+
let mut stream = t!(TcpStream::connect(&addr));
560+
let stream2 = t!(stream.try_clone());
561+
560562
let _t = thread::spawn(move || {
561-
let mut s2 = s2;
562-
assert_eq!(t!(s2.read(&mut [0])), 0);
563-
tx.send(()).unwrap();
563+
let stream2 = stream2;
564+
565+
// to make it more likely that `read` happens before `shutdown`
566+
thread::sleep(Duration::from_millis(1000));
567+
568+
// this should wake up the reader up
569+
t!(stream2.shutdown(Shutdown::Read));
564570
});
565-
// this should wake up the child thread
566-
t!(s.shutdown(Shutdown::Read));
567571

568-
// this test will never finish if the child doesn't wake up
569-
rx.recv().unwrap();
570-
drop(tx1);
572+
// this `read` should get interrupted by `shutdown`
573+
assert_eq!(t!(stream.read(&mut [0])), 0);
571574
})
572575
}
573576

0 commit comments

Comments
 (0)