Fix benches

This commit is contained in:
Igor Aleksanov 2021-06-22 19:54:12 +03:00
parent 7d61da0302
commit 54fa4e4e27
2 changed files with 7 additions and 10 deletions

View File

@ -1,6 +1,5 @@
use std::{future::Future, time::Instant}; use std::{future::Future, time::Instant};
use actix_http::Response;
use actix_utils::future::{ready, Ready}; use actix_utils::future::{ready, Ready};
use actix_web::http::StatusCode; use actix_web::http::StatusCode;
use actix_web::test::TestRequest; use actix_web::test::TestRequest;
@ -24,11 +23,11 @@ struct StringResponder(String);
impl FutureResponder for StringResponder { impl FutureResponder for StringResponder {
type Error = Error; type Error = Error;
type Future = Ready<Result<Response, Self::Error>>; type Future = Ready<Result<HttpResponse, Self::Error>>;
fn future_respond_to(self, _: &HttpRequest) -> Self::Future { fn future_respond_to(self, _: &HttpRequest) -> Self::Future {
// this is default builder for string response in both new and old responder trait. // this is default builder for string response in both new and old responder trait.
ready(Ok(Response::build(StatusCode::OK) ready(Ok(HttpResponse::build(StatusCode::OK)
.content_type("text/plain; charset=utf-8") .content_type("text/plain; charset=utf-8")
.body(self.0))) .body(self.0)))
} }
@ -37,7 +36,7 @@ impl FutureResponder for StringResponder {
impl<T> FutureResponder for OptionResponder<T> impl<T> FutureResponder for OptionResponder<T>
where where
T: FutureResponder, T: FutureResponder,
T::Future: Future<Output = Result<Response, Error>>, T::Future: Future<Output = Result<HttpResponse, Error>>,
{ {
type Error = Error; type Error = Error;
type Future = Either<T::Future, Ready<Result<HttpResponse, Self::Error>>>; type Future = Either<T::Future, Ready<Result<HttpResponse, Self::Error>>>;
@ -52,7 +51,7 @@ where
impl Responder for StringResponder { impl Responder for StringResponder {
fn respond_to(self, _: &HttpRequest) -> HttpResponse { fn respond_to(self, _: &HttpRequest) -> HttpResponse {
Response::build(StatusCode::OK) HttpResponse::build(StatusCode::OK)
.content_type("text/plain; charset=utf-8") .content_type("text/plain; charset=utf-8")
.body(self.0) .body(self.0)
} }
@ -62,7 +61,7 @@ impl<T: Responder> Responder for OptionResponder<T> {
fn respond_to(self, req: &HttpRequest) -> HttpResponse { fn respond_to(self, req: &HttpRequest) -> HttpResponse {
match self.0 { match self.0 {
Some(t) => t.respond_to(req), Some(t) => t.respond_to(req),
None => Response::from_error(error::ErrorInternalServerError("err")), None => HttpResponse::from_error(error::ErrorInternalServerError("err")),
} }
} }
} }

View File

@ -51,9 +51,8 @@ where
fut.await.unwrap(); fut.await.unwrap();
} }
}); });
let elapsed = start.elapsed();
// check that at least first request succeeded // check that at least first request succeeded
elapsed start.elapsed()
}) })
}); });
} }
@ -93,9 +92,8 @@ fn async_web_service(c: &mut Criterion) {
fut.await.unwrap(); fut.await.unwrap();
} }
}); });
let elapsed = start.elapsed();
// check that at least first request succeeded // check that at least first request succeeded
elapsed start.elapsed()
}) })
}); });
} }