Skip to content

Commit

Permalink
std: add regression test for rust-lang#107466
Browse files Browse the repository at this point in the history
Tests that messages are immediately dropped once the last receiver is destroyed.
  • Loading branch information
joboet committed Feb 17, 2023
1 parent 746331e commit 642a324
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions library/std/src/sync/mpsc/sync_tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::*;
use crate::env;
use crate::rc::Rc;
use crate::sync::mpmc::SendTimeoutError;
use crate::thread;
use crate::time::Duration;
Expand Down Expand Up @@ -656,3 +657,15 @@ fn issue_15761() {
repro()
}
}

#[test]
fn drop_unreceived() {
let (tx, rx) = sync_channel::<Rc<()>>(1);
let msg = Rc::new(());
let weak = Rc::downgrade(&msg);
assert!(tx.send(msg).is_ok());
drop(rx);
// Messages should be dropped immediately when the last receiver is destroyed.
assert!(weak.upgrade().is_none());
drop(tx);
}

0 comments on commit 642a324

Please sign in to comment.