aboutsummaryrefslogtreecommitdiff
path: root/tests/mpsc.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/mpsc.rs')
-rw-r--r--tests/mpsc.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/mpsc.rs b/tests/mpsc.rs
index 444c8e1..f5d7198 100644
--- a/tests/mpsc.rs
+++ b/tests/mpsc.rs
@@ -632,3 +632,26 @@ fn send_backpressure_multi_senders() {
let item = block_on(rx.next()).unwrap();
assert_eq!(item, 2);
}
+
+/// Test that empty channel has zero length and that non-empty channel has length equal to number
+/// of enqueued items
+#[test]
+fn unbounded_len() {
+ let (tx, mut rx) = mpsc::unbounded();
+ assert_eq!(tx.len(), 0);
+ assert!(tx.is_empty());
+ tx.unbounded_send(1).unwrap();
+ assert_eq!(tx.len(), 1);
+ assert!(!tx.is_empty());
+ tx.unbounded_send(2).unwrap();
+ assert_eq!(tx.len(), 2);
+ assert!(!tx.is_empty());
+ let item = block_on(rx.next()).unwrap();
+ assert_eq!(item, 1);
+ assert_eq!(tx.len(), 1);
+ assert!(!tx.is_empty());
+ let item = block_on(rx.next()).unwrap();
+ assert_eq!(item, 2);
+ assert_eq!(tx.len(), 0);
+ assert!(tx.is_empty());
+}