1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-24 00:21:08 +01:00

update tests; clippy warnings

This commit is contained in:
Nikolay Kim 2017-10-29 15:04:44 -07:00
parent 6b2248ecdf
commit 8ab04b39df
4 changed files with 49 additions and 48 deletions

View File

@ -141,8 +141,8 @@ impl<A> HttpContext<A> where A: Actor<Context=Self> + Route {
/// Returns drain future /// Returns drain future
pub fn drain(&mut self) -> Drain<A> { pub fn drain(&mut self) -> Drain<A> {
let fut = Rc::new(RefCell::new(DrainFut::new())); let fut = Rc::new(RefCell::new(DrainFut::default()));
self.stream.push_back(Frame::Drain(fut.clone())); self.stream.push_back(Frame::Drain(Rc::clone(&fut)));
self.modified = true; self.modified = true;
Drain{ a: PhantomData, inner: fut } Drain{ a: PhantomData, inner: fut }
} }

View File

@ -66,14 +66,17 @@ pub struct DrainFut {
task: Option<FutureTask>, task: Option<FutureTask>,
} }
impl DrainFut { impl Default for DrainFut {
pub fn new() -> DrainFut { fn default() -> DrainFut {
DrainFut { DrainFut {
drained: false, drained: false,
task: None, task: None,
} }
} }
}
impl DrainFut {
fn set(&mut self) { fn set(&mut self) {
self.drained = true; self.drained = true;
@ -319,8 +322,7 @@ impl Task {
// response is completed // response is completed
if self.frames.is_empty() && self.iostate.is_done() { if self.frames.is_empty() && self.iostate.is_done() {
return Ok(Async::Ready(self.state.is_done())); return Ok(Async::Ready(self.state.is_done()));
} else { } else if self.drain.is_empty() {
if self.drain.is_empty() {
// poll stream // poll stream
if self.state == TaskRunningState::Running { if self.state == TaskRunningState::Running {
match self.poll() { match self.poll() {
@ -369,7 +371,6 @@ impl Task {
} }
} }
} }
}
// write bytes to TcpStream // write bytes to TcpStream
if !self.disconnected { if !self.disconnected {

View File

@ -344,7 +344,7 @@ mod tests {
let req = HttpRequest::new(Method::GET, "/".to_owned(), let req = HttpRequest::new(Method::GET, "/".to_owned(),
Version::HTTP_11, HeaderMap::new(), String::new()); Version::HTTP_11, HeaderMap::new(), String::new());
match handshake(&req) { match handshake(&req) {
Err(err) => assert_eq!(err.status(), StatusCode::METHOD_NOT_ALLOWED), Err(err) => assert_eq!(err.status(), StatusCode::BAD_REQUEST),
_ => panic!("should not happen"), _ => panic!("should not happen"),
} }
@ -354,7 +354,7 @@ mod tests {
let req = HttpRequest::new(Method::GET, "/".to_owned(), let req = HttpRequest::new(Method::GET, "/".to_owned(),
Version::HTTP_11, headers, String::new()); Version::HTTP_11, headers, String::new());
match handshake(&req) { match handshake(&req) {
Err(err) => assert_eq!(err.status(), StatusCode::METHOD_NOT_ALLOWED), Err(err) => assert_eq!(err.status(), StatusCode::BAD_REQUEST),
_ => panic!("should not happen"), _ => panic!("should not happen"),
} }

View File

@ -73,7 +73,7 @@ fn test_request_query() {
assert_eq!(req.query_string(), "id=test"); assert_eq!(req.query_string(), "id=test");
let query = req.query(); let query = req.query();
assert_eq!(query.get("id").unwrap(), "test"); assert_eq!(&query["id"], "test");
} }
#[test] #[test]