mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-04 09:53:04 +03:00
Rollup merge of #139836 - glyn:test-mpmc-receiver-cloning, r=jhpratt
Basic tests of MPMC receiver cloning Ref: https://github.com/rust-lang/rust/issues/126840#issuecomment-2802321146
This commit is contained in:
@@ -63,6 +63,24 @@ fn smoke_port_gone() {
|
||||
assert!(tx.send(1).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn smoke_receiver_clone() {
|
||||
let (tx, rx) = channel::<i32>();
|
||||
let rx2 = rx.clone();
|
||||
drop(rx);
|
||||
tx.send(1).unwrap();
|
||||
assert_eq!(rx2.recv().unwrap(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn smoke_receiver_clone_port_gone() {
|
||||
let (tx, rx) = channel::<i32>();
|
||||
let rx2 = rx.clone();
|
||||
drop(rx);
|
||||
drop(rx2);
|
||||
assert!(tx.send(1).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn smoke_shared_port_gone() {
|
||||
let (tx, rx) = channel::<i32>();
|
||||
@@ -124,6 +142,18 @@ fn chan_gone_concurrent() {
|
||||
while rx.recv().is_ok() {}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn receiver_cloning() {
|
||||
let (tx, rx) = channel::<i32>();
|
||||
let rx2 = rx.clone();
|
||||
|
||||
tx.send(1).unwrap();
|
||||
tx.send(2).unwrap();
|
||||
|
||||
assert_eq!(rx2.recv(), Ok(1));
|
||||
assert_eq!(rx.recv(), Ok(2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stress() {
|
||||
let count = if cfg!(miri) { 100 } else { 10000 };
|
||||
|
||||
Reference in New Issue
Block a user