Add test and assertion for idle state handling (#160)

This commit is contained in:
Eliza Weisman
2017-10-27 14:14:00 -07:00
committed by Carl Lerche
parent b1d282799b
commit 8a1c4d3d52
4 changed files with 158 additions and 2 deletions

View File

@@ -369,6 +369,60 @@ fn recv_goaway_finishes_processed_streams() {
h2.join(srv).wait().expect("wait");
}
#[test]
fn skipped_stream_ids_are_implicitly_closed() {
let _ = ::env_logger::init();
let (io, srv) = mock::new();
let srv = srv
.assert_client_handshake()
.expect("handshake")
.recv_settings()
.recv_frame(frames::headers(5)
.request("GET", "https://example.com/")
.eos(),
)
// send the response on a lower-numbered stream, which should be
// implicitly closed.
.send_frame(frames::headers(3).response(200));
let h2 = Client::builder()
.initial_stream_id(5)
.handshake::<_, Bytes>(io)
.expect("handshake")
.and_then(|(mut client, h2)| {
let request = Request::builder()
.method(Method::GET)
.uri("https://example.com/")
.body(())
.unwrap();
let req = client.send_request(request, true)
.unwrap()
.0.then(|res| {
let err = res.unwrap_err();
assert_eq!(
err.to_string(),
"protocol error: unspecific protocol error detected");
Ok::<(), ()>(())
});
// client should see a conn error
let conn = h2.then(|res| {
let err = res.unwrap_err();
assert_eq!(
err.to_string(),
"protocol error: unspecific protocol error detected"
);
Ok::<(), ()>(())
});
conn.unwrap().join(req)
});
h2.join(srv).wait().expect("wait");
}
/*
#[test]
fn send_data_after_headers_eos() {

View File

@@ -15,6 +15,30 @@ pub trait FutureExt: Future {
}
}
/// Panic on success, yielding the content of an `Err`.
fn unwrap_err(self) -> UnwrapErr<Self>
where
Self: Sized,
Self::Error: fmt::Debug,
{
UnwrapErr {
inner: self,
}
}
/// Panic on success, with a message.
fn expect_err<T>(self, msg: T) -> ExpectErr<Self>
where
Self: Sized,
Self::Error: fmt::Debug,
T: fmt::Display,
{
ExpectErr{
inner: self,
msg: msg.to_string(),
}
}
/// Panic on error, with a message.
fn expect<T>(self, msg: T) -> Expect<Self>
where
@@ -68,6 +92,32 @@ where
}
}
// ===== UnwrapErr ======
/// Panic on success.
pub struct UnwrapErr<T> {
inner: T,
}
impl<T> Future for UnwrapErr<T>
where
T: Future,
T::Item: fmt::Debug,
T::Error: fmt::Debug,
{
type Item = T::Error;
type Error = ();
fn poll(&mut self) -> Poll<T::Error, ()> {
let poll =
self.inner.poll()
.map_err(Async::Ready)
.unwrap_err();
Ok(poll)
}
}
// ===== Expect ======
@@ -91,6 +141,32 @@ where
}
}
// ===== ExpectErr ======
/// Panic on success
pub struct ExpectErr<T> {
inner: T,
msg: String,
}
impl<T> Future for ExpectErr<T>
where
T: Future,
T::Item: fmt::Debug,
T::Error: fmt::Debug,
{
type Item = T::Error;
type Error = ();
fn poll(&mut self) -> Poll<T::Error, ()> {
let poll =
self.inner.poll()
.map_err(Async::Ready)
.expect_err(&self.msg);
Ok(poll)
}
}
// ===== Drive ======
/// Drive a future to completion while also polling the driver