summaryrefslogtreecommitdiffstats
path: root/third_party/rust/crossbeam-channel/tests/never.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/crossbeam-channel/tests/never.rs
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/crossbeam-channel/tests/never.rs')
-rw-r--r--third_party/rust/crossbeam-channel/tests/never.rs95
1 files changed, 95 insertions, 0 deletions
diff --git a/third_party/rust/crossbeam-channel/tests/never.rs b/third_party/rust/crossbeam-channel/tests/never.rs
new file mode 100644
index 0000000000..f275126f7d
--- /dev/null
+++ b/third_party/rust/crossbeam-channel/tests/never.rs
@@ -0,0 +1,95 @@
+//! Tests for the never channel flavor.
+
+use std::thread;
+use std::time::{Duration, Instant};
+
+use crossbeam_channel::{never, select, tick, unbounded};
+
+fn ms(ms: u64) -> Duration {
+ Duration::from_millis(ms)
+}
+
+#[test]
+fn smoke() {
+ select! {
+ recv(never::<i32>()) -> _ => panic!(),
+ default => {}
+ }
+}
+
+#[test]
+fn optional() {
+ let (s, r) = unbounded::<i32>();
+ s.send(1).unwrap();
+ s.send(2).unwrap();
+
+ let mut r = Some(&r);
+ select! {
+ recv(r.unwrap_or(&never())) -> _ => {}
+ default => panic!(),
+ }
+
+ r = None;
+ select! {
+ recv(r.unwrap_or(&never())) -> _ => panic!(),
+ default => {}
+ }
+}
+
+#[test]
+fn tick_n() {
+ let mut r = tick(ms(100));
+ let mut step = 0;
+
+ loop {
+ select! {
+ recv(r) -> _ => step += 1,
+ default(ms(500)) => break,
+ }
+
+ if step == 10 {
+ r = never();
+ }
+ }
+
+ assert_eq!(step, 10);
+}
+
+#[test]
+fn capacity() {
+ let r = never::<i32>();
+ assert_eq!(r.capacity(), Some(0));
+}
+
+#[test]
+fn len_empty_full() {
+ let r = never::<i32>();
+ assert_eq!(r.len(), 0);
+ assert!(r.is_empty());
+ assert!(r.is_full());
+}
+
+#[test]
+fn try_recv() {
+ let r = never::<i32>();
+ assert!(r.try_recv().is_err());
+
+ thread::sleep(ms(100));
+ assert!(r.try_recv().is_err());
+}
+
+#[test]
+fn recv_timeout() {
+ let start = Instant::now();
+ let r = never::<i32>();
+
+ assert!(r.recv_timeout(ms(100)).is_err());
+ let now = Instant::now();
+ assert!(now - start >= ms(100));
+ assert!(now - start <= ms(150));
+
+ assert!(r.recv_timeout(ms(100)).is_err());
+ let now = Instant::now();
+ assert!(now - start >= ms(200));
+ assert!(now - start <= ms(250));
+}