From 1376c5a617be5c25655d0d7cb63e3beaa5a6e026 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:20:39 +0200 Subject: Merging upstream version 1.70.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/futures-channel/tests/mpsc-close.rs | 1 + vendor/futures-channel/tests/mpsc-size_hint.rs | 40 ++++++++++++++++++++++++++ vendor/futures-channel/tests/mpsc.rs | 18 +++++++----- vendor/futures-channel/tests/oneshot.rs | 8 ++++-- 4 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 vendor/futures-channel/tests/mpsc-size_hint.rs (limited to 'vendor/futures-channel/tests') diff --git a/vendor/futures-channel/tests/mpsc-close.rs b/vendor/futures-channel/tests/mpsc-close.rs index 81203d334..1a14067ec 100644 --- a/vendor/futures-channel/tests/mpsc-close.rs +++ b/vendor/futures-channel/tests/mpsc-close.rs @@ -147,6 +147,7 @@ fn single_receiver_drop_closes_channel_and_drains() { // Stress test that `try_send()`s occurring concurrently with receiver // close/drops don't appear as successful sends. +#[cfg_attr(miri, ignore)] // Miri is too slow #[test] fn stress_try_send_as_receiver_closes() { const AMT: usize = 10000; diff --git a/vendor/futures-channel/tests/mpsc-size_hint.rs b/vendor/futures-channel/tests/mpsc-size_hint.rs new file mode 100644 index 000000000..d9cdaa31f --- /dev/null +++ b/vendor/futures-channel/tests/mpsc-size_hint.rs @@ -0,0 +1,40 @@ +use futures::channel::mpsc; +use futures::stream::Stream; + +#[test] +fn unbounded_size_hint() { + let (tx, mut rx) = mpsc::unbounded::(); + assert_eq!((0, None), rx.size_hint()); + tx.unbounded_send(1).unwrap(); + assert_eq!((1, None), rx.size_hint()); + rx.try_next().unwrap().unwrap(); + assert_eq!((0, None), rx.size_hint()); + tx.unbounded_send(2).unwrap(); + tx.unbounded_send(3).unwrap(); + assert_eq!((2, None), rx.size_hint()); + drop(tx); + assert_eq!((2, Some(2)), rx.size_hint()); + rx.try_next().unwrap().unwrap(); + assert_eq!((1, Some(1)), rx.size_hint()); + rx.try_next().unwrap().unwrap(); + assert_eq!((0, Some(0)), rx.size_hint()); +} + +#[test] +fn channel_size_hint() { + let (mut tx, mut rx) = mpsc::channel::(10); + assert_eq!((0, None), rx.size_hint()); + tx.try_send(1).unwrap(); + assert_eq!((1, None), rx.size_hint()); + rx.try_next().unwrap().unwrap(); + assert_eq!((0, None), rx.size_hint()); + tx.try_send(2).unwrap(); + tx.try_send(3).unwrap(); + assert_eq!((2, None), rx.size_hint()); + drop(tx); + assert_eq!((2, Some(2)), rx.size_hint()); + rx.try_next().unwrap().unwrap(); + assert_eq!((1, Some(1)), rx.size_hint()); + rx.try_next().unwrap().unwrap(); + assert_eq!((0, Some(0)), rx.size_hint()); +} diff --git a/vendor/futures-channel/tests/mpsc.rs b/vendor/futures-channel/tests/mpsc.rs index 88cdef13d..444c8e10f 100644 --- a/vendor/futures-channel/tests/mpsc.rs +++ b/vendor/futures-channel/tests/mpsc.rs @@ -200,7 +200,7 @@ fn tx_close_gets_none() { #[test] fn stress_shared_unbounded() { - const AMT: u32 = 10000; + const AMT: u32 = if cfg!(miri) { 100 } else { 10000 }; const NTHREADS: u32 = 8; let (tx, rx) = mpsc::unbounded::(); @@ -229,7 +229,7 @@ fn stress_shared_unbounded() { #[test] fn stress_shared_bounded_hard() { - const AMT: u32 = 10000; + const AMT: u32 = if cfg!(miri) { 100 } else { 10000 }; const NTHREADS: u32 = 8; let (tx, rx) = mpsc::channel::(0); @@ -259,7 +259,7 @@ fn stress_shared_bounded_hard() { #[allow(clippy::same_item_push)] #[test] fn stress_receiver_multi_task_bounded_hard() { - const AMT: usize = 10_000; + const AMT: usize = if cfg!(miri) { 100 } else { 10_000 }; const NTHREADS: u32 = 2; let (mut tx, rx) = mpsc::channel::(0); @@ -327,6 +327,8 @@ fn stress_receiver_multi_task_bounded_hard() { /// after sender dropped. #[test] fn stress_drop_sender() { + const ITER: usize = if cfg!(miri) { 100 } else { 10000 }; + fn list() -> impl Stream { let (tx, rx) = mpsc::channel(1); thread::spawn(move || { @@ -335,7 +337,7 @@ fn stress_drop_sender() { rx } - for _ in 0..10000 { + for _ in 0..ITER { let v: Vec<_> = block_on(list().collect()); assert_eq!(v, vec![1, 2, 3]); } @@ -382,7 +384,9 @@ fn stress_close_receiver_iter() { #[test] fn stress_close_receiver() { - for _ in 0..10000 { + const ITER: usize = if cfg!(miri) { 50 } else { 10000 }; + + for _ in 0..ITER { stress_close_receiver_iter(); } } @@ -397,7 +401,7 @@ async fn stress_poll_ready_sender(mut sender: mpsc::Sender, count: u32) { #[allow(clippy::same_item_push)] #[test] fn stress_poll_ready() { - const AMT: u32 = 1000; + const AMT: u32 = if cfg!(miri) { 100 } else { 1000 }; const NTHREADS: u32 = 8; /// Run a stress test using the specified channel capacity. @@ -426,7 +430,7 @@ fn stress_poll_ready() { #[test] fn try_send_1() { - const N: usize = 3000; + const N: usize = if cfg!(miri) { 100 } else { 3000 }; let (mut tx, rx) = mpsc::channel(0); let t = thread::spawn(move || { diff --git a/vendor/futures-channel/tests/oneshot.rs b/vendor/futures-channel/tests/oneshot.rs index 979cd8a15..6b48376dc 100644 --- a/vendor/futures-channel/tests/oneshot.rs +++ b/vendor/futures-channel/tests/oneshot.rs @@ -35,6 +35,8 @@ fn cancel_notifies() { #[test] fn cancel_lots() { + const N: usize = if cfg!(miri) { 100 } else { 20000 }; + let (tx, rx) = mpsc::channel::<(Sender<_>, mpsc::Sender<_>)>(); let t = thread::spawn(move || { for (mut tx, tx2) in rx { @@ -43,7 +45,7 @@ fn cancel_lots() { } }); - for _ in 0..20000 { + for _ in 0..N { let (otx, orx) = oneshot::channel::(); let (tx2, rx2) = mpsc::channel(); tx.send((otx, tx2)).unwrap(); @@ -101,6 +103,8 @@ fn is_canceled() { #[test] fn cancel_sends() { + const N: usize = if cfg!(miri) { 100 } else { 20000 }; + let (tx, rx) = mpsc::channel::>(); let t = thread::spawn(move || { for otx in rx { @@ -108,7 +112,7 @@ fn cancel_sends() { } }); - for _ in 0..20000 { + for _ in 0..N { let (otx, mut orx) = oneshot::channel::(); tx.send(otx).unwrap(); -- cgit v1.2.3