From e574356f82fca049cff920e64e7ef0d463be3730 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Wed, 3 Jan 2024 22:23:24 +0800 Subject: [PATCH] io: add a cooperative case for copy_bidirectional Signed-off-by: hi-rustin --- tokio/tests/io_copy_bidirectional.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tokio/tests/io_copy_bidirectional.rs b/tokio/tests/io_copy_bidirectional.rs index 10eba3166ac..3cdce32d0ce 100644 --- a/tokio/tests/io_copy_bidirectional.rs +++ b/tokio/tests/io_copy_bidirectional.rs @@ -138,3 +138,28 @@ async fn immediate_exit_on_read_error() { assert!(copy_bidirectional(&mut a, &mut b).await.is_err()); } + +#[tokio::test] +async fn copy_bidirectional_is_cooperative() { + tokio::select! { + biased; + _ = async { + loop { + let payload = b"here, take this"; + + let mut a = tokio_test::io::Builder::new() + .read(payload) + .write(payload) + .build(); + + let mut b = tokio_test::io::Builder::new() + .read(payload) + .write(payload) + .build(); + + let _ = copy_bidirectional(&mut a, &mut b).await; + } + } => {}, + _ = tokio::task::yield_now() => {} + } +}