Update `tower` and `tower-util` and prep for release (#378)

* Update tower and tower-util

* Prepare them for release

* fmt

* Get tower tests working
This commit is contained in:
Lucio Franco 2019-12-04 22:48:43 -05:00 committed by GitHub
parent 54dd475ec0
commit 0d2a3778ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 90 additions and 84 deletions

View File

@ -1,7 +1,7 @@
[workspace]
members = [
# "tower",
"tower",
# "tower-balance",
"tower-buffer",
# "tower-discover",
@ -19,5 +19,5 @@ members = [
"tower-test",
"tower-timeout",
"tower-make",
# "tower-util",
"tower-util",
]

View File

@ -1,3 +1,9 @@
# 0.3.0 (December 4, 2019)
- Update to `tower-serivce 0.3`
- Update to `futures 0.3`
- Update to `tokio 0.2`
# 0.3.0-alpha.2 (September 30, 2019)
- Move to `futures-*-preview 0.3.0-alpha.19`

View File

@ -9,7 +9,7 @@ name = "tower-util"
# - README.md
# - Update CHANGELOG.md.
# - Create "v0.3.x" git tag.
version = "0.3.0-alpha.2"
version = "0.3.0"
authors = ["Tower Maintainers <team@tower-rs.com>"]
license = "MIT"
readme = "README.md"
@ -23,15 +23,14 @@ categories = ["asynchronous", "network-programming"]
edition = "2018"
[dependencies]
tower-service = { version = "=0.3.0-alpha.2", path = "../tower-service" }
tower-layer = { version = "=0.3.0-alpha.2", path = "../tower-layer" }
tower-service = { version = "0.3", path = "../tower-service" }
tower-layer = { version = "0.3", path = "../tower-layer" }
pin-project = "0.4"
futures-util-preview = "=0.3.0-alpha.19"
futures-core-preview = "=0.3.0-alpha.19"
futures-util = "0.3"
futures-core = "0.3"
[dev-dependencies]
futures-util-preview = "=0.3.0-alpha.19"
tokio-test = "=0.2.0-alpha.6"
tokio = "=0.2.0-alpha.6"
tower = { version = "=0.3.0-alpha.2", path = "../tower" }
tower-test = { version = "=0.3.0-alpha.2", path = "../tower-test" }
tokio-test = "0.2"
tokio = { version = "0.2", features = ["stream", "sync", "macros"] }
tower = { version = "0.3", path = "../tower" }
tower-test = { version = "0.3", path = "../tower-test" }

View File

@ -21,6 +21,7 @@ use tower_service::Service;
/// # use std::rc::Rc;
/// #
/// use futures_util::future::{ready, Ready};
/// use futures_util::StreamExt;
/// use tower_service::Service;
/// use tower::ServiceExt;
/// use tokio::prelude::*;
@ -51,9 +52,9 @@ use tower_service::Service;
/// let mut rsps = FirstLetter.call_all(rx);
///
/// // Now, let's send a few requests and then check that we get the corresponding responses.
/// reqs.try_send("one");
/// reqs.try_send("two");
/// reqs.try_send("three");
/// reqs.send("one");
/// reqs.send("two");
/// reqs.send("three");
/// drop(reqs);
///
/// // We then loop over the response Strem that we get back from call_all.

View File

@ -1,4 +1,4 @@
#![doc(html_root_url = "https://docs.rs/tower-util/0.3.0-alpha.2")]
#![doc(html_root_url = "https://docs.rs/tower-util/0.3.0")]
#![warn(
missing_debug_implementations,
missing_docs,

View File

@ -39,7 +39,7 @@ impl Service<&'static str> for Srv {
#[test]
fn ordered() {
let mut mock = task::MockTask::new();
let mut mock = task::spawn(());
let admit = Rc::new(Cell::new(false));
let count = Rc::new(Cell::new(0));
@ -47,44 +47,44 @@ fn ordered() {
count: count.clone(),
admit: admit.clone(),
};
let (mut tx, rx) = tokio::sync::mpsc::unbounded_channel();
let (tx, rx) = tokio::sync::mpsc::unbounded_channel();
let ca = srv.call_all(rx);
pin_mut!(ca);
assert_pending!(mock.enter(|cx| ca.as_mut().poll_next(cx)));
tx.try_send("one").unwrap();
assert_pending!(mock.enter(|cx, _| ca.as_mut().poll_next(cx)));
tx.send("one").unwrap();
mock.is_woken();
assert_pending!(mock.enter(|cx| ca.as_mut().poll_next(cx)));
assert_pending!(mock.enter(|cx, _| ca.as_mut().poll_next(cx)));
admit.set(true);
let v = assert_ready!(mock.enter(|cx| ca.as_mut().poll_next(cx)))
let v = assert_ready!(mock.enter(|cx, _| ca.as_mut().poll_next(cx)))
.transpose()
.unwrap();
assert_eq!(v, Some("one"));
assert_pending!(mock.enter(|cx| ca.as_mut().poll_next(cx)));
assert_pending!(mock.enter(|cx, _| ca.as_mut().poll_next(cx)));
admit.set(true);
tx.try_send("two").unwrap();
tx.send("two").unwrap();
mock.is_woken();
tx.try_send("three").unwrap();
let v = assert_ready!(mock.enter(|cx| ca.as_mut().poll_next(cx)))
tx.send("three").unwrap();
let v = assert_ready!(mock.enter(|cx, _| ca.as_mut().poll_next(cx)))
.transpose()
.unwrap();
assert_eq!(v, Some("two"));
assert_pending!(mock.enter(|cx| ca.as_mut().poll_next(cx)));
assert_pending!(mock.enter(|cx, _| ca.as_mut().poll_next(cx)));
admit.set(true);
let v = assert_ready!(mock.enter(|cx| ca.as_mut().poll_next(cx)))
let v = assert_ready!(mock.enter(|cx, _| ca.as_mut().poll_next(cx)))
.transpose()
.unwrap();
assert_eq!(v, Some("three"));
admit.set(true);
assert_pending!(mock.enter(|cx| ca.as_mut().poll_next(cx)));
assert_pending!(mock.enter(|cx, _| ca.as_mut().poll_next(cx)));
admit.set(true);
tx.try_send("four").unwrap();
tx.send("four").unwrap();
mock.is_woken();
let v = assert_ready!(mock.enter(|cx| ca.as_mut().poll_next(cx)))
let v = assert_ready!(mock.enter(|cx, _| ca.as_mut().poll_next(cx)))
.transpose()
.unwrap();
assert_eq!(v, Some("four"));
assert_pending!(mock.enter(|cx| ca.as_mut().poll_next(cx)));
assert_pending!(mock.enter(|cx, _| ca.as_mut().poll_next(cx)));
// need to be ready since impl doesn't know it'll get EOF
admit.set(true);
@ -92,7 +92,7 @@ fn ordered() {
// When we drop the request stream, CallAll should return None.
drop(tx);
mock.is_woken();
let v = assert_ready!(mock.enter(|cx| ca.as_mut().poll_next(cx)))
let v = assert_ready!(mock.enter(|cx, _| ca.as_mut().poll_next(cx)))
.transpose()
.unwrap();
assert!(v.is_none());
@ -108,38 +108,38 @@ fn ordered() {
);
}
#[test]
fn unordered() {
#[tokio::test]
async fn unordered() {
let (mock, handle) = mock::pair::<_, &'static str>();
pin_mut!(handle);
let mut task = task::MockTask::new();
let mut task = task::spawn(());
let requests = futures_util::stream::iter(&["one", "two"]);
let svc = mock.call_all(requests).unordered();
pin_mut!(svc);
assert_pending!(task.enter(|cx| svc.as_mut().poll_next(cx)));
assert_pending!(task.enter(|cx, _| svc.as_mut().poll_next(cx)));
let resp1 = assert_request_eq!(handle, &"one");
let resp2 = assert_request_eq!(handle, &"two");
resp2.send_response("resp 1");
let v = assert_ready!(task.enter(|cx| svc.as_mut().poll_next(cx)))
let v = assert_ready!(task.enter(|cx, _| svc.as_mut().poll_next(cx)))
.transpose()
.unwrap();
assert_eq!(v, Some("resp 1"));
assert_pending!(task.enter(|cx| svc.as_mut().poll_next(cx)));
assert_pending!(task.enter(|cx, _| svc.as_mut().poll_next(cx)));
resp1.send_response("resp 2");
let v = assert_ready!(task.enter(|cx| svc.as_mut().poll_next(cx)))
let v = assert_ready!(task.enter(|cx, _| svc.as_mut().poll_next(cx)))
.transpose()
.unwrap();
assert_eq!(v, Some("resp 2"));
let v = assert_ready!(task.enter(|cx| svc.as_mut().poll_next(cx)))
let v = assert_ready!(task.enter(|cx, _| svc.as_mut().poll_next(cx)))
.transpose()
.unwrap();
assert!(v.is_none());

View File

@ -1,11 +1,10 @@
use futures_util::future::ready;
use tokio_test::block_on;
use tower_service::Service;
use tower_util::service_fn;
#[test]
fn simple() {
#[tokio::test]
async fn simple() {
let mut add_one = service_fn(|req| ready(Ok::<_, ()>(req + 1)));
let answer = block_on(add_one.call(1)).unwrap();
let answer = add_one.call(1).await.unwrap();
assert_eq!(answer, 2);
}

View File

@ -1,3 +1,9 @@
# 0.3.0 (December 4, 2019)
- Update all tower based crates to `0.3`.
- Update to `tokio 0.2`
- Update to `futures 0.3`
# 0.3.0-alpha.2 (September 30, 2019)
- Move to `futures-*-preview 0.3.0-alpha.19`

View File

@ -8,7 +8,7 @@ name = "tower"
# - README.md
# - Update CHANGELOG.md.
# - Create "v0.1.x" git tag.
version = "0.3.0-alpha.2"
version = "0.3.0"
authors = ["Tower Maintainers <team@tower-rs.com>"]
license = "MIT"
readme = "README.md"
@ -28,20 +28,21 @@ default = ["full"]
full = []
[dependencies]
tower-buffer = { version = "=0.3.0-alpha.2", path = "../tower-buffer" }
tower-discover = { version = "=0.3.0-alpha.2", path = "../tower-discover" }
tower-layer = { version = "=0.3.0-alpha.2", path = "../tower-layer" }
tower-limit = { version = "=0.3.0-alpha.2", path = "../tower-limit" }
tower-load-shed = { version = "=0.3.0-alpha.2", path = "../tower-load-shed" }
tower-retry = { version = "=0.3.0-alpha.2", path = "../tower-retry" }
tower-service = { version = "=0.3.0-alpha.2", path = "../tower-service" }
tower-timeout = { version = "=0.3.0-alpha.2", path = "../tower-timeout" }
tower-util = { version = "=0.3.0-alpha.2", path = "../tower-util" }
futures-core-preview = "=0.3.0-alpha.19"
tower-buffer = { version = "0.3", path = "../tower-buffer" }
# tower-discover = { version = "0.3", path = "../tower-discover" }
tower-layer = { version = "0.3", path = "../tower-layer" }
tower-limit = { version = "0.3", path = "../tower-limit" }
# tower-load-shed = { version = "0.3", path = "../tower-load-shed" }
tower-retry = { version = "0.3", path = "../tower-retry" }
tower-service = { version = "0.3", path = "../tower-service" }
tower-timeout = { version = "0.3", path = "../tower-timeout" }
tower-util = { version = "0.3", path = "../tower-util" }
futures-core = "0.3"
[dev-dependencies]
env_logger = { version = "0.5.3", default-features = false }
futures-util-preview = "=0.3.0-alpha.19"
log = "0.4.1"
tokio = "=0.2.0-alpha.6"
tower-test = { version = "=0.3.0-alpha.2", path = "../tower-test" }
# [dev-dependencies]
# env_logger = { version = "0.5.3", default-features = false }
futures-util = "0.3"
tokio = { version = "0.2", features = ["macros"] }
# log = "0.4.1"
# # tokio = "0.2"
tower-test = { version = "0.3", path = "../tower-test" }

View File

@ -3,13 +3,12 @@
use crate::{
buffer::BufferLayer,
limit::{concurrency::ConcurrencyLimitLayer, rate::RateLimitLayer},
load_shed::LoadShedLayer,
// load_shed::LoadShedLayer,
retry::RetryLayer,
timeout::TimeoutLayer,
};
use tower_layer::Layer;
use tower_util::layer::{Identity, Stack};
use tower_layer::{Identity, Layer, Stack};
use std::{fmt, time::Duration};
@ -147,9 +146,9 @@ impl<L> ServiceBuilder<L> {
///
/// `load_shed` immediately responds with an error when the next layer is
/// out of capacity.
pub fn load_shed(self) -> ServiceBuilder<Stack<LoadShedLayer, L>> {
self.layer(LoadShedLayer::new())
}
// pub fn load_shed(self) -> ServiceBuilder<Stack<LoadShedLayer, L>> {
// self.layer(LoadShedLayer::new())
// }
/// Limit requests to at most `num` per the given duration
pub fn rate_limit(self, num: u64, per: Duration) -> ServiceBuilder<Stack<RateLimitLayer, L>> {

View File

@ -4,5 +4,5 @@ pub use tower_layer::Layer;
/// `util` exports an Identity Layer and Chain, a mechanism for chaining them.
pub mod util {
pub use tower_util::layer::{Identity, Stack};
pub use tower_layer::{Identity, Stack};
}

View File

@ -1,4 +1,4 @@
#![doc(html_root_url = "https://docs.rs/tower/0.3.0-alpha.2")]
#![doc(html_root_url = "https://docs.rs/tower/0.3.0")]
// Allows refining features in the future without breaking backwards
// compatibility
#![cfg(feature = "full")]
@ -16,19 +16,21 @@
#[doc(inline)]
pub use tower_buffer as buffer;
#[doc(inline)]
pub use tower_discover as discover;
// #[doc(inline)]
// pub use tower_discover as discover;
#[doc(inline)]
pub use tower_limit as limit;
#[doc(inline)]
pub use tower_load_shed as load_shed;
// pub use tower_load_shed as load_shed;
#[doc(inline)]
pub use tower_retry as retry;
#[doc(inline)]
pub use tower_timeout as timeout;
// pub use tower_layer as layer;
#[doc(inline)]
pub use tower_layer as layer;
pub mod builder;
pub mod layer;
pub mod util;
pub use crate::{builder::ServiceBuilder, util::ServiceExt};

View File

@ -1,7 +1,4 @@
use futures_util::{
future::{poll_fn, Ready},
pin_mut,
};
use futures_util::{future::Ready, pin_mut};
use std::time::Duration;
use tower::builder::ServiceBuilder;
use tower::util::ServiceExt;
@ -9,7 +6,7 @@ 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::{assert_request_eq, mock};
#[tokio::test]
async fn builder_service() {
@ -30,11 +27,7 @@ async fn builder_service() {
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_request_eq!(handle, "hello").send_response("world");
assert_eq!(fut.await.unwrap(), "world");
}