Try to clean up test
This commit is contained in:
		| @@ -32,13 +32,12 @@ fn send_recv_headers_only() { | |||||||
|         .body(()).unwrap(); |         .body(()).unwrap(); | ||||||
|  |  | ||||||
|     info!("sending request"); |     info!("sending request"); | ||||||
|     let stream = h2.request(request, true).unwrap(); |     let mut stream = h2.request(request, true).unwrap(); | ||||||
|  |  | ||||||
|     // Wait |     let resp = h2.run(poll_fn(|| stream.poll_response())).unwrap(); | ||||||
|     h2.wait().ok().unwrap(); |  | ||||||
|  |  | ||||||
|     // Try to get response |     // Try to get response | ||||||
|     println!("GOT: {:?}", stream.wait().ok().unwrap()); |     println!("GOT: {:?}", resp); | ||||||
|  |  | ||||||
|     // let resp = stream.select2(h2).wait().ok().unwrap(); |     // let resp = stream.select2(h2).wait().ok().unwrap(); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -3,6 +3,7 @@ | |||||||
| pub extern crate bytes; | pub extern crate bytes; | ||||||
| pub extern crate h2; | pub extern crate h2; | ||||||
| pub extern crate http; | pub extern crate http; | ||||||
|  | pub extern crate tokio_io; | ||||||
| pub extern crate futures; | pub extern crate futures; | ||||||
| pub extern crate mock_io; | pub extern crate mock_io; | ||||||
| pub extern crate env_logger; | pub extern crate env_logger; | ||||||
| @@ -12,6 +13,7 @@ pub use self::futures::{ | |||||||
|     Sink, |     Sink, | ||||||
|     Stream, |     Stream, | ||||||
| }; | }; | ||||||
|  | pub use self::futures::future::poll_fn; | ||||||
|  |  | ||||||
| pub use self::http::{ | pub use self::http::{ | ||||||
|     request, |     request, | ||||||
| @@ -30,8 +32,11 @@ pub use self::bytes::{ | |||||||
|     BufMut, |     BufMut, | ||||||
|     Bytes, |     Bytes, | ||||||
|     BytesMut, |     BytesMut, | ||||||
|  |     IntoBuf, | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | use tokio_io::{AsyncRead, AsyncWrite}; | ||||||
|  |  | ||||||
| pub trait MockH2 { | pub trait MockH2 { | ||||||
|     fn handshake(&mut self) -> &mut Self; |     fn handshake(&mut self) -> &mut Self; | ||||||
| } | } | ||||||
| @@ -46,6 +51,33 @@ impl MockH2 for mock_io::Builder { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | pub trait ClientExt { | ||||||
|  |     fn run<F: Future>(&mut self, f: F) -> Result<F::Item, F::Error>; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | impl<T, B> ClientExt for Client<T, B> | ||||||
|  |     where T: AsyncRead + AsyncWrite + 'static, | ||||||
|  |           B: IntoBuf + 'static, | ||||||
|  | { | ||||||
|  |     fn run<F: Future>(&mut self, f: F) -> Result<F::Item, F::Error> { | ||||||
|  |         use futures::future::{self, Future}; | ||||||
|  |         use futures::future::Either::*; | ||||||
|  |  | ||||||
|  |         let res = future::poll_fn(|| self.poll()) | ||||||
|  |             .select2(f).wait(); | ||||||
|  |  | ||||||
|  |         match res { | ||||||
|  |             Ok(A((_, b))) => { | ||||||
|  |                 // Connection is done... | ||||||
|  |                 b.wait() | ||||||
|  |             } | ||||||
|  |             Ok(B((v, _))) => return Ok(v), | ||||||
|  |             Err(A((e, _))) => panic!("err: {:?}", e), | ||||||
|  |             Err(B((e, _))) => return Err(e), | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
| pub mod frames { | pub mod frames { | ||||||
|     //! Some useful frames |     //! Some useful frames | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user