use futures_executor::block_on;
use futures_util::pin_mut;
use std::future::Future;
use tokio_test::{assert_pending, assert_ready, task};
use tower_service::Service;
use tower_test::{assert_request_eq, mock};
#[test]
fn single_request_ready() {
task::mock(|cx| {
let (mock, handle) = new_mock();
pin_mut!(mock);
pin_mut!(handle);
assert!(handle.as_mut().poll_request(cx).is_pending());
assert_ready!(mock.poll_ready(cx)).unwrap();
let response = mock.call("hello?".into());
pin_mut!(response);
let send_response = assert_request_eq!(handle, "hello?");
assert_pending!(response.as_mut().poll(cx));
send_response.send_response("yes?".into());
assert_eq!(block_on(response).unwrap().as_str(), "yes?");
});
}
#[test]
#[should_panic]
fn backpressure() {
task::mock(|cx| {
let (mut mock, mut handle) = new_mock();
handle.allow(0);
assert_pending!(mock.poll_ready(cx));
mock.call("hello?".into());
});
}
type Mock = mock::Mock<String, String>;
type Handle = mock::Handle<String, String>;
fn new_mock() -> (Mock, Handle) {
mock::pair()
}