about summary refs log tree commit diff
diff options
context:
space:
mode:
authorStuart Cook <Zalathar@users.noreply.github.com>2025-04-15 15:47:32 +1000
committerGitHub <noreply@github.com>2025-04-15 15:47:32 +1000
commit783b08156ebf2e8f2ee766bb4bfc2f8025c38243 (patch)
tree741e88f487cc033e137375a4ede5fae96c32a72f
parent4d5284a866b1072c88a231becb5affa4a12defb5 (diff)
parent1376810d44d62dc7e8146f988e41aa2a9f641cf8 (diff)
downloadrust-783b08156ebf2e8f2ee766bb4bfc2f8025c38243.tar.gz
rust-783b08156ebf2e8f2ee766bb4bfc2f8025c38243.zip
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
-rw-r--r--library/std/tests/sync/mpmc.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/library/std/tests/sync/mpmc.rs b/library/std/tests/sync/mpmc.rs
index 81b92297f76..78abcb3bcbe 100644
--- a/library/std/tests/sync/mpmc.rs
+++ b/library/std/tests/sync/mpmc.rs
@@ -64,6 +64,24 @@ fn smoke_port_gone() {
 }
 
 #[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>();
     drop(rx);
@@ -125,6 +143,18 @@ fn chan_gone_concurrent() {
 }
 
 #[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 };
     let (tx, rx) = channel::<i32>();