aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJeff Vander Stoep <jeffv@google.com>2021-11-16 11:16:30 +0100
committerJeff Vander Stoep <jeffv@google.com>2021-11-16 11:17:30 +0100
commit1db412d2c35d13b9d4b8ab28ca56de5b77abff71 (patch)
treea86a1094890ceb522b599e1f37f24c2e16239fd3 /tests
parente16ac718df3b8af3bef9bc0c1b6c9bfb5f8e71e1 (diff)
downloadtokio-1db412d2c35d13b9d4b8ab28ca56de5b77abff71.tar.gz
Update to 1.14.0
Test: atest Change-Id: I713529f5ba957c212f50bde27b4428612dbcdefd
Diffstat (limited to 'tests')
-rw-r--r--tests/macros_select.rs26
-rw-r--r--tests/macros_test.rs16
-rw-r--r--tests/rt_basic.rs35
-rw-r--r--tests/rt_threaded.rs25
-rw-r--r--tests/udp.rs44
-rw-r--r--tests/uds_datagram.rs47
6 files changed, 192 insertions, 1 deletions
diff --git a/tests/macros_select.rs b/tests/macros_select.rs
index 4da88fb..b4f8544 100644
--- a/tests/macros_select.rs
+++ b/tests/macros_select.rs
@@ -558,3 +558,29 @@ pub async fn default_numeric_fallback() {
else => (),
}
}
+
+// https://github.com/tokio-rs/tokio/issues/4182
+#[tokio::test]
+async fn mut_ref_patterns() {
+ tokio::select! {
+ Some(mut foo) = async { Some("1".to_string()) } => {
+ assert_eq!(foo, "1");
+ foo = "2".to_string();
+ assert_eq!(foo, "2");
+ },
+ };
+
+ tokio::select! {
+ Some(ref foo) = async { Some("1".to_string()) } => {
+ assert_eq!(*foo, "1");
+ },
+ };
+
+ tokio::select! {
+ Some(ref mut foo) = async { Some("1".to_string()) } => {
+ assert_eq!(*foo, "1");
+ *foo = "2".to_string();
+ assert_eq!(*foo, "2");
+ },
+ };
+}
diff --git a/tests/macros_test.rs b/tests/macros_test.rs
index 7212c7b..bca2c91 100644
--- a/tests/macros_test.rs
+++ b/tests/macros_test.rs
@@ -30,3 +30,19 @@ fn trait_method() {
}
().f()
}
+
+// https://github.com/tokio-rs/tokio/issues/4175
+#[tokio::main]
+pub async fn issue_4175_main_1() -> ! {
+ panic!();
+}
+#[tokio::main]
+pub async fn issue_4175_main_2() -> std::io::Result<()> {
+ panic!();
+}
+#[allow(unreachable_code)]
+#[tokio::test]
+pub async fn issue_4175_test() -> std::io::Result<()> {
+ return Ok(());
+ panic!();
+}
diff --git a/tests/rt_basic.rs b/tests/rt_basic.rs
index 4b1bdad..70056b1 100644
--- a/tests/rt_basic.rs
+++ b/tests/rt_basic.rs
@@ -3,10 +3,14 @@
use tokio::runtime::Runtime;
use tokio::sync::oneshot;
+use tokio::time::{timeout, Duration};
use tokio_test::{assert_err, assert_ok};
+use std::future::Future;
+use std::pin::Pin;
+use std::sync::atomic::{AtomicBool, Ordering};
+use std::task::{Context, Poll};
use std::thread;
-use tokio::time::{timeout, Duration};
mod support {
pub(crate) mod mpsc_stream;
@@ -136,6 +140,35 @@ fn acquire_mutex_in_drop() {
}
#[test]
+fn drop_tasks_in_context() {
+ static SUCCESS: AtomicBool = AtomicBool::new(false);
+
+ struct ContextOnDrop;
+
+ impl Future for ContextOnDrop {
+ type Output = ();
+
+ fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<()> {
+ Poll::Pending
+ }
+ }
+
+ impl Drop for ContextOnDrop {
+ fn drop(&mut self) {
+ if tokio::runtime::Handle::try_current().is_ok() {
+ SUCCESS.store(true, Ordering::SeqCst);
+ }
+ }
+ }
+
+ let rt = rt();
+ rt.spawn(ContextOnDrop);
+ drop(rt);
+
+ assert!(SUCCESS.load(Ordering::SeqCst));
+}
+
+#[test]
#[should_panic(
expected = "A Tokio 1.x context was found, but timers are disabled. Call `enable_time` on the runtime builder to enable timers."
)]
diff --git a/tests/rt_threaded.rs b/tests/rt_threaded.rs
index 9e76c4e..5f047a7 100644
--- a/tests/rt_threaded.rs
+++ b/tests/rt_threaded.rs
@@ -54,6 +54,7 @@ fn many_oneshot_futures() {
drop(rt);
}
}
+
#[test]
fn many_multishot_futures() {
const CHAIN: usize = 200;
@@ -473,6 +474,30 @@ fn wake_during_shutdown() {
rt.block_on(async { tokio::time::sleep(tokio::time::Duration::from_millis(20)).await });
}
+#[should_panic]
+#[tokio::test]
+async fn test_block_in_place1() {
+ tokio::task::block_in_place(|| {});
+}
+
+#[tokio::test(flavor = "multi_thread")]
+async fn test_block_in_place2() {
+ tokio::task::block_in_place(|| {});
+}
+
+#[should_panic]
+#[tokio::main(flavor = "current_thread")]
+#[test]
+async fn test_block_in_place3() {
+ tokio::task::block_in_place(|| {});
+}
+
+#[tokio::main]
+#[test]
+async fn test_block_in_place4() {
+ tokio::task::block_in_place(|| {});
+}
+
fn rt() -> Runtime {
Runtime::new().unwrap()
}
diff --git a/tests/udp.rs b/tests/udp.rs
index 715d8eb..ec2a1e9 100644
--- a/tests/udp.rs
+++ b/tests/udp.rs
@@ -5,6 +5,7 @@ use futures::future::poll_fn;
use std::io;
use std::sync::Arc;
use tokio::{io::ReadBuf, net::UdpSocket};
+use tokio_test::assert_ok;
const MSG: &[u8] = b"hello";
const MSG_LEN: usize = MSG.len();
@@ -440,3 +441,46 @@ async fn try_recv_buf_from() {
}
}
}
+
+#[tokio::test]
+async fn poll_ready() {
+ // Create listener
+ let server = UdpSocket::bind("127.0.0.1:0").await.unwrap();
+ let saddr = server.local_addr().unwrap();
+
+ // Create socket pair
+ let client = UdpSocket::bind("127.0.0.1:0").await.unwrap();
+ let caddr = client.local_addr().unwrap();
+
+ for _ in 0..5 {
+ loop {
+ assert_ok!(poll_fn(|cx| client.poll_send_ready(cx)).await);
+
+ match client.try_send_to(b"hello world", saddr) {
+ Ok(n) => {
+ assert_eq!(n, 11);
+ break;
+ }
+ Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => continue,
+ Err(e) => panic!("{:?}", e),
+ }
+ }
+
+ loop {
+ assert_ok!(poll_fn(|cx| server.poll_recv_ready(cx)).await);
+
+ let mut buf = Vec::with_capacity(512);
+
+ match server.try_recv_buf_from(&mut buf) {
+ Ok((n, addr)) => {
+ assert_eq!(n, 11);
+ assert_eq!(addr, caddr);
+ assert_eq!(&buf[0..11], &b"hello world"[..]);
+ break;
+ }
+ Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => continue,
+ Err(e) => panic!("{:?}", e),
+ }
+ }
+ }
+}
diff --git a/tests/uds_datagram.rs b/tests/uds_datagram.rs
index 4d28468..5e5486b 100644
--- a/tests/uds_datagram.rs
+++ b/tests/uds_datagram.rs
@@ -328,3 +328,50 @@ async fn try_recv_buf_never_block() -> io::Result<()> {
Ok(())
}
+
+#[tokio::test]
+async fn poll_ready() -> io::Result<()> {
+ let dir = tempfile::tempdir().unwrap();
+ let server_path = dir.path().join("server.sock");
+ let client_path = dir.path().join("client.sock");
+
+ // Create listener
+ let server = UnixDatagram::bind(&server_path)?;
+
+ // Create socket pair
+ let client = UnixDatagram::bind(&client_path)?;
+
+ for _ in 0..5 {
+ loop {
+ poll_fn(|cx| client.poll_send_ready(cx)).await?;
+
+ match client.try_send_to(b"hello world", &server_path) {
+ Ok(n) => {
+ assert_eq!(n, 11);
+ break;
+ }
+ Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => continue,
+ Err(e) => panic!("{:?}", e),
+ }
+ }
+
+ loop {
+ poll_fn(|cx| server.poll_recv_ready(cx)).await?;
+
+ let mut buf = Vec::with_capacity(512);
+
+ match server.try_recv_buf_from(&mut buf) {
+ Ok((n, addr)) => {
+ assert_eq!(n, 11);
+ assert_eq!(addr.as_pathname(), Some(client_path.as_ref()));
+ assert_eq!(&buf[0..11], &b"hello world"[..]);
+ break;
+ }
+ Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => continue,
+ Err(e) => panic!("{:?}", e),
+ }
+ }
+ }
+
+ Ok(())
+}