cargo fmt

This commit is contained in:
Jon Gjengset 2019-09-11 10:30:41 -04:00
parent 87976ae418
commit 4c1df65a75
No known key found for this signature in database
GPG Key ID: FAEA8B761ADA5F4C
2 changed files with 31 additions and 24 deletions

View File

@ -62,9 +62,7 @@ where
Ok(Err(e)) => return Poll::Ready(Err(e.into())),
Err(_) => return Poll::Ready(Err(Closed::new().into())),
},
ResponseState::Poll(fut) => {
return fut.poll(cx).map_err(Into::into)
}
ResponseState::Poll(fut) => return fut.poll(cx).map_err(Into::into),
}
}
}

View File

@ -1,36 +1,41 @@
use futures_util::{
future::{poll_fn, Ready},
pin_mut,
};
use std::time::Duration;
use futures_util::{pin_mut, future::{Ready, poll_fn}};
use tower::builder::ServiceBuilder;
use tower::util::ServiceExt;
use tower_buffer::BufferLayer;
use tower_limit::{concurrency::ConcurrencyLimitLayer, rate::RateLimitLayer};
use tower_retry::{Policy, RetryLayer};
use tower_service::*;
use tower_test::{mock};
use tower_test::mock;
#[tokio::test]
async fn builder_service() {
let (service, handle) = mock::pair();
pin_mut!(handle);
let (service, handle) = mock::pair();
pin_mut!(handle);
let policy = MockPolicy;
let client = ServiceBuilder::new()
.layer(BufferLayer::new(5))
.layer(ConcurrencyLimitLayer::new(5))
.layer(RateLimitLayer::new(5, Duration::from_secs(1)))
.layer(RetryLayer::new(policy))
.layer(BufferLayer::new(5))
.service(service);
let policy = MockPolicy;
let client = ServiceBuilder::new()
.layer(BufferLayer::new(5))
.layer(ConcurrencyLimitLayer::new(5))
.layer(RateLimitLayer::new(5, Duration::from_secs(1)))
.layer(RetryLayer::new(policy))
.layer(BufferLayer::new(5))
.service(service);
// allow a request through
handle.allow(1);
// allow a request through
handle.allow(1);
let mut client = client.ready().await.unwrap();
let fut = client.call("hello");
let (request, rsp) = poll_fn(|cx| handle.as_mut().poll_request(cx)).await.unwrap();
assert_eq!(request, "hello");
rsp.send_response("world");
assert_eq!(fut.await.unwrap(), "world");
let mut client = client.ready().await.unwrap();
let fut = client.call("hello");
let (request, rsp) = poll_fn(|cx| handle.as_mut().poll_request(cx))
.await
.unwrap();
assert_eq!(request, "hello");
rsp.send_response("world");
assert_eq!(fut.await.unwrap(), "world");
}
#[derive(Debug, Clone)]
@ -42,7 +47,11 @@ where
{
type Future = Ready<Self>;
fn retry(&self, _req: &&'static str, _result: Result<&&'static str, &E>) -> Option<Self::Future> {
fn retry(
&self,
_req: &&'static str,
_result: Result<&&'static str, &E>,
) -> Option<Self::Future> {
None
}