Skip to content

Basic tests of MPMC receiver cloning #139836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions library/std/tests/sync/mpmc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
Expand Down Expand Up @@ -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 };
Expand Down
Loading