Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: print traces from tests #479

Merged
merged 2 commits into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tower-test/tests/mock.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use tokio_test::{assert_pending, assert_ready};
use tower_test::{assert_request_eq, mock};

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn single_request_ready() {
let (mut service, mut handle) = mock::spawn();

Expand All @@ -16,7 +16,7 @@ async fn single_request_ready() {
assert_eq!(response.await.unwrap(), "world");
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
#[should_panic]
async fn backpressure() {
let (mut service, mut handle) = mock::spawn::<_, ()>();
Expand Down
3 changes: 3 additions & 0 deletions tower/tests/balance/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![cfg(feature = "balance")]
#[path = "../support.rs"]
mod support;

use std::future::Future;
use std::task::{Context, Poll};
Expand Down Expand Up @@ -32,6 +34,7 @@ impl tower::load::Load for Mock {

#[test]
fn stress() {
let _t = support::trace_init();
let mut task = task::spawn(());
let (tx, rx) = tokio::sync::mpsc::unbounded_channel::<Result<_, &'static str>>();
let mut cache = Balance::<_, Req>::new(rx);
Expand Down
30 changes: 22 additions & 8 deletions tower/tests/buffer/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![cfg(feature = "buffer")]

#[path = "../support.rs"]
mod support;
use std::thread;
use tokio_test::{assert_pending, assert_ready, assert_ready_err, assert_ready_ok, task};
use tower::buffer::{error, Buffer};
Expand All @@ -10,8 +11,10 @@ fn let_worker_work() {
thread::sleep(::std::time::Duration::from_millis(100));
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn req_and_res() {
let _t = support::trace_init();

let (mut service, mut handle) = new_service();

assert_ready_ok!(service.poll_ready());
Expand All @@ -23,8 +26,10 @@ async fn req_and_res() {
assert_eq!(assert_ready_ok!(response.poll()), "world");
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn clears_canceled_requests() {
let _t = support::trace_init();

let (mut service, mut handle) = new_service();

handle.allow(1);
Expand Down Expand Up @@ -59,8 +64,10 @@ async fn clears_canceled_requests() {
assert_eq!(assert_ready_ok!(res3.poll()), "world3");
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn when_inner_is_not_ready() {
let _t = support::trace_init();

let (mut service, mut handle) = new_service();

// Make the service NotReady
Expand All @@ -81,9 +88,10 @@ async fn when_inner_is_not_ready() {
assert_eq!(assert_ready_ok!(res1.poll()), "world");
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn when_inner_fails() {
use std::error::Error as StdError;
let _t = support::trace_init();

let (mut service, mut handle) = new_service();

Expand All @@ -105,8 +113,10 @@ async fn when_inner_fails() {
}
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn poll_ready_when_worker_is_dropped_early() {
let _t = support::trace_init();

let (service, _handle) = mock::pair::<(), ()>();

let (service, worker) = Buffer::pair(service, 1);
Expand All @@ -120,8 +130,10 @@ async fn poll_ready_when_worker_is_dropped_early() {
assert!(err.is::<error::Closed>(), "should be a Closed: {:?}", err);
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn response_future_when_worker_is_dropped_early() {
let _t = support::trace_init();

let (service, mut handle) = mock::pair::<_, ()>();

let (service, worker) = Buffer::pair(service, 1);
Expand All @@ -140,8 +152,10 @@ async fn response_future_when_worker_is_dropped_early() {
assert!(err.is::<error::Closed>(), "should be a Closed: {:?}", err);
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn waits_for_channel_capacity() {
let _t = support::trace_init();

let (service, mut handle) = mock::pair::<&'static str, &'static str>();

let (service, worker) = Buffer::pair(service, 3);
Expand Down
6 changes: 4 additions & 2 deletions tower/tests/builder.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![cfg(all(feature = "buffer", feature = "limit", feature = "retry"))]

mod support;
use futures_util::{future::Ready, pin_mut};
use std::time::Duration;
use tower::builder::ServiceBuilder;
Expand All @@ -8,8 +8,10 @@ use tower::util::ServiceExt;
use tower_service::*;
use tower_test::{assert_request_eq, mock};

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn builder_service() {
let _t = support::trace_init();

let (service, handle) = mock::pair();
pin_mut!(handle);

Expand Down
11 changes: 8 additions & 3 deletions tower/tests/filter/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#![cfg(feature = "filter")]

#[path = "../support.rs"]
mod support;
use futures_util::{future::poll_fn, pin_mut};
use std::future::Future;
use tower::filter::{error::Error, Filter};
use tower_service::Service;
use tower_test::{assert_request_eq, mock};

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn passthrough_sync() {
let _t = support::trace_init();

let (mut service, handle) = new_service(|_| async { Ok(()) });

let th = tokio::spawn(async move {
Expand Down Expand Up @@ -37,8 +40,10 @@ async fn passthrough_sync() {
th.await.unwrap();
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn rejected_sync() {
let _t = support::trace_init();

let (mut service, _handle) = new_service(|_| async { Err(Error::rejected()) });

service.call("hello".into()).await.unwrap_err();
Expand Down
17 changes: 12 additions & 5 deletions tower/tests/hedge/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#![cfg(feature = "hedge")]
#[path = "../support.rs"]
mod support;

use std::time::Duration;
use tokio::time;
use tokio_test::{assert_pending, assert_ready, assert_ready_ok, task};
use tower::hedge::{Hedge, Policy};
use tower_test::{assert_request_eq, mock};

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn hedge_orig_completes_first() {
let _t = support::trace_init();
time::pause();

let (mut service, mut handle) = new_service(TestPolicy);
Expand All @@ -33,8 +36,9 @@ async fn hedge_orig_completes_first() {
assert_eq!(assert_ready_ok!(fut.poll()), "orig-done");
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn hedge_hedge_completes_first() {
let _t = support::trace_init();
time::pause();

let (mut service, mut handle) = new_service(TestPolicy);
Expand All @@ -61,8 +65,9 @@ async fn hedge_hedge_completes_first() {
assert_eq!(assert_ready_ok!(fut.poll()), "hedge-done");
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn completes_before_hedge() {
let _t = support::trace_init();
let (mut service, mut handle) = new_service(TestPolicy);

assert_ready_ok!(service.poll_ready());
Expand All @@ -80,8 +85,9 @@ async fn completes_before_hedge() {
assert_eq!(assert_ready_ok!(fut.poll()), "orig-done");
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn request_not_retyable() {
let _t = support::trace_init();
time::pause();

let (mut service, mut handle) = new_service(TestPolicy);
Expand All @@ -107,8 +113,9 @@ async fn request_not_retyable() {
assert_eq!(assert_ready_ok!(fut.poll()), "orig-done");
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn request_not_clonable() {
let _t = support::trace_init();
time::pause();

let (mut service, mut handle) = new_service(TestPolicy);
Expand Down
26 changes: 18 additions & 8 deletions tower/tests/limit/concurrency.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#[path = "../support.rs"]
mod support;
use tokio_test::{assert_pending, assert_ready, assert_ready_ok};
use tower::limit::concurrency::ConcurrencyLimitLayer;
use tower_test::{assert_request_eq, mock};

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn basic_service_limit_functionality_with_poll_ready() {
let _t = support::trace_init();
let limit = ConcurrencyLimitLayer::new(2);
let (mut service, mut handle) = mock::spawn_layer(limit);

Expand Down Expand Up @@ -45,8 +48,9 @@ async fn basic_service_limit_functionality_with_poll_ready() {
assert_eq!(r3.await.unwrap(), "world 3");
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn basic_service_limit_functionality_without_poll_ready() {
let _t = support::trace_init();
let limit = ConcurrencyLimitLayer::new(2);
let (mut service, mut handle) = mock::spawn_layer(limit);

Expand Down Expand Up @@ -90,16 +94,18 @@ async fn basic_service_limit_functionality_without_poll_ready() {
assert_eq!(r4.await.unwrap(), "world 4");
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn request_without_capacity() {
let _t = support::trace_init();
let limit = ConcurrencyLimitLayer::new(0);
let (mut service, _) = mock::spawn_layer::<(), (), _>(limit);

assert_pending!(service.poll_ready());
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn reserve_capacity_without_sending_request() {
let _t = support::trace_init();
let limit = ConcurrencyLimitLayer::new(1);
let (mut s1, mut handle) = mock::spawn_layer(limit);

Expand All @@ -123,8 +129,9 @@ async fn reserve_capacity_without_sending_request() {
assert_ready_ok!(s2.poll_ready());
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn service_drop_frees_capacity() {
let _t = support::trace_init();
let limit = ConcurrencyLimitLayer::new(1);
let (mut s1, _handle) = mock::spawn_layer::<(), (), _>(limit);

Expand All @@ -142,8 +149,9 @@ async fn service_drop_frees_capacity() {
assert_ready_ok!(s2.poll_ready());
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn response_error_releases_capacity() {
let _t = support::trace_init();
let limit = ConcurrencyLimitLayer::new(1);
let (mut s1, mut handle) = mock::spawn_layer::<_, (), _>(limit);

Expand All @@ -162,8 +170,9 @@ async fn response_error_releases_capacity() {
assert_ready_ok!(s2.poll_ready());
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn response_future_drop_releases_capacity() {
let _t = support::trace_init();
let limit = ConcurrencyLimitLayer::new(1);
let (mut s1, _handle) = mock::spawn_layer::<_, (), _>(limit);

Expand All @@ -182,8 +191,9 @@ async fn response_future_drop_releases_capacity() {
assert_ready_ok!(s2.poll_ready());
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn multi_waiters() {
let _t = support::trace_init();
let limit = ConcurrencyLimitLayer::new(1);
let (mut s1, _handle) = mock::spawn_layer::<(), (), _>(limit);
let mut s2 = s1.clone();
Expand Down
3 changes: 2 additions & 1 deletion tower/tests/limit/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![cfg(feature = "limit")]

mod concurrency;
mod rate;
#[path = "../support.rs"]
pub(crate) mod support;
8 changes: 5 additions & 3 deletions tower/tests/limit/rate.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use super::support;
use std::time::Duration;
use tokio::time;
use tokio_test::{assert_pending, assert_ready, assert_ready_ok};
use tower::limit::rate::RateLimitLayer;
use tower_test::{assert_request_eq, mock};

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn reaching_capacity() {
let _t = support::trace_init();
time::pause();

let rate_limit = RateLimitLayer::new(1, Duration::from_millis(100));
Expand Down Expand Up @@ -33,7 +35,7 @@ async fn reaching_capacity() {
assert_eq!(response.await.unwrap(), "done");
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn remaining_gets_reset() {
// This test checks for the case where the `until` state gets reset
// but the `rem` does not. This was a bug found `cd7dd12315706fc0860a35646b1eb7b60c50a5c1`.
Expand All @@ -42,7 +44,7 @@ async fn remaining_gets_reset() {
// as ready. Then we can advance the clock to put us beyond the current period. When we make
// subsequent requests the `rem` for the next window is continued from the previous when
// it should be totally reset.

let _t = support::trace_init();
time::pause();

let rate_limit = RateLimitLayer::new(3, Duration::from_millis(100));
Expand Down
10 changes: 8 additions & 2 deletions tower/tests/load_shed/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#![cfg(feature = "load-shed")]
#[path = "../support.rs"]
mod support;

use tokio_test::{assert_ready_err, assert_ready_ok, task};
use tower::load_shed::LoadShedLayer;
use tower_test::{assert_request_eq, mock};

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn when_ready() {
let _t = support::trace_init();

let layer = LoadShedLayer::new();
let (mut service, mut handle) = mock::spawn_layer(layer);

Expand All @@ -17,8 +21,10 @@ async fn when_ready() {
assert_eq!(assert_ready_ok!(response.poll()), "world");
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn when_not_ready() {
let _t = support::trace_init();

let layer = LoadShedLayer::new();
let (mut service, mut handle) = mock::spawn_layer::<_, (), _>(layer);

Expand Down
Loading