add test for waker

This commit is contained in:
fakeshadow 2021-04-25 22:12:40 -07:00
parent c0208cc69e
commit 8abd8e66d6
1 changed files with 34 additions and 0 deletions

View File

@ -90,3 +90,37 @@ pub(crate) fn waker_channel() -> (WakerTx, WakerRx) {
(WakerTx(tx), WakerRx(rx)) (WakerTx(tx), WakerRx(rx))
} }
#[cfg(test)]
mod test {
use std::task::{Context, Poll};
use super::*;
#[test]
fn test_waker_channel() {
let poll = mio::Poll::new().unwrap();
let waker = from_registry(poll.registry()).unwrap();
let cx = &mut Context::from_waker(&waker);
let (tx, mut rx) = waker_channel();
assert!(rx.poll_recv(cx).is_pending());
tx.wake(super::WakerInterest::Stop);
match rx.poll_recv(cx) {
Poll::Ready(Some(WakerInterest::Stop)) => {}
_ => panic!("Failed to wake up WakerRx"),
}
drop(tx);
match rx.poll_recv(cx) {
Poll::Ready(None) => {}
_ => panic!("Failed to close waker channel"),
}
}
}