Skip to content

Commit

Permalink
Add test coverage for next_event_async
Browse files Browse the repository at this point in the history
  • Loading branch information
tnull committed Jan 4, 2024
1 parent 7da3722 commit 9e7c2b6
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,9 +833,10 @@ where
mod tests {
use super::*;
use lightning::util::test_utils::{TestLogger, TestStore};
use std::time::Duration;

#[test]
fn event_queue_persistence() {
#[tokio::test]
async fn event_queue_persistence() {
let store = Arc::new(TestStore::new(false));
let logger = Arc::new(TestLogger::new());
let event_queue = EventQueue::new(Arc::clone(&store), Arc::clone(&logger));
Expand All @@ -851,6 +852,7 @@ mod tests {
// Check we get the expected event and that it is returned until we mark it handled.
for _ in 0..5 {
assert_eq!(event_queue.wait_next_event(), expected_event);
assert_eq!(event_queue.next_event_async().await, expected_event);
assert_eq!(event_queue.next_event(), Some(expected_event.clone()));
}

Expand All @@ -868,5 +870,15 @@ mod tests {

event_queue.event_handled().unwrap();
assert_eq!(event_queue.next_event(), None);

// Check `next_event_async` won't return if the queue is empty and always rather timeout.
tokio::select! {
_ = tokio::time::sleep(Duration::from_secs(1)) => {
// Timeout
}
_ = event_queue.next_event_async() => {
panic!();
}
}
}
}

0 comments on commit 9e7c2b6

Please sign in to comment.