mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-24 07:53:00 +01:00
tests for Completed state
This commit is contained in:
parent
97bed17fd2
commit
186726fbad
@ -887,13 +887,15 @@ mod tests {
|
||||
use super::*;
|
||||
use actix::*;
|
||||
use context::HttpContext;
|
||||
use tokio_core::reactor::Core;
|
||||
use futures::future::{lazy, result};
|
||||
|
||||
impl PipelineState {
|
||||
fn is_none(&self) -> Option<bool> {
|
||||
if let PipelineState::None = *self { Some(true) } else { None }
|
||||
}
|
||||
fn is_completed(&self) -> Option<bool> {
|
||||
if let PipelineState::Completed(_) = *self { Some(true) } else { None }
|
||||
fn completed(self) -> Option<Completed> {
|
||||
if let PipelineState::Completed(c) = self { Some(c) } else { None }
|
||||
}
|
||||
}
|
||||
|
||||
@ -904,13 +906,26 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_completed() {
|
||||
Core::new().unwrap().run(lazy(|| {
|
||||
let info = Box::new(PipelineInfo::new(HttpRequest::default()));
|
||||
Completed::init(info).is_none().unwrap();
|
||||
|
||||
let req = HttpRequest::default();
|
||||
let ctx = HttpContext::new(req.clone(), MyActor);
|
||||
let mut ctx = HttpContext::new(req.clone(), MyActor);
|
||||
let addr: Address<_> = ctx.address();
|
||||
let mut info = Box::new(PipelineInfo::new(req));
|
||||
info.context = Some(Box::new(ctx));
|
||||
Completed::init(info).is_completed().unwrap();
|
||||
let mut state = Completed::init(info).completed().unwrap();
|
||||
|
||||
let st = state.poll().ok().unwrap();
|
||||
assert!(!st.is_done());
|
||||
|
||||
state = st.completed().unwrap();
|
||||
drop(addr);
|
||||
|
||||
state.poll().ok().unwrap().is_none().unwrap();
|
||||
|
||||
result(Ok::<_, ()>(()))
|
||||
})).unwrap()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user