std: add regression test for #107466

Tests that messages are immediately dropped once the last receiver is destroyed.
This commit is contained in:
joboet 2023-02-17 15:58:15 +01:00
parent 746331edf3
commit 642a324746

View File

@ -1,5 +1,6 @@
use super::*; use super::*;
use crate::env; use crate::env;
use crate::rc::Rc;
use crate::sync::mpmc::SendTimeoutError; use crate::sync::mpmc::SendTimeoutError;
use crate::thread; use crate::thread;
use crate::time::Duration; use crate::time::Duration;
@ -656,3 +657,15 @@ fn repro() {
repro() 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);
}