mirror of https://github.com/fafhrd91/actix-net
add test for waker
This commit is contained in:
parent
c0208cc69e
commit
8abd8e66d6
|
@ -90,3 +90,37 @@ pub(crate) fn waker_channel() -> (WakerTx, WakerRx) {
|
|||
|
||||
(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"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue