summaryrefslogtreecommitdiffstats
path: root/vendor/tokio/tests/tcp_stream.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
commitdc0db358abe19481e475e10c32149b53370f1a1c (patch)
treeab8ce99c4b255ce46f99ef402c27916055b899ee /vendor/tokio/tests/tcp_stream.rs
parentReleasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff)
downloadrustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz
rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/tokio/tests/tcp_stream.rs')
-rw-r--r--vendor/tokio/tests/tcp_stream.rs51
1 files changed, 46 insertions, 5 deletions
diff --git a/vendor/tokio/tests/tcp_stream.rs b/vendor/tokio/tests/tcp_stream.rs
index 0b5d12ae8..31fe3baa2 100644
--- a/vendor/tokio/tests/tcp_stream.rs
+++ b/vendor/tokio/tests/tcp_stream.rs
@@ -1,5 +1,5 @@
#![warn(rust_2018_idioms)]
-#![cfg(feature = "full")]
+#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi doesn't support bind
use tokio::io::{AsyncReadExt, AsyncWriteExt, Interest};
use tokio::net::{TcpListener, TcpStream};
@@ -254,30 +254,34 @@ async fn create_pair() -> (TcpStream, TcpStream) {
(client, server)
}
-fn read_until_pending(stream: &mut TcpStream) {
+fn read_until_pending(stream: &mut TcpStream) -> usize {
let mut buf = vec![0u8; 1024 * 1024];
+ let mut total = 0;
loop {
match stream.try_read(&mut buf) {
- Ok(_) => (),
+ Ok(n) => total += n,
Err(err) => {
assert_eq!(err.kind(), io::ErrorKind::WouldBlock);
break;
}
}
}
+ total
}
-fn write_until_pending(stream: &mut TcpStream) {
+fn write_until_pending(stream: &mut TcpStream) -> usize {
let buf = vec![0u8; 1024 * 1024];
+ let mut total = 0;
loop {
match stream.try_write(&buf) {
- Ok(_) => (),
+ Ok(n) => total += n,
Err(err) => {
assert_eq!(err.kind(), io::ErrorKind::WouldBlock);
break;
}
}
}
+ total
}
#[tokio::test]
@@ -357,3 +361,40 @@ async fn try_read_buf() {
}
}
}
+
+// read_closed is a best effort event, so test only for no false positives.
+#[tokio::test]
+async fn read_closed() {
+ let (client, mut server) = create_pair().await;
+
+ let mut ready_fut = task::spawn(client.ready(Interest::READABLE));
+ assert_pending!(ready_fut.poll());
+
+ assert_ok!(server.write_all(b"ping").await);
+
+ let ready_event = assert_ok!(ready_fut.await);
+
+ assert!(!ready_event.is_read_closed());
+}
+
+// write_closed is a best effort event, so test only for no false positives.
+#[tokio::test]
+async fn write_closed() {
+ let (mut client, mut server) = create_pair().await;
+
+ // Fill the write buffer.
+ let write_size = write_until_pending(&mut client);
+ let mut ready_fut = task::spawn(client.ready(Interest::WRITABLE));
+ assert_pending!(ready_fut.poll());
+
+ // Drain the socket to make client writable.
+ let mut read_size = 0;
+ while read_size < write_size {
+ server.readable().await.unwrap();
+ read_size += read_until_pending(&mut server);
+ }
+
+ let ready_event = assert_ok!(ready_fut.await);
+
+ assert!(!ready_event.is_write_closed());
+}