mirror of
https://github.com/actix/actix-web.git
synced 2025-01-03 13:58:44 +00:00
tests for Completed state
This commit is contained in:
parent
97bed17fd2
commit
186726fbad
1 changed files with 24 additions and 9 deletions
|
@ -887,13 +887,15 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use actix::*;
|
use actix::*;
|
||||||
use context::HttpContext;
|
use context::HttpContext;
|
||||||
|
use tokio_core::reactor::Core;
|
||||||
|
use futures::future::{lazy, result};
|
||||||
|
|
||||||
impl PipelineState {
|
impl PipelineState {
|
||||||
fn is_none(&self) -> Option<bool> {
|
fn is_none(&self) -> Option<bool> {
|
||||||
if let PipelineState::None = *self { Some(true) } else { None }
|
if let PipelineState::None = *self { Some(true) } else { None }
|
||||||
}
|
}
|
||||||
fn is_completed(&self) -> Option<bool> {
|
fn completed(self) -> Option<Completed> {
|
||||||
if let PipelineState::Completed(_) = *self { Some(true) } else { None }
|
if let PipelineState::Completed(c) = self { Some(c) } else { None }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -904,13 +906,26 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_completed() {
|
fn test_completed() {
|
||||||
let info = Box::new(PipelineInfo::new(HttpRequest::default()));
|
Core::new().unwrap().run(lazy(|| {
|
||||||
Completed::init(info).is_none().unwrap();
|
let info = Box::new(PipelineInfo::new(HttpRequest::default()));
|
||||||
|
Completed::init(info).is_none().unwrap();
|
||||||
|
|
||||||
let req = HttpRequest::default();
|
let req = HttpRequest::default();
|
||||||
let ctx = HttpContext::new(req.clone(), MyActor);
|
let mut ctx = HttpContext::new(req.clone(), MyActor);
|
||||||
let mut info = Box::new(PipelineInfo::new(req));
|
let addr: Address<_> = ctx.address();
|
||||||
info.context = Some(Box::new(ctx));
|
let mut info = Box::new(PipelineInfo::new(req));
|
||||||
Completed::init(info).is_completed().unwrap();
|
info.context = Some(Box::new(ctx));
|
||||||
|
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 a new issue