Skip to content

Commit

Permalink
test: add test for poll_future
Browse files Browse the repository at this point in the history
  • Loading branch information
spacemeowx2 committed Sep 5, 2023
1 parent 3f06216 commit 6fc946a
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions rd-std/src/util/poll_future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,43 @@ impl<T> PollFuture<T> {
}
}
}

#[cfg(test)]
mod tests {
use tokio::sync::mpsc;

use super::*;

#[test]
fn test_poll_future() {
let (tx, mut rx) = mpsc::unbounded_channel::<()>();
let mut fut = PollFuture::new(async move {
rx.recv().await;
1
});

assert!(!fut.is_ready());
assert_eq!(
fut.poll(&mut Context::from_waker(futures::task::noop_waker_ref())),
Poll::Pending
);
assert!(!fut.is_ready());
tx.send(()).unwrap();
assert_eq!(
fut.poll(&mut Context::from_waker(futures::task::noop_waker_ref())),
Poll::Ready(1)
);
assert!(fut.is_ready());
}

#[test]
fn test_poll_future_ready() {
let mut fut = PollFuture::ready(1);
assert!(fut.is_ready());
assert_eq!(
fut.poll(&mut Context::from_waker(futures::task::noop_waker_ref())),
Poll::Ready(1)
);
assert!(fut.is_ready());
}
}

0 comments on commit 6fc946a

Please sign in to comment.