Skip to content

Commit

Permalink
Add unit test of re_smart_channel is_connected
Browse files Browse the repository at this point in the history
Follow-up to #2106
  • Loading branch information
emilk committed May 15, 2023
1 parent a64edaa commit 3f09a93
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions crates/re_smart_channel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,26 @@ fn test_smart_channel() {
assert_eq!(rx.len(), 0);
assert!(tx.latency_ns() > 1_000_000);
}

#[test]
fn test_smart_channel_connected() {
let (tx1, rx) = smart_channel(Source::Sdk); // whatever source
assert_eq!(rx.try_recv(), Err(TryRecvError::Empty));
assert!(rx.is_connected());

let tx2 = tx1.clone();
assert_eq!(rx.try_recv(), Err(TryRecvError::Empty));
assert!(rx.is_connected());

tx2.send(42).unwrap();
assert_eq!(rx.try_recv(), Ok(42));
assert!(rx.is_connected());

drop(tx1);
assert_eq!(rx.try_recv(), Err(TryRecvError::Empty));
assert!(rx.is_connected());

drop(tx2);
assert_eq!(rx.try_recv(), Err(TryRecvError::Disconnected));
assert!(!rx.is_connected());
}

0 comments on commit 3f09a93

Please sign in to comment.