Add test to tower-timeout
This commit is contained in:
parent
7b48479bd2
commit
00e23a140f
|
@ -22,7 +22,9 @@ categories = ["asynchronous", "network-programming"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
tokio = { version = "0.2", features = ["time", "test-util"] }
|
||||||
|
tokio-test = "0.2"
|
||||||
tower-service = "0.3"
|
tower-service = "0.3"
|
||||||
tower-layer = "0.3"
|
tower-layer = "0.3"
|
||||||
tokio = { version = "0.2", features = ["time"] }
|
tower-test = { path = "../tower-test" }
|
||||||
pin-project = "0.4"
|
pin-project = "0.4"
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
use tokio::time::{self, Duration};
|
||||||
|
use tokio_test::{assert_err, assert_ready_ok};
|
||||||
|
use tower_test::{
|
||||||
|
assert_request_eq,
|
||||||
|
mock::{self, Spawn},
|
||||||
|
};
|
||||||
|
use tower_timeout::{Timeout, TimeoutLayer};
|
||||||
|
|
||||||
|
type Err = Box<dyn std::error::Error + Send + Sync + 'static>;
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn timeout() -> Result<(), Err> {
|
||||||
|
time::pause();
|
||||||
|
|
||||||
|
let timeout = TimeoutLayer::new(Duration::from_millis(100));
|
||||||
|
let (mut service, mut handle): (Spawn<Timeout<_>>, _) = mock::spawn_layer(timeout);
|
||||||
|
|
||||||
|
assert_ready_ok!(service.poll_ready());
|
||||||
|
|
||||||
|
let response = service.call("hello");
|
||||||
|
assert_request_eq!(handle, "hello").send_response("world");
|
||||||
|
assert_eq!(response.await?, "world");
|
||||||
|
|
||||||
|
assert_ready_ok!(service.poll_ready());
|
||||||
|
let response = service.call("two");
|
||||||
|
time::advance(Duration::from_millis(200)).await;
|
||||||
|
assert_err!(response.await);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
Loading…
Reference in New Issue