step 2: make all the tests work again
This commit is contained in:
parent
8df2a3e410
commit
c4d70b535b
|
@ -24,9 +24,9 @@ edition = "2018"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
futures-util = { version = "0.3", default-features = false }
|
futures-util = { version = "0.3", default-features = false }
|
||||||
tokio = { version = "0.2", features = ["sync"]}
|
tokio = { version = "0.2", features = ["sync"]}
|
||||||
tower-layer = "0.3"
|
tower-layer = { version = "0.3", path = "../tower-layer" }
|
||||||
tokio-test = "0.2"
|
tokio-test = "0.2"
|
||||||
tower-service = "0.3"
|
tower-service = { version = "0.3", path = "../tower-service" }
|
||||||
pin-project = "0.4"
|
pin-project = "0.4"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
|
use crate::discover::ServiceList;
|
||||||
|
use crate::load;
|
||||||
use futures_util::pin_mut;
|
use futures_util::pin_mut;
|
||||||
use std::task::Poll;
|
use std::task::Poll;
|
||||||
use tokio_test::{assert_pending, assert_ready, assert_ready_ok, task};
|
use tokio_test::{assert_pending, assert_ready, assert_ready_ok, task};
|
||||||
use tower_discover::ServiceList;
|
|
||||||
use tower_load as load;
|
|
||||||
use tower_test::{assert_request_eq, mock};
|
use tower_test::{assert_request_eq, mock};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
use crate::load;
|
||||||
use futures_util::pin_mut;
|
use futures_util::pin_mut;
|
||||||
use tokio_test::{assert_pending, assert_ready, assert_ready_ok, task};
|
use tokio_test::{assert_pending, assert_ready, assert_ready_ok, task};
|
||||||
use tower_load as load;
|
|
||||||
use tower_test::{assert_request_eq, mock};
|
use tower_test::{assert_request_eq, mock};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
@ -29,8 +29,11 @@ use std::fmt;
|
||||||
/// `service` will be last to see the request.
|
/// `service` will be last to see the request.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
|
/// # // this (and other) doctest is ignored because we don't have a way
|
||||||
|
/// # // to say that it should only be run with cfg(feature = "...")
|
||||||
/// # use tower::Service;
|
/// # use tower::Service;
|
||||||
/// # use tower::builder::ServiceBuilder;
|
/// # use tower::builder::ServiceBuilder;
|
||||||
|
/// #[cfg(all(feature = "buffer", feature = "limit"))]
|
||||||
/// # async fn wrap<S>(svc: S) where S: Service<(), Error = &'static str> + 'static + Send, S::Future: Send {
|
/// # async fn wrap<S>(svc: S) where S: Service<(), Error = &'static str> + 'static + Send, S::Future: Send {
|
||||||
/// ServiceBuilder::new()
|
/// ServiceBuilder::new()
|
||||||
/// .buffer(100)
|
/// .buffer(100)
|
||||||
|
@ -49,6 +52,7 @@ use std::fmt;
|
||||||
/// ```
|
/// ```
|
||||||
/// # use tower::Service;
|
/// # use tower::Service;
|
||||||
/// # use tower::builder::ServiceBuilder;
|
/// # use tower::builder::ServiceBuilder;
|
||||||
|
/// #[cfg(all(feature = "buffer", feature = "limit"))]
|
||||||
/// # async fn wrap<S>(svc: S) where S: Service<(), Error = &'static str> + 'static + Send, S::Future: Send {
|
/// # async fn wrap<S>(svc: S) where S: Service<(), Error = &'static str> + 'static + Send, S::Future: Send {
|
||||||
/// ServiceBuilder::new()
|
/// ServiceBuilder::new()
|
||||||
/// .concurrency_limit(10)
|
/// .concurrency_limit(10)
|
||||||
|
@ -69,7 +73,9 @@ use std::fmt;
|
||||||
/// ```
|
/// ```
|
||||||
/// # use tower::Service;
|
/// # use tower::Service;
|
||||||
/// # use tower::builder::ServiceBuilder;
|
/// # use tower::builder::ServiceBuilder;
|
||||||
/// # use tower_limit::concurrency::ConcurrencyLimitLayer;
|
/// # #[cfg(feature = "limit")]
|
||||||
|
/// # use tower::limit::concurrency::ConcurrencyLimitLayer;
|
||||||
|
/// #[cfg(feature = "limit")]
|
||||||
/// # async fn wrap<S>(svc: S) where S: Service<(), Error = &'static str> + 'static + Send, S::Future: Send {
|
/// # async fn wrap<S>(svc: S) where S: Service<(), Error = &'static str> + 'static + Send, S::Future: Send {
|
||||||
/// ServiceBuilder::new()
|
/// ServiceBuilder::new()
|
||||||
/// .concurrency_limit(5)
|
/// .concurrency_limit(5)
|
||||||
|
@ -85,6 +91,7 @@ use std::fmt;
|
||||||
/// # use tower::Service;
|
/// # use tower::Service;
|
||||||
/// # use tower::builder::ServiceBuilder;
|
/// # use tower::builder::ServiceBuilder;
|
||||||
/// # use std::time::Duration;
|
/// # use std::time::Duration;
|
||||||
|
/// #[cfg(all(feature = "buffer", feature = "limit"))]
|
||||||
/// # async fn wrap<S>(svc: S) where S: Service<(), Error = &'static str> + 'static + Send, S::Future: Send {
|
/// # async fn wrap<S>(svc: S) where S: Service<(), Error = &'static str> + 'static + Send, S::Future: Send {
|
||||||
/// ServiceBuilder::new()
|
/// ServiceBuilder::new()
|
||||||
/// .buffer(5)
|
/// .buffer(5)
|
||||||
|
|
|
@ -19,11 +19,11 @@ pub mod buffer;
|
||||||
#[cfg(feature = "discover")]
|
#[cfg(feature = "discover")]
|
||||||
pub mod discover;
|
pub mod discover;
|
||||||
#[cfg(feature = "filter")]
|
#[cfg(feature = "filter")]
|
||||||
#[allow(unreachable_pub)]
|
#[doc(hidden)] // not yet released
|
||||||
pub(crate) mod filter;
|
pub mod filter;
|
||||||
#[cfg(feature = "hedge")]
|
#[cfg(feature = "hedge")]
|
||||||
#[allow(unreachable_pub)]
|
#[doc(hidden)] // not yet released
|
||||||
pub(crate) mod hedge;
|
pub mod hedge;
|
||||||
#[cfg(feature = "limit")]
|
#[cfg(feature = "limit")]
|
||||||
pub mod limit;
|
pub mod limit;
|
||||||
#[cfg(feature = "load")]
|
#[cfg(feature = "load")]
|
||||||
|
|
|
@ -5,7 +5,7 @@ use std::future::Future;
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use tower_retry::Policy;
|
/// use tower::retry::Policy;
|
||||||
/// use futures_util::future;
|
/// use futures_util::future;
|
||||||
///
|
///
|
||||||
/// type Req = String;
|
/// type Req = String;
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
//! ```
|
//! ```
|
||||||
//! use futures_util::future::ready;
|
//! use futures_util::future::ready;
|
||||||
//! # use tower_service::Service;
|
//! # use tower_service::Service;
|
||||||
//! # use tower_util::{BoxService, service_fn};
|
//! # use tower::util::{BoxService, service_fn};
|
||||||
//! // Respond to requests using a closure, but closures cannot be named...
|
//! // Respond to requests using a closure, but closures cannot be named...
|
||||||
//! # pub fn main() {
|
//! # pub fn main() {
|
||||||
//! let svc = service_fn(|mut request: String| {
|
//! let svc = service_fn(|mut request: String| {
|
||||||
|
|
|
@ -23,7 +23,7 @@ use tower_service::Service;
|
||||||
/// use futures_util::future::{ready, Ready};
|
/// use futures_util::future::{ready, Ready};
|
||||||
/// use futures_util::StreamExt;
|
/// use futures_util::StreamExt;
|
||||||
/// use tower_service::Service;
|
/// use tower_service::Service;
|
||||||
/// use tower_util::ServiceExt;
|
/// use tower::util::ServiceExt;
|
||||||
/// use tokio::prelude::*;
|
/// use tokio::prelude::*;
|
||||||
///
|
///
|
||||||
/// // First, we need to have a Service to process our requests.
|
/// // First, we need to have a Service to process our requests.
|
||||||
|
|
|
@ -75,7 +75,6 @@ pub trait ServiceExt<Request>: tower_service::Service<Request> {
|
||||||
///
|
///
|
||||||
/// This is essentially `Stream<Item = Request>` + `Self` => `Stream<Item = Response>`. See the
|
/// This is essentially `Stream<Item = Request>` + `Self` => `Stream<Item = Response>`. See the
|
||||||
/// documentation for [`CallAll`](struct.CallAll.html) for details.
|
/// documentation for [`CallAll`](struct.CallAll.html) for details.
|
||||||
#[cfg(feature = "call-all")]
|
|
||||||
fn call_all<S>(self, reqs: S) -> CallAll<Self, S>
|
fn call_all<S>(self, reqs: S) -> CallAll<Self, S>
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
|
#![cfg(feature = "balance")]
|
||||||
|
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
use tokio_test::{assert_pending, assert_ready, task};
|
use tokio_test::{assert_pending, assert_ready, task};
|
||||||
use tower_balance::p2c::Balance;
|
use tower::balance::p2c::Balance;
|
||||||
use tower_discover::{Change, ServiceStream};
|
use tower::discover::{Change, ServiceStream};
|
||||||
use tower_service::Service;
|
use tower_service::Service;
|
||||||
use tower_test::mock;
|
use tower_test::mock;
|
||||||
|
|
||||||
|
@ -21,7 +23,7 @@ impl Service<Req> for Mock {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl tower_load::Load for Mock {
|
impl tower::load::Load for Mock {
|
||||||
type Metric = usize;
|
type Metric = usize;
|
||||||
fn load(&self) -> Self::Metric {
|
fn load(&self) -> Self::Metric {
|
||||||
rand::random()
|
rand::random()
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
|
#![cfg(feature = "buffer")]
|
||||||
|
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use tokio_test::{assert_pending, assert_ready, assert_ready_err, assert_ready_ok, task};
|
use tokio_test::{assert_pending, assert_ready, assert_ready_err, assert_ready_ok, task};
|
||||||
use tower_buffer::{error, Buffer};
|
use tower::buffer::{error, Buffer};
|
||||||
use tower_test::{assert_request_eq, mock};
|
use tower_test::{assert_request_eq, mock};
|
||||||
|
|
||||||
fn let_worker_work() {
|
fn let_worker_work() {
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
|
#![cfg(all(feature = "buffer", feature = "limit", feature = "retry"))]
|
||||||
|
|
||||||
use futures_util::{future::Ready, pin_mut};
|
use futures_util::{future::Ready, pin_mut};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
use tower::buffer::BufferLayer;
|
||||||
use tower::builder::ServiceBuilder;
|
use tower::builder::ServiceBuilder;
|
||||||
|
use tower::limit::{concurrency::ConcurrencyLimitLayer, rate::RateLimitLayer};
|
||||||
|
use tower::retry::{Policy, RetryLayer};
|
||||||
use tower::util::ServiceExt;
|
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_service::*;
|
||||||
use tower_test::{assert_request_eq, mock};
|
use tower_test::{assert_request_eq, mock};
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
|
#![cfg(feature = "filter")]
|
||||||
|
|
||||||
use futures_util::{future::poll_fn, pin_mut};
|
use futures_util::{future::poll_fn, pin_mut};
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use tower_filter::{error::Error, Filter};
|
use tower::filter::{error::Error, Filter};
|
||||||
use tower_service::Service;
|
use tower_service::Service;
|
||||||
use tower_test::{assert_request_eq, mock};
|
use tower_test::{assert_request_eq, mock};
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
|
#![cfg(feature = "hedge")]
|
||||||
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tokio::time;
|
use tokio::time;
|
||||||
use tokio_test::{assert_pending, assert_ready, assert_ready_ok, task};
|
use tokio_test::{assert_pending, assert_ready, assert_ready_ok, task};
|
||||||
use tower_hedge::{Hedge, Policy};
|
use tower::hedge::{Hedge, Policy};
|
||||||
use tower_test::{assert_request_eq, mock};
|
use tower_test::{assert_request_eq, mock};
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
@ -143,7 +145,7 @@ static NOT_CLONABLE: &'static str = "NOT_CLONABLE";
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct TestPolicy;
|
struct TestPolicy;
|
||||||
|
|
||||||
impl tower_hedge::Policy<Req> for TestPolicy {
|
impl tower::hedge::Policy<Req> for TestPolicy {
|
||||||
fn can_retry(&self, req: &Req) -> bool {
|
fn can_retry(&self, req: &Req) -> bool {
|
||||||
*req != NOT_RETRYABLE
|
*req != NOT_RETRYABLE
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use tokio_test::{assert_pending, assert_ready, assert_ready_ok};
|
use tokio_test::{assert_pending, assert_ready, assert_ready_ok};
|
||||||
use tower_limit::concurrency::ConcurrencyLimitLayer;
|
use tower::limit::concurrency::ConcurrencyLimitLayer;
|
||||||
use tower_test::{assert_request_eq, mock};
|
use tower_test::{assert_request_eq, mock};
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|
|
@ -1,2 +1,4 @@
|
||||||
|
#![cfg(feature = "limit")]
|
||||||
|
|
||||||
mod concurrency;
|
mod concurrency;
|
||||||
mod rate;
|
mod rate;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tokio::time;
|
use tokio::time;
|
||||||
use tokio_test::{assert_pending, assert_ready, assert_ready_ok};
|
use tokio_test::{assert_pending, assert_ready, assert_ready_ok};
|
||||||
use tower_limit::rate::RateLimitLayer;
|
use tower::limit::rate::RateLimitLayer;
|
||||||
use tower_test::{assert_request_eq, mock};
|
use tower_test::{assert_request_eq, mock};
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
|
#![cfg(feature = "load-shed")]
|
||||||
|
|
||||||
use tokio_test::{assert_ready_err, assert_ready_ok, task};
|
use tokio_test::{assert_ready_err, assert_ready_ok, task};
|
||||||
use tower_load_shed::LoadShedLayer;
|
use tower::load_shed::LoadShedLayer;
|
||||||
use tower_test::{assert_request_eq, mock};
|
use tower_test::{assert_request_eq, mock};
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
@ -27,5 +29,5 @@ async fn when_not_ready() {
|
||||||
let mut fut = task::spawn(service.call("hello"));
|
let mut fut = task::spawn(service.call("hello"));
|
||||||
|
|
||||||
let err = assert_ready_err!(fut.poll());
|
let err = assert_ready_err!(fut.poll());
|
||||||
assert!(err.is::<tower_load_shed::error::Overloaded>());
|
assert!(err.is::<tower::load_shed::error::Overloaded>());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
|
#![cfg(feature = "ready-cache")]
|
||||||
|
|
||||||
use tokio_test::{assert_pending, assert_ready, task};
|
use tokio_test::{assert_pending, assert_ready, task};
|
||||||
use tower_ready_cache::ReadyCache;
|
use tower::ready_cache::ReadyCache;
|
||||||
use tower_test::mock;
|
use tower_test::mock;
|
||||||
|
|
||||||
type Req = &'static str;
|
type Req = &'static str;
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
|
#![cfg(feature = "retry")]
|
||||||
|
|
||||||
use futures_util::future;
|
use futures_util::future;
|
||||||
use tokio_test::{assert_pending, assert_ready_err, assert_ready_ok, task};
|
use tokio_test::{assert_pending, assert_ready_err, assert_ready_ok, task};
|
||||||
use tower_retry::Policy;
|
use tower::retry::Policy;
|
||||||
use tower_test::{assert_request_eq, mock};
|
use tower_test::{assert_request_eq, mock};
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
@ -155,7 +157,7 @@ impl Policy<Req, Res, Error> for CannotClone {
|
||||||
|
|
||||||
fn new_service<P: Policy<Req, Res, Error> + Clone>(
|
fn new_service<P: Policy<Req, Res, Error> + Clone>(
|
||||||
policy: P,
|
policy: P,
|
||||||
) -> (mock::Spawn<tower_retry::Retry<P, Mock>>, Handle) {
|
) -> (mock::Spawn<tower::retry::Retry<P, Mock>>, Handle) {
|
||||||
let retry = tower_retry::RetryLayer::new(policy);
|
let retry = tower::retry::RetryLayer::new(policy);
|
||||||
mock::spawn_layer(retry)
|
mock::spawn_layer(retry)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
|
#![cfg(feature = "spawn-ready")]
|
||||||
|
|
||||||
use std::{thread, time::Duration};
|
use std::{thread, time::Duration};
|
||||||
use tokio_test::{assert_pending, assert_ready, assert_ready_err, assert_ready_ok};
|
use tokio_test::{assert_pending, assert_ready, assert_ready_err, assert_ready_ok};
|
||||||
use tower_spawn_ready::SpawnReadyLayer;
|
use tower::spawn_ready::SpawnReadyLayer;
|
||||||
use tower_test::mock;
|
use tower_test::mock;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|
|
@ -6,9 +6,9 @@ use futures_util::{
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
use std::{cell::Cell, rc::Rc};
|
use std::{cell::Cell, rc::Rc};
|
||||||
use tokio_test::{assert_pending, assert_ready, task};
|
use tokio_test::{assert_pending, assert_ready, task};
|
||||||
|
use tower::util::ServiceExt;
|
||||||
use tower_service::*;
|
use tower_service::*;
|
||||||
use tower_test::{assert_request_eq, mock};
|
use tower_test::{assert_request_eq, mock};
|
||||||
use tower_util::ServiceExt;
|
|
||||||
|
|
||||||
type Error = Box<dyn std::error::Error + Send + Sync>;
|
type Error = Box<dyn std::error::Error + Send + Sync>;
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,4 @@
|
||||||
|
#![cfg(feature = "util")]
|
||||||
|
|
||||||
mod call_all;
|
mod call_all;
|
||||||
mod service_fn;
|
mod service_fn;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use futures_util::future::ready;
|
use futures_util::future::ready;
|
||||||
|
use tower::util::service_fn;
|
||||||
use tower_service::Service;
|
use tower_service::Service;
|
||||||
use tower_util::service_fn;
|
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn simple() {
|
async fn simple() {
|
||||||
|
|
Loading…
Reference in New Issue