Repository: tower-rs/tower
Pull request #378 (2019-12-05 00:05:06)

Update `tower` and `tower-util` and prep for release

LucioFranco: This depends on #376 and #377

Patch:
diff --git a/Cargo.toml b/Cargo.toml
index 7e41f45..7921d2f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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",
 ]
diff --git a/tower-util/CHANGELOG.md b/tower-util/CHANGELOG.md
index 633a866..d6633fe 100644
--- a/tower-util/CHANGELOG.md
+++ b/tower-util/CHANGELOG.md
@@ -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`
diff --git a/tower-util/Cargo.toml b/tower-util/Cargo.toml
index 901fba8..164e522 100644
--- a/tower-util/Cargo.toml
+++ b/tower-util/Cargo.toml
@@ -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" }
diff --git a/tower-util/src/call_all/ordered.rs b/tower-util/src/call_all/ordered.rs
index e2f7780..1ec47a4 100644
--- a/tower-util/src/call_all/ordered.rs
+++ b/tower-util/src/call_all/ordered.rs
@@ -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.
diff --git a/tower-util/src/lib.rs b/tower-util/src/lib.rs
index d5517b9..e1c444d 100644
--- a/tower-util/src/lib.rs
+++ b/tower-util/src/lib.rs
@@ -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,
diff --git a/tower/CHANGELOG.md b/tower/CHANGELOG.md
index 5f729b7..78614fa 100644
--- a/tower/CHANGELOG.md
+++ b/tower/CHANGELOG.md
@@ -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`
diff --git a/tower/Cargo.toml b/tower/Cargo.toml
index 6016868..fb87276 100644
--- a/tower/Cargo.toml
+++ b/tower/Cargo.toml
@@ -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" }
diff --git a/tower/src/builder/mod.rs b/tower/src/builder/mod.rs
index 2281858..fb2ce04 100644
--- a/tower/src/builder/mod.rs
+++ b/tower/src/builder/mod.rs
@@ -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>> {
diff --git a/tower/src/layer.rs b/tower/src/layer.rs
index e1b3d3b..8aa27ee 100644
--- a/tower/src/layer.rs
+++ b/tower/src/layer.rs
@@ -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};
 }
diff --git a/tower/src/lib.rs b/tower/src/lib.rs
index 8bcd89e..b0b3a65 100644
--- a/tower/src/lib.rs
+++ b/tower/src/lib.rs
@@ -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};


Test patch:
diff --git a/tower-util/tests/call_all.rs b/tower-util/tests/call_all.rs
index c4c5818..c1652ec 100644
--- a/tower-util/tests/call_all.rs
+++ b/tower-util/tests/call_all.rs
@@ -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());
diff --git a/tower-util/tests/service_fn.rs b/tower-util/tests/service_fn.rs
index d1349c1..3a5a5ab 100644
--- a/tower-util/tests/service_fn.rs
+++ b/tower-util/tests/service_fn.rs
@@ -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);
 }
diff --git a/tower/tests/builder.rs b/tower/tests/builder.rs
index cbb76e8..87d8aff 100644
--- a/tower/tests/builder.rs
+++ b/tower/tests/builder.rs
@@ -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");
 }