Make reason for try_send errors clearer (#864)

This commit is contained in:
Jon Gjengset
2019-01-23 15:06:24 -08:00
committed by Carl Lerche
parent c6f8bdb249
commit 0ec8986b0b
3 changed files with 33 additions and 2 deletions
+14 -1
View File
@@ -255,7 +255,7 @@ fn try_send_fail() {
tx.try_send("hello").unwrap();
// This should fail
assert!(tx.try_send("fail").is_err());
assert!(tx.try_send("fail").unwrap_err().is_full());
assert_eq!(rx.next().unwrap().unwrap(), "hello");
@@ -300,6 +300,19 @@ fn dropping_rx_closes_channel() {
assert_eq!(1, Arc::strong_count(&msg));
}
#[test]
fn dropping_rx_closes_channel_for_try() {
let (mut tx, rx) = mpsc::channel(100);
let msg = Arc::new(());
tx.try_send(msg.clone()).unwrap();
drop(rx);
assert!(tx.try_send(msg.clone()).unwrap_err().is_closed());
assert_eq!(1, Arc::strong_count(&msg));
}
#[test]
fn unconsumed_messagers_are_dropped() {
let msg = Arc::new(());