id stringlengths 22 133 | text stringlengths 40 40.2k | arch stringclasses 1
value | syntax stringclasses 1
value | kind stringclasses 4
values | repo stringclasses 27
values | path stringlengths 5 116 | license stringclasses 6
values | commit stringlengths 40 40 | source_host stringclasses 1
value | category stringclasses 16
values | source_url stringlengths 85 196 | line_start int64 1 4.28k | line_end int64 4 4.31k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:1 | #![allow(clippy::redundant_clone)]
#![warn(rust_2018_idioms)]
#![cfg(feature = "sync")]
#[cfg(tokio_wasm_not_wasi)]
use wasm_bindgen_test::wasm_bindgen_test as test;
#[cfg(tokio_wasm_not_wasi)]
use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test;
#[cfg(not(tokio_wasm_not_wasi))]
use tokio::test as maybe_toki... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b3c7c9846b414b217ec97522194c170dd1ba4add | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b3c7c9846b414b217ec97522194c170dd1ba4add/tokio/tests/sync_mpsc.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:2 | tx.try_send(2).unwrap();
drop(tx);
let val = rx.recv().await;
assert_eq!(val, Some(1));
let val = rx.recv().await;
assert_eq!(val, Some(2));
let val = rx.recv().await;
assert!(val.is_none());
}
#[tokio::test]
#[cfg(feature = "full")]
async fn reserve_disarm() {
let (tx, mut rx) = mp... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b3c7c9846b414b217ec97522194c170dd1ba4add | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b3c7c9846b414b217ec97522194c170dd1ba4add/tokio/tests/sync_mpsc.rs | 41 | 100 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:3 | // Now there's a free slot!
assert!(r3.is_woken());
assert!(!r4.is_woken());
// Dropping a permit should also open up a slot
drop(permit2);
assert!(r4.is_woken());
let mut r1 = tokio_test::task::spawn(tx1.reserve());
assert_pending!(r1.poll());
}
#[tokio::test]
#[cfg(all(feature = "full",... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b3c7c9846b414b217ec97522194c170dd1ba4add | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b3c7c9846b414b217ec97522194c170dd1ba4add/tokio/tests/sync_mpsc.rs | 81 | 140 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:4 | assert_eq!(Some(1), rx.recv().await);
assert_eq!(Some(2), rx.recv().await);
assert_eq!(None, rx.recv().await);
}
#[tokio::test]
#[cfg(feature = "full")]
async fn start_send_past_cap() {
use std::future::Future;
let mut t1 = tokio_test::task::spawn(());
let (tx1, mut rx) = mpsc::channel(1);
le... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b3c7c9846b414b217ec97522194c170dd1ba4add | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b3c7c9846b414b217ec97522194c170dd1ba4add/tokio/tests/sync_mpsc.rs | 121 | 180 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:5 | #[cfg(not(tokio_wasm))] // wasm currently doesn't support unwinding
fn buffer_gteq_one() {
mpsc::channel::<i32>(0);
}
#[maybe_tokio_test]
async fn send_recv_unbounded() {
let (tx, mut rx) = mpsc::unbounded_channel::<i32>();
// Using `try_send`
assert_ok!(tx.send(1));
assert_ok!(tx.send(2));
a... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b3c7c9846b414b217ec97522194c170dd1ba4add | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b3c7c9846b414b217ec97522194c170dd1ba4add/tokio/tests/sync_mpsc.rs | 161 | 220 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:6 | let (tx, rx) = support::mpsc_stream::unbounded_channel_stream::<i32>();
let mut rx = Box::pin(rx);
tokio::spawn(async move {
assert_ok!(tx.send(1));
assert_ok!(tx.send(2));
});
assert_eq!(Some(1), rx.next().await);
assert_eq!(Some(2), rx.next().await);
assert_eq!(None, rx.next... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b3c7c9846b414b217ec97522194c170dd1ba4add | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b3c7c9846b414b217ec97522194c170dd1ba4add/tokio/tests/sync_mpsc.rs | 201 | 260 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:7 | println!("{:?}", rx);
// and sender should be Clone even though T isn't Clone
assert!(tx.clone().send(NoImpls).is_ok());
assert!(rx.recv().await.is_some());
}
#[tokio::test]
#[cfg(feature = "full")]
async fn send_recv_buffer_limited() {
let (tx, mut rx) = mpsc::channel::<i32>(1);
// Reserve capac... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b3c7c9846b414b217ec97522194c170dd1ba4add | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b3c7c9846b414b217ec97522194c170dd1ba4add/tokio/tests/sync_mpsc.rs | 241 | 300 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:8 | let (tx, mut rx) = mpsc::channel::<i32>(10);
rx.close();
assert!(rx.recv().await.is_none());
assert_err!(tx.send(1).await);
}
#[tokio::test]
#[cfg(feature = "full")]
async fn recv_close_gets_none_reserved() {
let (tx1, mut rx) = mpsc::channel::<i32>(1);
let tx2 = tx1.clone();
let permit1 = ... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b3c7c9846b414b217ec97522194c170dd1ba4add | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b3c7c9846b414b217ec97522194c170dd1ba4add/tokio/tests/sync_mpsc.rs | 281 | 340 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:9 | let (_, mut rx) = mpsc::channel::<i32>(10);
assert!(rx.recv().await.is_none());
}
#[maybe_tokio_test]
async fn try_send_fail() {
let (tx, mut rx) = mpsc::channel(1);
tx.try_send("hello").unwrap();
// This should fail
match assert_err!(tx.try_send("fail")) {
TrySendError::Full(..) => {}
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b3c7c9846b414b217ec97522194c170dd1ba4add | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b3c7c9846b414b217ec97522194c170dd1ba4add/tokio/tests/sync_mpsc.rs | 321 | 380 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:10 | drop(tx);
assert_eq!(rx.try_recv(), Ok("goodbye"));
assert_eq!(rx.try_recv(), Err(TryRecvError::Disconnected));
}
#[maybe_tokio_test]
async fn try_reserve_fails() {
let (tx, mut rx) = mpsc::channel(1);
let permit = tx.try_reserve().unwrap();
// This should fail
match assert_err!(tx.try_reser... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b3c7c9846b414b217ec97522194c170dd1ba4add | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b3c7c9846b414b217ec97522194c170dd1ba4add/tokio/tests/sync_mpsc.rs | 361 | 420 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:11 | assert_pending!(reserve2.poll());
drop(permit);
assert!(reserve2.is_woken());
assert_ready_ok!(reserve2.poll());
}
#[maybe_tokio_test]
async fn dropping_rx_closes_channel() {
let (tx, rx) = mpsc::channel(100);
let msg = Arc::new(());
assert_ok!(tx.try_send(msg.clone()));
drop(rx);
a... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b3c7c9846b414b217ec97522194c170dd1ba4add | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b3c7c9846b414b217ec97522194c170dd1ba4add/tokio/tests/sync_mpsc.rs | 401 | 460 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:12 | }
#[test]
fn unconsumed_messages_are_dropped() {
let msg = Arc::new(());
let (tx, rx) = mpsc::channel(100);
tx.try_send(msg.clone()).unwrap();
assert_eq!(2, Arc::strong_count(&msg));
drop((tx, rx));
assert_eq!(1, Arc::strong_count(&msg));
}
#[test]
#[cfg(all(feature = "full", not(tokio_wa... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b3c7c9846b414b217ec97522194c170dd1ba4add | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b3c7c9846b414b217ec97522194c170dd1ba4add/tokio/tests/sync_mpsc.rs | 441 | 500 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:13 | }
#[test]
#[cfg(all(feature = "full", not(tokio_wasi)))] // Wasi doesn't support threads
fn blocking_send() {
let (tx, mut rx) = mpsc::channel::<u8>(1);
let sync_code = std::thread::spawn(move || {
tx.blocking_send(10).unwrap();
});
tokio::runtime::Runtime::new()
.unwrap()
.bl... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b3c7c9846b414b217ec97522194c170dd1ba4add | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b3c7c9846b414b217ec97522194c170dd1ba4add/tokio/tests/sync_mpsc.rs | 481 | 540 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:15 | assert_eq!(Ok("hello"), rx.try_recv());
assert_eq!(Ok("hello"), rx.try_recv());
assert_eq!(Ok("hello"), rx.try_recv());
assert_eq!(Err(TryRecvError::Empty), rx.try_recv());
tx.try_send("hello").unwrap();
tx.try_send("hello").unwrap();
tx.try_send("hello").unwrap();
tx.try_send("hello").unwr... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b3c7c9846b414b217ec97522194c170dd1ba4add | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b3c7c9846b414b217ec97522194c170dd1ba4add/tokio/tests/sync_mpsc.rs | 561 | 620 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:16 | assert_eq!(rx.try_recv(), Ok(i));
}
assert_eq!(rx.try_recv(), Err(TryRecvError::Empty));
drop(tx);
assert_eq!(rx.try_recv(), Err(TryRecvError::Disconnected));
}
}
#[test]
fn try_recv_close_while_empty_bounded() {
let (tx, mut rx) = mpsc::channel::<()>(5);
assert_eq!(Err(Tr... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b3c7c9846b414b217ec97522194c170dd1ba4add | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b3c7c9846b414b217ec97522194c170dd1ba4add/tokio/tests/sync_mpsc.rs | 601 | 660 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:17 | assert_eq!(
tx.send_timeout(60, Duration::from_secs(1)).await,
Err(Timeout(60))
);
drop(rx);
assert_eq!(
tx.send_timeout(70, Duration::from_secs(1)).await,
Err(Closed(70))
);
}
#[test]
#[should_panic = "there is no reactor running, must be called from the context of a T... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b3c7c9846b414b217ec97522194c170dd1ba4add | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b3c7c9846b414b217ec97522194c170dd1ba4add/tokio/tests/sync_mpsc.rs | 641 | 700 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:18 | let tx_weak = tx2.downgrade();
Some(tx_weak)
})
.await
.unwrap();
for i in 0..12 {
let recvd = rx.recv().await;
match recvd {
Some(msg) => {
if i == 10 {
assert_eq!(msg, 20);
}
}
None => {
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b3c7c9846b414b217ec97522194c170dd1ba4add | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b3c7c9846b414b217ec97522194c170dd1ba4add/tokio/tests/sync_mpsc.rs | 681 | 740 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:19 | }
impl MyActor {
fn new(
receiver: mpsc::Receiver<ActorMessage>,
sender: mpsc::WeakSender<ActorMessage>,
) -> Self {
MyActor {
receiver,
sender,
next_id: 0,
received_self_msg: false,
}
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b3c7c9846b414b217ec97522194c170dd1ba4add | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b3c7c9846b414b217ec97522194c170dd1ba4add/tokio/tests/sync_mpsc.rs | 721 | 780 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:20 | self.sender = sender.downgrade();
}
}
async fn run(&mut self) {
let mut i = 0;
while let Some(msg) = self.receiver.recv().await {
self.handle_message(msg);
if i == 0 {
self.send_message_to_self().await;
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b3c7c9846b414b217ec97522194c170dd1ba4add | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b3c7c9846b414b217ec97522194c170dd1ba4add/tokio/tests/sync_mpsc.rs | 761 | 820 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:21 | let _ = self.sender.send(msg).await;
recv.await.expect("Actor task has been killed")
}
}
let (handle, mut actor) = MyActorHandle::new();
let actor_handle = tokio::spawn(async move { actor.run().await });
let _ = tokio::spawn(async move {
let _ = handle.get_unique_id().awai... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b3c7c9846b414b217ec97522194c170dd1ba4add | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b3c7c9846b414b217ec97522194c170dd1ba4add/tokio/tests/sync_mpsc.rs | 801 | 860 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:22 | let _ = tx.send(Msg {}).await.unwrap();
let _ = tx.send(Msg {}).await.unwrap();
// This msg will be pending and should be dropped when `rx` is dropped
let sent_fut = tx.send(Msg {});
let _ = rx.recv().await.unwrap();
let _ = rx.recv().await.unwrap();
let _ = sent_fut.await.unwrap();
drop... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b3c7c9846b414b217ec97522194c170dd1ba4add | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b3c7c9846b414b217ec97522194c170dd1ba4add/tokio/tests/sync_mpsc.rs | 841 | 900 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:23 | // which existed at the time of the `downgrade` call.
#[tokio::test]
async fn downgrade_drop_upgrade() {
let (tx, _rx) = mpsc::channel::<i32>(1);
// the cloned `Tx` is dropped right away
let weak_tx = tx.clone().downgrade();
drop(tx);
assert!(weak_tx.upgrade().is_none());
}
// Tests that we can up... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b3c7c9846b414b217ec97522194c170dd1ba4add | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b3c7c9846b414b217ec97522194c170dd1ba4add/tokio/tests/sync_mpsc.rs | 881 | 940 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:24 | assert!(tx_weak.upgrade().is_none() && tx_weak2.upgrade().is_none());
}
// Tests that channel `capacity` changes and `max_capacity` stays the same
#[tokio::test]
async fn test_tx_capacity() {
let (tx, _rx) = mpsc::channel::<()>(10);
// both capacities are same before
assert_eq!(tx.capacity(), 10);
asse... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b3c7c9846b414b217ec97522194c170dd1ba4add | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b3c7c9846b414b217ec97522194c170dd1ba4add/tokio/tests/sync_mpsc.rs | 921 | 942 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:23 | // which existed at the time of the `downgrade` call.
#[tokio::test]
async fn downgrade_drop_upgrade() {
let (tx, _rx) = mpsc::channel::<i32>(1);
// the cloned `Tx` is dropped right away
let weak_tx = tx.clone().downgrade();
drop(tx);
assert!(weak_tx.upgrade().is_none());
}
// Tests that we can up... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | 1d75b57ad0f134f71a32cc42d1bd3e7a3e21a7f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1d75b57ad0f134f71a32cc42d1bd3e7a3e21a7f7/tokio/tests/sync_mpsc.rs | 881 | 923 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:1 | #![allow(clippy::redundant_clone)]
#![warn(rust_2018_idioms)]
#![cfg(feature = "sync")]
#[cfg(tokio_wasm_not_wasi)]
use wasm_bindgen_test::wasm_bindgen_test as test;
#[cfg(tokio_wasm_not_wasi)]
use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test;
#[cfg(not(tokio_wasm_not_wasi))]
use tokio::test as maybe_toki... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b2ada60e701d5c9e6644cf8fc42a100774f8e23f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b2ada60e701d5c9e6644cf8fc42a100774f8e23f/tokio/tests/sync_mpsc.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:2 | let val = rx.recv().await;
assert_eq!(val, Some(1));
let val = rx.recv().await;
assert_eq!(val, Some(2));
let val = rx.recv().await;
assert!(val.is_none());
}
#[tokio::test]
#[cfg(feature = "full")]
async fn reserve_disarm() {
let (tx, mut rx) = mpsc::channel::<i32>(2);
let tx1 = tx.clone... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b2ada60e701d5c9e6644cf8fc42a100774f8e23f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b2ada60e701d5c9e6644cf8fc42a100774f8e23f/tokio/tests/sync_mpsc.rs | 41 | 100 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:4 | }
#[tokio::test]
#[cfg(feature = "full")]
async fn start_send_past_cap() {
use std::future::Future;
let mut t1 = tokio_test::task::spawn(());
let (tx1, mut rx) = mpsc::channel(1);
let tx2 = tx1.clone();
assert_ok!(tx1.try_send(()));
let mut r1 = Box::pin(tx1.reserve());
t1.enter(|cx, _|... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b2ada60e701d5c9e6644cf8fc42a100774f8e23f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b2ada60e701d5c9e6644cf8fc42a100774f8e23f/tokio/tests/sync_mpsc.rs | 121 | 180 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:5 | }
#[maybe_tokio_test]
async fn send_recv_unbounded() {
let (tx, mut rx) = mpsc::unbounded_channel::<i32>();
// Using `try_send`
assert_ok!(tx.send(1));
assert_ok!(tx.send(2));
assert_eq!(rx.recv().await, Some(1));
assert_eq!(rx.recv().await, Some(2));
drop(tx);
assert!(rx.recv().awa... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b2ada60e701d5c9e6644cf8fc42a100774f8e23f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b2ada60e701d5c9e6644cf8fc42a100774f8e23f/tokio/tests/sync_mpsc.rs | 161 | 220 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:6 | let mut rx = Box::pin(rx);
tokio::spawn(async move {
assert_ok!(tx.send(1));
assert_ok!(tx.send(2));
});
assert_eq!(Some(1), rx.next().await);
assert_eq!(Some(2), rx.next().await);
assert_eq!(None, rx.next().await);
}
#[maybe_tokio_test]
async fn no_t_bounds_buffer() {
struct ... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b2ada60e701d5c9e6644cf8fc42a100774f8e23f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b2ada60e701d5c9e6644cf8fc42a100774f8e23f/tokio/tests/sync_mpsc.rs | 201 | 260 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:11 | assert!(reserve2.is_woken());
assert_ready_ok!(reserve2.poll());
}
#[maybe_tokio_test]
async fn dropping_rx_closes_channel() {
let (tx, rx) = mpsc::channel(100);
let msg = Arc::new(());
assert_ok!(tx.try_send(msg.clone()));
drop(rx);
assert_err!(tx.reserve().await);
assert_eq!(1, Arc::str... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b2ada60e701d5c9e6644cf8fc42a100774f8e23f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b2ada60e701d5c9e6644cf8fc42a100774f8e23f/tokio/tests/sync_mpsc.rs | 401 | 460 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:12 | fn unconsumed_messages_are_dropped() {
let msg = Arc::new(());
let (tx, rx) = mpsc::channel(100);
tx.try_send(msg.clone()).unwrap();
assert_eq!(2, Arc::strong_count(&msg));
drop((tx, rx));
assert_eq!(1, Arc::strong_count(&msg));
}
#[test]
#[cfg(all(feature = "full", not(tokio_wasi)))] // W... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b2ada60e701d5c9e6644cf8fc42a100774f8e23f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b2ada60e701d5c9e6644cf8fc42a100774f8e23f/tokio/tests/sync_mpsc.rs | 441 | 500 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:13 | #[cfg(all(feature = "full", not(tokio_wasi)))] // Wasi doesn't support threads
fn blocking_send() {
let (tx, mut rx) = mpsc::channel::<u8>(1);
let sync_code = std::thread::spawn(move || {
tx.blocking_send(10).unwrap();
});
tokio::runtime::Runtime::new()
.unwrap()
.block_on(asyn... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b2ada60e701d5c9e6644cf8fc42a100774f8e23f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b2ada60e701d5c9e6644cf8fc42a100774f8e23f/tokio/tests/sync_mpsc.rs | 481 | 540 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:16 | assert_eq!(rx.try_recv(), Err(TryRecvError::Empty));
drop(tx);
assert_eq!(rx.try_recv(), Err(TryRecvError::Disconnected));
}
}
#[test]
fn try_recv_close_while_empty_bounded() {
let (tx, mut rx) = mpsc::channel::<()>(5);
assert_eq!(Err(TryRecvError::Empty), rx.try_recv());
drop(tx);
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b2ada60e701d5c9e6644cf8fc42a100774f8e23f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b2ada60e701d5c9e6644cf8fc42a100774f8e23f/tokio/tests/sync_mpsc.rs | 601 | 659 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:17 | );
drop(rx);
assert_eq!(
tx.send_timeout(70, Duration::from_secs(1)).await,
Err(Closed(70))
);
}
#[test]
#[should_panic = "there is no reactor running, must be called from the context of a Tokio 1.x runtime"]
#[cfg(not(tokio_wasm))] // wasm currently doesn't support unwinding
fn recv_timeo... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b2ada60e701d5c9e6644cf8fc42a100774f8e23f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b2ada60e701d5c9e6644cf8fc42a100774f8e23f/tokio/tests/sync_mpsc.rs | 641 | 659 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:1 | #![allow(clippy::redundant_clone)]
#![warn(rust_2018_idioms)]
#![cfg(feature = "sync")]
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
use wasm_bindgen_test::wasm_bindgen_test as test;
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_tes... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | 0dc62da21b0bffe113e2efa23f6da6ef4e36bf4f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0dc62da21b0bffe113e2efa23f6da6ef4e36bf4f/tokio/tests/sync_mpsc.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:5 | }
#[maybe_tokio_test]
async fn send_recv_unbounded() {
let (tx, mut rx) = mpsc::unbounded_channel::<i32>();
// Using `try_send`
assert_ok!(tx.send(1));
assert_ok!(tx.send(2));
assert_eq!(rx.recv().await, Some(1));
assert_eq!(rx.recv().await, Some(2));
drop(tx);
assert!(rx.recv().awa... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | 0dc62da21b0bffe113e2efa23f6da6ef4e36bf4f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0dc62da21b0bffe113e2efa23f6da6ef4e36bf4f/tokio/tests/sync_mpsc.rs | 161 | 220 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:17 | );
drop(rx);
assert_eq!(
tx.send_timeout(70, Duration::from_secs(1)).await,
Err(Closed(70))
);
}
#[test]
#[should_panic = "there is no reactor running, must be called from the context of a Tokio 1.x runtime"]
#[cfg(not(target_family = "wasm"))] // wasm currently doesn't support unwinding
f... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | 0dc62da21b0bffe113e2efa23f6da6ef4e36bf4f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0dc62da21b0bffe113e2efa23f6da6ef4e36bf4f/tokio/tests/sync_mpsc.rs | 641 | 659 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:1 | #![allow(clippy::redundant_clone)]
#![warn(rust_2018_idioms)]
#![cfg(feature = "sync")]
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
use wasm_bindgen_test::wasm_bindgen_test as test;
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_tes... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | 6d3f92dddc510e9276191cfab1b0432ce8248589 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6d3f92dddc510e9276191cfab1b0432ce8248589/tokio/tests/sync_mpsc.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:4 | }
#[tokio::test]
#[cfg(feature = "full")]
async fn start_send_past_cap() {
use std::future::Future;
let mut t1 = tokio_test::task::spawn(());
let (tx1, mut rx) = mpsc::channel(1);
let tx2 = tx1.clone();
assert_ok!(tx1.try_send(()));
let mut r1 = Box::pin(tx1.reserve());
t1.enter(|cx, _|... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | 6d3f92dddc510e9276191cfab1b0432ce8248589 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6d3f92dddc510e9276191cfab1b0432ce8248589/tokio/tests/sync_mpsc.rs | 121 | 180 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:12 | fn unconsumed_messages_are_dropped() {
let msg = Arc::new(());
let (tx, rx) = mpsc::channel(100);
tx.try_send(msg.clone()).unwrap();
assert_eq!(2, Arc::strong_count(&msg));
drop((tx, rx));
assert_eq!(1, Arc::strong_count(&msg));
}
#[test]
#[cfg(all(feature = "full", not(target_os = "wasi")... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | 6d3f92dddc510e9276191cfab1b0432ce8248589 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6d3f92dddc510e9276191cfab1b0432ce8248589/tokio/tests/sync_mpsc.rs | 441 | 500 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:13 | #[cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads
fn blocking_send() {
let (tx, mut rx) = mpsc::channel::<u8>(1);
let sync_code = std::thread::spawn(move || {
tx.blocking_send(10).unwrap();
});
tokio::runtime::Runtime::new()
.unwrap()
.block... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | 6d3f92dddc510e9276191cfab1b0432ce8248589 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6d3f92dddc510e9276191cfab1b0432ce8248589/tokio/tests/sync_mpsc.rs | 481 | 540 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:16 | assert_eq!(rx.try_recv(), Err(TryRecvError::Empty));
drop(tx);
assert_eq!(rx.try_recv(), Err(TryRecvError::Disconnected));
}
}
#[test]
fn try_recv_close_while_empty_bounded() {
let (tx, mut rx) = mpsc::channel::<()>(5);
assert_eq!(Err(TryRecvError::Empty), rx.try_recv());
drop(tx);
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | 6d3f92dddc510e9276191cfab1b0432ce8248589 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6d3f92dddc510e9276191cfab1b0432ce8248589/tokio/tests/sync_mpsc.rs | 601 | 659 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:17 | );
drop(rx);
assert_eq!(
tx.send_timeout(70, Duration::from_secs(1)).await,
Err(Closed(70))
);
}
#[test]
#[should_panic = "there is no reactor running, must be called from the context of a Tokio 1.x runtime"]
#[cfg(not(target_arch = "wasm32"))] // wasm currently doesn't support unwinding
f... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | 6d3f92dddc510e9276191cfab1b0432ce8248589 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6d3f92dddc510e9276191cfab1b0432ce8248589/tokio/tests/sync_mpsc.rs | 641 | 659 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:1 | #![allow(clippy::redundant_clone)]
#![warn(rust_2018_idioms)]
#![cfg(feature = "sync")]
#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::wasm_bindgen_test as test;
#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test;
#[cfg(not(target_arch = "wasm32"))]
use tokio::test as m... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | 2747043f6f7e0870cc5aa72c146dfae9543c5ba8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2747043f6f7e0870cc5aa72c146dfae9543c5ba8/tokio/tests/sync_mpsc.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:2 | let val = rx.recv().await;
assert_eq!(val, Some(1));
let val = rx.recv().await;
assert_eq!(val, Some(2));
let val = rx.recv().await;
assert!(val.is_none());
}
#[tokio::test]
#[cfg(feature = "full")]
async fn reserve_disarm() {
let (tx, mut rx) = mpsc::channel::<i32>(2);
let tx1 = tx.clone... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | 2747043f6f7e0870cc5aa72c146dfae9543c5ba8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2747043f6f7e0870cc5aa72c146dfae9543c5ba8/tokio/tests/sync_mpsc.rs | 41 | 100 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:3 | // Dropping a permit should also open up a slot
drop(permit2);
assert!(r4.is_woken());
let mut r1 = tokio_test::task::spawn(tx1.reserve());
assert_pending!(r1.poll());
}
#[tokio::test]
#[cfg(feature = "full")]
async fn send_recv_stream_with_buffer() {
use tokio_stream::StreamExt;
let (tx, rx)... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | 2747043f6f7e0870cc5aa72c146dfae9543c5ba8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2747043f6f7e0870cc5aa72c146dfae9543c5ba8/tokio/tests/sync_mpsc.rs | 81 | 140 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:5 | }
#[maybe_tokio_test]
async fn send_recv_unbounded() {
let (tx, mut rx) = mpsc::unbounded_channel::<i32>();
// Using `try_send`
assert_ok!(tx.send(1));
assert_ok!(tx.send(2));
assert_eq!(rx.recv().await, Some(1));
assert_eq!(rx.recv().await, Some(2));
drop(tx);
assert!(rx.recv().awa... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | 2747043f6f7e0870cc5aa72c146dfae9543c5ba8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2747043f6f7e0870cc5aa72c146dfae9543c5ba8/tokio/tests/sync_mpsc.rs | 161 | 220 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:11 | assert!(reserve2.is_woken());
assert_ready_ok!(reserve2.poll());
}
#[maybe_tokio_test]
async fn dropping_rx_closes_channel() {
let (tx, rx) = mpsc::channel(100);
let msg = Arc::new(());
assert_ok!(tx.try_send(msg.clone()));
drop(rx);
assert_err!(tx.reserve().await);
assert_eq!(1, Arc::str... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | 2747043f6f7e0870cc5aa72c146dfae9543c5ba8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2747043f6f7e0870cc5aa72c146dfae9543c5ba8/tokio/tests/sync_mpsc.rs | 401 | 460 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:12 | fn unconsumed_messages_are_dropped() {
let msg = Arc::new(());
let (tx, rx) = mpsc::channel(100);
tx.try_send(msg.clone()).unwrap();
assert_eq!(2, Arc::strong_count(&msg));
drop((tx, rx));
assert_eq!(1, Arc::strong_count(&msg));
}
#[test]
#[cfg(feature = "full")]
fn blocking_recv() {
l... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | 2747043f6f7e0870cc5aa72c146dfae9543c5ba8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2747043f6f7e0870cc5aa72c146dfae9543c5ba8/tokio/tests/sync_mpsc.rs | 441 | 500 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:13 | #[cfg(feature = "full")]
fn blocking_send() {
let (tx, mut rx) = mpsc::channel::<u8>(1);
let sync_code = std::thread::spawn(move || {
tx.blocking_send(10).unwrap();
});
tokio::runtime::Runtime::new()
.unwrap()
.block_on(async move {
assert_eq!(Some(10), rx.recv().aw... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | 2747043f6f7e0870cc5aa72c146dfae9543c5ba8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2747043f6f7e0870cc5aa72c146dfae9543c5ba8/tokio/tests/sync_mpsc.rs | 481 | 540 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:1 | #![allow(clippy::redundant_clone)]
#![warn(rust_2018_idioms)]
#![cfg(feature = "full")]
use std::thread;
use tokio::runtime::Runtime;
use tokio::sync::mpsc;
use tokio::sync::mpsc::error::{TryRecvError, TrySendError};
use tokio_test::task;
use tokio_test::{
assert_err, assert_ok, assert_pending, assert_ready, asser... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b1afd95994be0d46ea70ba784439a684a787f50e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1afd95994be0d46ea70ba784439a684a787f50e/tokio/tests/sync_mpsc.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:2 | let val = rx.recv().await;
assert_eq!(val, Some(2));
let val = rx.recv().await;
assert!(val.is_none());
}
#[tokio::test]
async fn reserve_disarm() {
let (tx, mut rx) = mpsc::channel::<i32>(2);
let tx1 = tx.clone();
let tx2 = tx.clone();
let tx3 = tx.clone();
let tx4 = tx;
// We sh... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b1afd95994be0d46ea70ba784439a684a787f50e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1afd95994be0d46ea70ba784439a684a787f50e/tokio/tests/sync_mpsc.rs | 41 | 100 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:3 | let mut r1 = task::spawn(tx1.reserve());
assert_pending!(r1.poll());
}
#[tokio::test]
async fn send_recv_stream_with_buffer() {
use tokio_stream::StreamExt;
let (tx, rx) = support::mpsc_stream::channel_stream::<i32>(16);
let mut rx = Box::pin(rx);
tokio::spawn(async move {
assert_ok!(tx.s... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b1afd95994be0d46ea70ba784439a684a787f50e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1afd95994be0d46ea70ba784439a684a787f50e/tokio/tests/sync_mpsc.rs | 81 | 140 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:4 | let (tx1, mut rx) = mpsc::channel(1);
let tx2 = tx1.clone();
assert_ok!(tx1.try_send(()));
let mut r1 = Box::pin(tx1.reserve());
t1.enter(|cx, _| assert_pending!(r1.as_mut().poll(cx)));
{
let mut r2 = task::spawn(tx2.reserve());
assert_pending!(r2.poll());
drop(r1);
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b1afd95994be0d46ea70ba784439a684a787f50e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1afd95994be0d46ea70ba784439a684a787f50e/tokio/tests/sync_mpsc.rs | 121 | 180 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:5 | assert_eq!(rx.recv().await, Some(1));
assert_eq!(rx.recv().await, Some(2));
drop(tx);
assert!(rx.recv().await.is_none());
}
#[tokio::test]
async fn async_send_recv_unbounded() {
let (tx, mut rx) = mpsc::unbounded_channel();
tokio::spawn(async move {
assert_ok!(tx.send(1));
assert... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b1afd95994be0d46ea70ba784439a684a787f50e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1afd95994be0d46ea70ba784439a684a787f50e/tokio/tests/sync_mpsc.rs | 161 | 220 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:6 | #[tokio::test]
async fn no_t_bounds_buffer() {
struct NoImpls;
let (tx, mut rx) = mpsc::channel(100);
// sender should be Debug even though T isn't Debug
println!("{:?}", tx);
// same with Receiver
println!("{:?}", rx);
// and sender should be Clone even though T isn't Clone
assert!(tx... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b1afd95994be0d46ea70ba784439a684a787f50e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1afd95994be0d46ea70ba784439a684a787f50e/tokio/tests/sync_mpsc.rs | 201 | 260 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:7 | // Send first message
p1.send(1);
// Not ready
let mut p2 = task::spawn(tx.reserve());
assert_pending!(p2.poll());
// Take the value
assert!(rx.recv().await.is_some());
// Notified
assert!(p2.is_woken());
// Trying to send fails
assert_err!(tx.try_send(1337));
// Send se... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b1afd95994be0d46ea70ba784439a684a787f50e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1afd95994be0d46ea70ba784439a684a787f50e/tokio/tests/sync_mpsc.rs | 241 | 300 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:8 | let mut permit2 = task::spawn(tx2.reserve());
assert_pending!(permit2.poll());
rx.close();
assert!(permit2.is_woken());
assert_ready_err!(permit2.poll());
{
let mut recv = task::spawn(rx.recv());
assert_pending!(recv.poll());
permit1.send(123);
assert!(recv.is_wok... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b1afd95994be0d46ea70ba784439a684a787f50e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1afd95994be0d46ea70ba784439a684a787f50e/tokio/tests/sync_mpsc.rs | 281 | 340 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:9 | assert_eq!(rx.recv().await, Some("hello"));
assert_ok!(tx.try_send("goodbye"));
drop(tx);
assert_eq!(rx.recv().await, Some("goodbye"));
assert!(rx.recv().await.is_none());
}
#[tokio::test]
async fn try_send_fail_with_try_recv() {
let (tx, mut rx) = mpsc::channel(1);
tx.try_send("hello").unwr... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b1afd95994be0d46ea70ba784439a684a787f50e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1afd95994be0d46ea70ba784439a684a787f50e/tokio/tests/sync_mpsc.rs | 321 | 380 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:10 | }
permit.send("foo");
assert_eq!(rx.recv().await, Some("foo"));
// Dropping permit releases the slot.
let permit = tx.try_reserve().unwrap();
drop(permit);
let _permit = tx.try_reserve().unwrap();
}
#[tokio::test]
async fn drop_permit_releases_permit() {
// poll_ready reserves capacity,... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b1afd95994be0d46ea70ba784439a684a787f50e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1afd95994be0d46ea70ba784439a684a787f50e/tokio/tests/sync_mpsc.rs | 361 | 420 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:11 | assert_eq!(1, Arc::strong_count(&msg));
}
#[test]
fn dropping_rx_closes_channel_for_try() {
let (tx, rx) = mpsc::channel(100);
let msg = Arc::new(());
tx.try_send(msg.clone()).unwrap();
drop(rx);
assert!(matches!(
tx.try_send(msg.clone()),
Err(TrySendError::Closed(_))
));
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b1afd95994be0d46ea70ba784439a684a787f50e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1afd95994be0d46ea70ba784439a684a787f50e/tokio/tests/sync_mpsc.rs | 401 | 460 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:12 | #[test]
fn blocking_recv() {
let (tx, mut rx) = mpsc::channel::<u8>(1);
let sync_code = thread::spawn(move || {
assert_eq!(Some(10), rx.blocking_recv());
});
Runtime::new().unwrap().block_on(async move {
let _ = tx.send(10).await;
});
sync_code.join().unwrap()
}
#[tokio::test]... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b1afd95994be0d46ea70ba784439a684a787f50e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1afd95994be0d46ea70ba784439a684a787f50e/tokio/tests/sync_mpsc.rs | 441 | 500 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:13 | }
#[tokio::test]
async fn ready_close_cancel_bounded() {
let (tx, mut rx) = mpsc::channel::<()>(100);
let _tx2 = tx.clone();
let permit = assert_ok!(tx.reserve().await);
rx.close();
let mut recv = task::spawn(rx.recv());
assert_pending!(recv.poll());
drop(permit);
assert!(recv.is_w... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b1afd95994be0d46ea70ba784439a684a787f50e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1afd95994be0d46ea70ba784439a684a787f50e/tokio/tests/sync_mpsc.rs | 481 | 540 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:14 | #[test]
fn try_recv_bounded() {
let (tx, mut rx) = mpsc::channel(5);
tx.try_send("hello").unwrap();
tx.try_send("hello").unwrap();
tx.try_send("hello").unwrap();
tx.try_send("hello").unwrap();
tx.try_send("hello").unwrap();
assert!(tx.try_send("hello").is_err());
assert_eq!(Ok("hello")... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b1afd95994be0d46ea70ba784439a684a787f50e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1afd95994be0d46ea70ba784439a684a787f50e/tokio/tests/sync_mpsc.rs | 521 | 580 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:15 | assert_eq!(Err(TryRecvError::Disconnected), rx.try_recv());
}
#[test]
fn try_recv_unbounded() {
for num in 0..100 {
let (tx, mut rx) = mpsc::unbounded_channel();
for i in 0..num {
tx.send(i).unwrap();
}
for i in 0..num {
assert_eq!(rx.try_recv(), Ok(i));
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b1afd95994be0d46ea70ba784439a684a787f50e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1afd95994be0d46ea70ba784439a684a787f50e/tokio/tests/sync_mpsc.rs | 561 | 620 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:16 | #[tokio::test(start_paused = true)]
async fn recv_timeout() {
use tokio::sync::mpsc::error::SendTimeoutError::{Closed, Timeout};
use tokio::time::Duration;
let (tx, rx) = mpsc::channel(5);
assert_eq!(tx.send_timeout(10, Duration::from_secs(1)).await, Ok(()));
assert_eq!(tx.send_timeout(20, Duratio... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | b1afd95994be0d46ea70ba784439a684a787f50e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1afd95994be0d46ea70ba784439a684a787f50e/tokio/tests/sync_mpsc.rs | 601 | 633 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:15 | assert_eq!(Err(TryRecvError::Disconnected), rx.try_recv());
}
#[test]
fn try_recv_unbounded() {
for num in 0..100 {
let (tx, mut rx) = mpsc::unbounded_channel();
for i in 0..num {
tx.send(i).unwrap();
}
for i in 0..num {
assert_eq!(rx.try_recv(), Ok(i));
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | e9f6faee67a5756458cc1802f73168c88c3edd81 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e9f6faee67a5756458cc1802f73168c88c3edd81/tokio/tests/sync_mpsc.rs | 561 | 599 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:10 | }
permit.send("foo");
assert_eq!(rx.recv().await, Some("foo"));
// Dropping permit releases the slot.
let permit = tx.try_reserve().unwrap();
drop(permit);
let _permit = tx.try_reserve().unwrap();
}
#[tokio::test]
async fn drop_permit_releases_permit() {
// poll_ready reserves capacity,... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | ddd33f2b05dacd81c5fcd3170c1c9e1b2abad0f5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ddd33f2b05dacd81c5fcd3170c1c9e1b2abad0f5/tokio/tests/sync_mpsc.rs | 361 | 420 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:11 | assert_eq!(1, Arc::strong_count(&msg));
}
#[test]
fn dropping_rx_closes_channel_for_try() {
let (tx, rx) = mpsc::channel(100);
let msg = Arc::new(());
tx.try_send(msg.clone()).unwrap();
drop(rx);
{
let err = assert_err!(tx.try_send(msg.clone()));
match err {
TrySendEr... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | ddd33f2b05dacd81c5fcd3170c1c9e1b2abad0f5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ddd33f2b05dacd81c5fcd3170c1c9e1b2abad0f5/tokio/tests/sync_mpsc.rs | 401 | 460 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:12 | let (tx, mut rx) = mpsc::channel::<u8>(1);
let sync_code = thread::spawn(move || {
assert_eq!(Some(10), rx.blocking_recv());
});
Runtime::new().unwrap().block_on(async move {
let _ = tx.send(10).await;
});
sync_code.join().unwrap()
}
#[tokio::test]
#[should_panic]
async fn blockin... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | ddd33f2b05dacd81c5fcd3170c1c9e1b2abad0f5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ddd33f2b05dacd81c5fcd3170c1c9e1b2abad0f5/tokio/tests/sync_mpsc.rs | 441 | 500 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:13 | #[tokio::test]
async fn ready_close_cancel_bounded() {
let (tx, mut rx) = mpsc::channel::<()>(100);
let _tx2 = tx.clone();
let permit = assert_ok!(tx.reserve().await);
rx.close();
let mut recv = task::spawn(rx.recv());
assert_pending!(recv.poll());
drop(permit);
assert!(recv.is_woke... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | ddd33f2b05dacd81c5fcd3170c1c9e1b2abad0f5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ddd33f2b05dacd81c5fcd3170c1c9e1b2abad0f5/tokio/tests/sync_mpsc.rs | 481 | 540 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:14 | let (tx, mut rx) = mpsc::channel(5);
tx.try_send("hello").unwrap();
tx.try_send("hello").unwrap();
tx.try_send("hello").unwrap();
tx.try_send("hello").unwrap();
tx.try_send("hello").unwrap();
assert!(tx.try_send("hello").is_err());
assert_eq!(Ok("hello"), rx.try_recv());
assert_eq!(Ok(... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | ddd33f2b05dacd81c5fcd3170c1c9e1b2abad0f5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ddd33f2b05dacd81c5fcd3170c1c9e1b2abad0f5/tokio/tests/sync_mpsc.rs | 521 | 580 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:15 | #[test]
fn try_recv_unbounded() {
for num in 0..100 {
let (tx, mut rx) = mpsc::unbounded_channel();
for i in 0..num {
tx.send(i).unwrap();
}
for i in 0..num {
assert_eq!(rx.try_recv(), Ok(i));
}
assert_eq!(rx.try_recv(), Err(TryRecvError::Em... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | ddd33f2b05dacd81c5fcd3170c1c9e1b2abad0f5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ddd33f2b05dacd81c5fcd3170c1c9e1b2abad0f5/tokio/tests/sync_mpsc.rs | 561 | 597 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:1 | #![allow(clippy::redundant_clone)]
#![warn(rust_2018_idioms)]
#![cfg(feature = "full")]
use std::thread;
use tokio::runtime::Runtime;
use tokio::sync::mpsc;
use tokio::sync::mpsc::error::TrySendError;
use tokio_test::task;
use tokio_test::{
assert_err, assert_ok, assert_pending, assert_ready, assert_ready_err, ass... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | 672be92a03a489d028ed7ec2c6b1abdbf0874a1d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/672be92a03a489d028ed7ec2c6b1abdbf0874a1d/tokio/tests/sync_mpsc.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:8 | let mut permit2 = task::spawn(tx2.reserve());
assert_pending!(permit2.poll());
rx.close();
assert!(permit2.is_woken());
assert_ready_err!(permit2.poll());
{
let mut recv = task::spawn(rx.recv());
assert_pending!(recv.poll());
permit1.send(123);
assert!(recv.is_wok... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | 672be92a03a489d028ed7ec2c6b1abdbf0874a1d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/672be92a03a489d028ed7ec2c6b1abdbf0874a1d/tokio/tests/sync_mpsc.rs | 281 | 340 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:9 | assert_eq!(rx.recv().await, Some("hello"));
assert_ok!(tx.try_send("goodbye"));
drop(tx);
assert_eq!(rx.recv().await, Some("goodbye"));
assert!(rx.recv().await.is_none());
}
#[tokio::test]
async fn try_reserve_fails() {
let (tx, mut rx) = mpsc::channel(1);
let permit = tx.try_reserve().unwra... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | 672be92a03a489d028ed7ec2c6b1abdbf0874a1d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/672be92a03a489d028ed7ec2c6b1abdbf0874a1d/tokio/tests/sync_mpsc.rs | 321 | 380 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:10 | let mut reserve2 = task::spawn(tx2.reserve());
assert_pending!(reserve2.poll());
drop(permit);
assert!(reserve2.is_woken());
assert_ready_ok!(reserve2.poll());
}
#[tokio::test]
async fn dropping_rx_closes_channel() {
let (tx, rx) = mpsc::channel(100);
let msg = Arc::new(());
assert_ok!(t... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | 672be92a03a489d028ed7ec2c6b1abdbf0874a1d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/672be92a03a489d028ed7ec2c6b1abdbf0874a1d/tokio/tests/sync_mpsc.rs | 361 | 420 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:11 | }
#[test]
fn unconsumed_messages_are_dropped() {
let msg = Arc::new(());
let (tx, rx) = mpsc::channel(100);
tx.try_send(msg.clone()).unwrap();
assert_eq!(2, Arc::strong_count(&msg));
drop((tx, rx));
assert_eq!(1, Arc::strong_count(&msg));
}
#[test]
fn blocking_recv() {
let (tx, mut rx... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | 672be92a03a489d028ed7ec2c6b1abdbf0874a1d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/672be92a03a489d028ed7ec2c6b1abdbf0874a1d/tokio/tests/sync_mpsc.rs | 401 | 460 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:12 | let (tx, mut rx) = mpsc::channel::<u8>(1);
let sync_code = thread::spawn(move || {
tx.blocking_send(10).unwrap();
});
Runtime::new().unwrap().block_on(async move {
assert_eq!(Some(10), rx.recv().await);
});
sync_code.join().unwrap()
}
#[tokio::test]
#[should_panic]
async fn blocki... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | 672be92a03a489d028ed7ec2c6b1abdbf0874a1d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/672be92a03a489d028ed7ec2c6b1abdbf0874a1d/tokio/tests/sync_mpsc.rs | 441 | 496 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:13 | let (tx1, mut rx) = mpsc::channel::<()>(1);
let tx2 = tx1.clone();
let permit1 = assert_ok!(tx1.reserve().await);
let mut permit2 = task::spawn(tx2.reserve());
assert_pending!(permit2.poll());
rx.close();
drop(permit1);
assert!(permit2.is_woken());
drop(permit2);
assert!(rx.recv... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | 672be92a03a489d028ed7ec2c6b1abdbf0874a1d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/672be92a03a489d028ed7ec2c6b1abdbf0874a1d/tokio/tests/sync_mpsc.rs | 481 | 496 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:8 | let mut permit2 = task::spawn(tx2.reserve());
assert_pending!(permit2.poll());
rx.close();
assert!(permit2.is_woken());
assert_ready_err!(permit2.poll());
{
let mut recv = task::spawn(rx.recv());
assert_pending!(recv.poll());
permit1.send(123);
assert!(recv.is_wok... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | 8efa62013b551d5130791c3a79ce8ab5cb0b5abf | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8efa62013b551d5130791c3a79ce8ab5cb0b5abf/tokio/tests/sync_mpsc.rs | 281 | 340 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:9 | assert_eq!(rx.recv().await, Some("hello"));
assert_ok!(tx.try_send("goodbye"));
drop(tx);
assert_eq!(rx.recv().await, Some("goodbye"));
assert!(rx.recv().await.is_none());
}
#[tokio::test]
async fn drop_permit_releases_permit() {
// poll_ready reserves capacity, ensure that the capacity is releas... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | 8efa62013b551d5130791c3a79ce8ab5cb0b5abf | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8efa62013b551d5130791c3a79ce8ab5cb0b5abf/tokio/tests/sync_mpsc.rs | 321 | 380 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:10 | fn dropping_rx_closes_channel_for_try() {
let (tx, rx) = mpsc::channel(100);
let msg = Arc::new(());
tx.try_send(msg.clone()).unwrap();
drop(rx);
{
let err = assert_err!(tx.try_send(msg.clone()));
match err {
TrySendError::Closed(..) => {}
_ => panic!(),
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | 8efa62013b551d5130791c3a79ce8ab5cb0b5abf | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8efa62013b551d5130791c3a79ce8ab5cb0b5abf/tokio/tests/sync_mpsc.rs | 361 | 420 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:11 | });
Runtime::new().unwrap().block_on(async move {
let _ = tx.send(10).await;
});
sync_code.join().unwrap()
}
#[tokio::test]
#[should_panic]
async fn blocking_recv_async() {
let (_tx, mut rx) = mpsc::channel::<()>(1);
let _ = rx.blocking_recv();
}
#[test]
fn blocking_send() {
let (tx, ... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | 8efa62013b551d5130791c3a79ce8ab5cb0b5abf | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8efa62013b551d5130791c3a79ce8ab5cb0b5abf/tokio/tests/sync_mpsc.rs | 401 | 460 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:12 | let permit = assert_ok!(tx.reserve().await);
rx.close();
let mut recv = task::spawn(rx.recv());
assert_pending!(recv.poll());
drop(permit);
assert!(recv.is_woken());
let val = assert_ready!(recv.poll());
assert!(val.is_none());
}
#[tokio::test]
async fn permit_available_not_acquired_clo... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | 8efa62013b551d5130791c3a79ce8ab5cb0b5abf | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8efa62013b551d5130791c3a79ce8ab5cb0b5abf/tokio/tests/sync_mpsc.rs | 441 | 473 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:1 | #![allow(clippy::redundant_clone)]
#![warn(rust_2018_idioms)]
#![cfg(feature = "full")]
use std::thread;
use tokio::runtime::Runtime;
use tokio::sync::mpsc;
use tokio::sync::mpsc::error::TrySendError;
use tokio_test::task;
use tokio_test::{
assert_err, assert_ok, assert_pending, assert_ready, assert_ready_err, ass... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | a7833e300780546c091e606bb2e077542f2e2e4e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a7833e300780546c091e606bb2e077542f2e2e4e/tokio/tests/sync_mpsc.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:2 | assert!(val.is_none());
}
#[tokio::test]
async fn reserve_disarm() {
let (tx, mut rx) = mpsc::channel::<i32>(2);
let tx1 = tx.clone();
let tx2 = tx.clone();
let tx3 = tx.clone();
let tx4 = tx;
// We should be able to `poll_ready` two handles without problem
let permit1 = assert_ok!(tx1.res... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | a7833e300780546c091e606bb2e077542f2e2e4e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a7833e300780546c091e606bb2e077542f2e2e4e/tokio/tests/sync_mpsc.rs | 41 | 100 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:3 | #[tokio::test]
async fn send_recv_stream_with_buffer() {
use tokio::stream::StreamExt;
let (tx, mut rx) = mpsc::channel::<i32>(16);
tokio::spawn(async move {
assert_ok!(tx.send(1).await);
assert_ok!(tx.send(2).await);
});
assert_eq!(Some(1), rx.next().await);
assert_eq!(Some(2... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | a7833e300780546c091e606bb2e077542f2e2e4e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a7833e300780546c091e606bb2e077542f2e2e4e/tokio/tests/sync_mpsc.rs | 81 | 140 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:4 | let mut r1 = Box::pin(tx1.reserve());
t1.enter(|cx, _| assert_pending!(r1.as_mut().poll(cx)));
{
let mut r2 = task::spawn(tx2.reserve());
assert_pending!(r2.poll());
drop(r1);
assert!(rx.recv().await.is_some());
assert!(r2.is_woken());
assert!(!t1.is_woken());... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | a7833e300780546c091e606bb2e077542f2e2e4e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a7833e300780546c091e606bb2e077542f2e2e4e/tokio/tests/sync_mpsc.rs | 121 | 180 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:5 | assert!(rx.recv().await.is_none());
}
#[tokio::test]
async fn async_send_recv_unbounded() {
let (tx, mut rx) = mpsc::unbounded_channel();
tokio::spawn(async move {
assert_ok!(tx.send(1));
assert_ok!(tx.send(2));
});
assert_eq!(Some(1), rx.recv().await);
assert_eq!(Some(2), rx.recv... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | a7833e300780546c091e606bb2e077542f2e2e4e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a7833e300780546c091e606bb2e077542f2e2e4e/tokio/tests/sync_mpsc.rs | 161 | 220 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:6 | // sender should be Debug even though T isn't Debug
println!("{:?}", tx);
// same with Receiver
println!("{:?}", rx);
// and sender should be Clone even though T isn't Clone
assert!(tx.clone().try_send(NoImpls).is_ok());
assert!(rx.recv().await.is_some());
}
#[tokio::test]
async fn no_t_bounds... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | a7833e300780546c091e606bb2e077542f2e2e4e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a7833e300780546c091e606bb2e077542f2e2e4e/tokio/tests/sync_mpsc.rs | 201 | 260 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:7 | // Take the value
assert!(rx.recv().await.is_some());
// Notified
assert!(p2.is_woken());
// Trying to send fails
assert_err!(tx.try_send(1337));
// Send second
let permit = assert_ready_ok!(p2.poll());
permit.send(2);
assert!(rx.recv().await.is_some());
}
#[tokio::test]
async f... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | a7833e300780546c091e606bb2e077542f2e2e4e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a7833e300780546c091e606bb2e077542f2e2e4e/tokio/tests/sync_mpsc.rs | 241 | 300 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:8 | {
let mut recv = task::spawn(rx.recv());
assert_pending!(recv.poll());
permit1.send(123);
assert!(recv.is_woken());
let v = assert_ready!(recv.poll());
assert_eq!(v, Some(123));
}
assert!(rx.recv().await.is_none());
}
#[tokio::test]
async fn tx_close_gets_none... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | a7833e300780546c091e606bb2e077542f2e2e4e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a7833e300780546c091e606bb2e077542f2e2e4e/tokio/tests/sync_mpsc.rs | 281 | 340 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:9 | }
#[tokio::test]
async fn drop_permit_releases_permit() {
// poll_ready reserves capacity, ensure that the capacity is released if tx
// is dropped w/o sending a value.
let (tx1, _rx) = mpsc::channel::<i32>(1);
let tx2 = tx1.clone();
let permit = assert_ok!(tx1.reserve().await);
let mut reser... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | a7833e300780546c091e606bb2e077542f2e2e4e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a7833e300780546c091e606bb2e077542f2e2e4e/tokio/tests/sync_mpsc.rs | 321 | 380 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:10 | {
let err = assert_err!(tx.try_send(msg.clone()));
match err {
TrySendError::Closed(..) => {}
_ => panic!(),
}
}
assert_eq!(1, Arc::strong_count(&msg));
}
#[test]
fn unconsumed_messages_are_dropped() {
let msg = Arc::new(());
let (tx, rx) = mpsc::channe... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | a7833e300780546c091e606bb2e077542f2e2e4e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a7833e300780546c091e606bb2e077542f2e2e4e/tokio/tests/sync_mpsc.rs | 361 | 420 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:11 | #[tokio::test]
#[should_panic]
async fn blocking_recv_async() {
let (_tx, mut rx) = mpsc::channel::<()>(1);
let _ = rx.blocking_recv();
}
#[test]
fn blocking_send() {
let (tx, mut rx) = mpsc::channel::<u8>(1);
let sync_code = thread::spawn(move || {
tx.blocking_send(10).unwrap();
});
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | a7833e300780546c091e606bb2e077542f2e2e4e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a7833e300780546c091e606bb2e077542f2e2e4e/tokio/tests/sync_mpsc.rs | 401 | 460 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:12 | drop(permit);
assert!(recv.is_woken());
let val = assert_ready!(recv.poll());
assert!(val.is_none());
}
#[tokio::test]
async fn permit_available_not_acquired_close() {
let (tx1, mut rx) = mpsc::channel::<()>(1);
let tx2 = tx1.clone();
let permit1 = assert_ok!(tx1.reserve().await);
let mu... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | a7833e300780546c091e606bb2e077542f2e2e4e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a7833e300780546c091e606bb2e077542f2e2e4e/tokio/tests/sync_mpsc.rs | 441 | 466 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:1 | #![allow(clippy::redundant_clone)]
#![warn(rust_2018_idioms)]
#![cfg(feature = "full")]
use std::thread;
use tokio::runtime::Runtime;
use tokio::sync::mpsc;
use tokio::sync::mpsc::error::{TryRecvError, TrySendError};
use tokio_test::task;
use tokio_test::{
assert_err, assert_ok, assert_pending, assert_ready, asser... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | 62023dffe5396ee1a0380f12c7530bf4ff59fe4a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/62023dffe5396ee1a0380f12c7530bf4ff59fe4a/tokio/tests/sync_mpsc.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:10 | {
let err = assert_err!(tx.try_send(msg.clone()));
match err {
TrySendError::Closed(..) => {}
_ => panic!(),
}
}
assert_eq!(1, Arc::strong_count(&msg));
}
#[test]
fn unconsumed_messages_are_dropped() {
let msg = Arc::new(());
let (tx, rx) = mpsc::channe... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | 62023dffe5396ee1a0380f12c7530bf4ff59fe4a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/62023dffe5396ee1a0380f12c7530bf4ff59fe4a/tokio/tests/sync_mpsc.rs | 361 | 420 |
tokio-rs/tokio:tokio/tests/sync_mpsc.rs:11 | match rx.try_recv() {
Err(TryRecvError::Closed) => {}
_ => panic!(),
}
}
#[test]
fn try_recv_unbounded() {
let (tx, mut rx) = mpsc::unbounded_channel();
match rx.try_recv() {
Err(TryRecvError::Empty) => {}
_ => panic!(),
}
tx.send(42).unwrap();
match rx.try_recv(... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/sync_mpsc.rs | MIT | 62023dffe5396ee1a0380f12c7530bf4ff59fe4a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/62023dffe5396ee1a0380f12c7530bf4ff59fe4a/tokio/tests/sync_mpsc.rs | 401 | 460 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.