From c210524e9463df1a480bf5f55ad1a69fbb2f6c91 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Sat, 7 Apr 2018 10:27:35 -0700 Subject: [PATCH] chore(tests): fix tokio runtime deprecations --- Cargo.toml | 2 +- benches/end_to_end.rs | 4 +- tests/client.rs | 87 +++++++------------------------------------ tests/server.rs | 22 +++++------ 4 files changed, 27 insertions(+), 88 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ed5e1052..2750432a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,7 @@ iovec = "0.1" log = "0.4" net2 = "0.2.32" time = "0.1" -tokio = "0.1.3" +tokio = "0.1.5" tokio-executor = "0.1.0" tokio-service = "0.1" tokio-io = "0.1" diff --git a/benches/end_to_end.rs b/benches/end_to_end.rs index 8c9aeecf..075f98d6 100644 --- a/benches/end_to_end.rs +++ b/benches/end_to_end.rs @@ -22,7 +22,7 @@ fn get_one_at_a_time(b: &mut test::Bencher) { let addr = spawn_hello(&mut rt); let client = hyper::Client::configure() - .build_with_executor(&rt.handle(), rt.executor()); + .build_with_executor(&rt.reactor(), rt.executor()); let url: hyper::Uri = format!("http://{}/get", addr).parse().unwrap(); @@ -44,7 +44,7 @@ fn post_one_at_a_time(b: &mut test::Bencher) { let addr = spawn_hello(&mut rt); let client = hyper::Client::configure() - .build_with_executor(&rt.handle(), rt.executor()); + .build_with_executor(&rt.reactor(), rt.executor()); let url: hyper::Uri = format!("http://{}/post", addr).parse().unwrap(); diff --git a/tests/client.rs b/tests/client.rs index 33f0f2e3..6705d370 100644 --- a/tests/client.rs +++ b/tests/client.rs @@ -186,7 +186,7 @@ macro_rules! test { if !$set_host { config = config.set_host(false); } - let client = config.build_with_executor(&runtime.handle(), runtime.executor()); + let client = config.build_with_executor(&runtime.reactor(), runtime.executor()); let body = if let Some(body) = $request_body { let body: &'static str = body; @@ -665,7 +665,7 @@ mod dispatch_impl { let runtime = Runtime::new().unwrap(); let (closes_tx, closes) = mpsc::channel(10); let client = Client::configure() - .connector(DebugConnector::with_http_and_closes(HttpConnector::new(1, &runtime.handle()), closes_tx)) + .connector(DebugConnector::with_http_and_closes(HttpConnector::new(1, &runtime.reactor()), closes_tx)) .executor(runtime.executor()); let (tx1, rx1) = oneshot::channel(); @@ -705,7 +705,7 @@ mod dispatch_impl { let server = TcpListener::bind("127.0.0.1:0").unwrap(); let addr = server.local_addr().unwrap(); let runtime = Runtime::new().unwrap(); - let handle = runtime.handle(); + let handle = runtime.reactor(); let (closes_tx, closes) = mpsc::channel(10); let (tx1, rx1) = oneshot::channel(); @@ -754,7 +754,7 @@ mod dispatch_impl { let server = TcpListener::bind("127.0.0.1:0").unwrap(); let addr = server.local_addr().unwrap(); let runtime = Runtime::new().unwrap(); - let handle = runtime.handle(); + let handle = runtime.reactor(); let (closes_tx, mut closes) = mpsc::channel(10); let (tx1, rx1) = oneshot::channel(); @@ -818,7 +818,7 @@ mod dispatch_impl { let server = TcpListener::bind("127.0.0.1:0").unwrap(); let addr = server.local_addr().unwrap(); let runtime = Runtime::new().unwrap(); - let handle = runtime.handle(); + let handle = runtime.reactor(); let (closes_tx, closes) = mpsc::channel(10); let (tx1, rx1) = oneshot::channel(); @@ -871,7 +871,7 @@ mod dispatch_impl { let server = TcpListener::bind("127.0.0.1:0").unwrap(); let addr = server.local_addr().unwrap(); let runtime = Runtime::new().unwrap(); - let handle = runtime.handle(); + let handle = runtime.reactor(); let (closes_tx, closes) = mpsc::channel(10); let (tx1, rx1) = oneshot::channel(); @@ -925,7 +925,7 @@ mod dispatch_impl { let server = TcpListener::bind("127.0.0.1:0").unwrap(); let addr = server.local_addr().unwrap(); let runtime = Runtime::new().unwrap(); - let handle = runtime.handle(); + let handle = runtime.reactor(); let (closes_tx, closes) = mpsc::channel(10); let (tx1, rx1) = oneshot::channel(); @@ -976,7 +976,7 @@ mod dispatch_impl { let server = TcpListener::bind("127.0.0.1:0").unwrap(); let addr = server.local_addr().unwrap(); let runtime = Runtime::new().unwrap(); - let handle = runtime.handle(); + let handle = runtime.reactor(); let (closes_tx, closes) = mpsc::channel(10); let (tx1, rx1) = oneshot::channel(); @@ -1017,73 +1017,12 @@ mod dispatch_impl { let _ = t.select(close).wait(); } - #[test] - fn conn_drop_prevents_pool_checkout() { - // a drop might happen for any sort of reason, and we can protect - // against a lot of them, but if the `runtime` is dropped, we can't - // really catch that. So, this is case to always check. - // - // See https://github.com/hyperium/hyper/issues/1429 - - use std::error::Error; - let _ = pretty_env_logger::try_init(); - - let server = TcpListener::bind("127.0.0.1:0").unwrap(); - let addr = server.local_addr().unwrap(); - let runtime = Runtime::new().unwrap(); - let handle = runtime.handle().clone(); - - let (tx1, rx1) = oneshot::channel(); - - thread::spawn(move || { - let mut sock = server.accept().unwrap().0; - sock.set_read_timeout(Some(Duration::from_secs(5))).unwrap(); - sock.set_write_timeout(Some(Duration::from_secs(5))).unwrap(); - let mut buf = [0; 4096]; - sock.read(&mut buf).expect("read 1"); - sock.write_all(b"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n").unwrap(); - sock.read(&mut buf).expect("read 2"); - let _ = tx1.send(()); - }); - - let uri = format!("http://{}/a", addr).parse::().unwrap(); - - let client = Client::configure().build_with_executor(&handle, runtime.executor()); - - let req = Request::builder() - .uri(uri.clone()) - .body(Body::empty()) - .unwrap(); - let res = client.request(req).and_then(move |res| { - assert_eq!(res.status(), hyper::StatusCode::OK); - res.into_body().into_stream().concat2() - }); - - res.wait().unwrap(); - - // drop previous runtime - drop(runtime); - let timeout = Delay::new(Duration::from_millis(200)); - let rx = rx1.map_err(|_| hyper::Error::Io(io::Error::new(io::ErrorKind::Other, "thread panicked"))); - let rx = rx.and_then(move |_| timeout.map_err(|e| e.into())); - - let req = Request::builder() - .uri(uri) - .body(Body::empty()) - .unwrap(); - let res = client.request(req); - // this does trigger an 'event loop gone' error, but before, it would - // panic internally on a `SendError`, which is what we're testing against. - let err = res.join(rx).map(|r| r.0).wait().unwrap_err(); - assert_eq!(err.description(), "event loop gone"); - } - #[test] fn client_custom_executor() { let server = TcpListener::bind("127.0.0.1:0").unwrap(); let addr = server.local_addr().unwrap(); let runtime = Runtime::new().unwrap(); - let handle = runtime.handle(); + let handle = runtime.reactor(); let (closes_tx, closes) = mpsc::channel(10); let (tx1, rx1) = oneshot::channel(); @@ -1134,7 +1073,7 @@ mod dispatch_impl { let _ = pretty_env_logger::try_init(); let runtime = Runtime::new().unwrap(); - let handle = runtime.handle(); + let handle = runtime.reactor(); let connector = DebugConnector::new(&handle); let connects = connector.connects.clone(); @@ -1159,7 +1098,7 @@ mod dispatch_impl { let server = TcpListener::bind("127.0.0.1:0").unwrap(); let addr = server.local_addr().unwrap(); let runtime = Runtime::new().unwrap(); - let handle = runtime.handle(); + let handle = runtime.reactor(); let connector = DebugConnector::new(&handle); let connects = connector.connects.clone(); @@ -1221,7 +1160,7 @@ mod dispatch_impl { let server = TcpListener::bind("127.0.0.1:0").unwrap(); let addr = server.local_addr().unwrap(); let runtime = Runtime::new().unwrap(); - let handle = runtime.handle(); + let handle = runtime.reactor(); let connector = DebugConnector::new(&handle); let connects = connector.connects.clone(); @@ -1283,7 +1222,7 @@ mod dispatch_impl { let server = TcpListener::bind("127.0.0.1:0").unwrap(); let addr = server.local_addr().unwrap(); let runtime = Runtime::new().unwrap(); - let handle = runtime.handle(); + let handle = runtime.reactor(); let connector = DebugConnector::new(&handle) .proxy(); diff --git a/tests/server.rs b/tests/server.rs index 548b3467..b7dee695 100644 --- a/tests/server.rs +++ b/tests/server.rs @@ -78,7 +78,7 @@ fn get_with_body() { fn get_implicitly_empty() { // See https://github.com/hyperium/hyper/issues/1373 let runtime = Runtime::new().unwrap(); - let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.handle()).unwrap(); + let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.reactor()).unwrap(); let addr = listener.local_addr().unwrap(); thread::spawn(move || { @@ -755,7 +755,7 @@ fn http_10_request_receives_http_10_response() { #[test] fn disable_keep_alive_mid_request() { let runtime = Runtime::new().unwrap(); - let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.handle()).unwrap(); + let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.reactor()).unwrap(); let addr = listener.local_addr().unwrap(); let (tx1, rx1) = oneshot::channel(); @@ -800,7 +800,7 @@ fn disable_keep_alive_mid_request() { fn disable_keep_alive_post_request() { let _ = pretty_env_logger::try_init(); let runtime = Runtime::new().unwrap(); - let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.handle()).unwrap(); + let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.reactor()).unwrap(); let addr = listener.local_addr().unwrap(); let (tx1, rx1) = oneshot::channel(); @@ -871,7 +871,7 @@ fn disable_keep_alive_post_request() { #[test] fn empty_parse_eof_does_not_return_error() { let runtime = Runtime::new().unwrap(); - let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.handle()).unwrap(); + let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.reactor()).unwrap(); let addr = listener.local_addr().unwrap(); thread::spawn(move || { @@ -892,7 +892,7 @@ fn empty_parse_eof_does_not_return_error() { #[test] fn nonempty_parse_eof_returns_error() { let runtime = Runtime::new().unwrap(); - let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.handle()).unwrap(); + let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.reactor()).unwrap(); let addr = listener.local_addr().unwrap(); thread::spawn(move || { @@ -915,7 +915,7 @@ fn nonempty_parse_eof_returns_error() { #[test] fn returning_1xx_response_is_error() { let runtime = Runtime::new().unwrap(); - let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.handle()).unwrap(); + let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.reactor()).unwrap(); let addr = listener.local_addr().unwrap(); thread::spawn(move || { @@ -951,7 +951,7 @@ fn upgrades() { use tokio_io::io::{read_to_end, write_all}; let _ = pretty_env_logger::try_init(); let runtime = Runtime::new().unwrap(); - let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.handle()).unwrap(); + let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.reactor()).unwrap(); let addr = listener.local_addr().unwrap(); let (tx, rx) = oneshot::channel(); @@ -1016,7 +1016,7 @@ fn upgrades() { #[test] fn parse_errors_send_4xx_response() { let runtime = Runtime::new().unwrap(); - let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.handle()).unwrap(); + let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.reactor()).unwrap(); let addr = listener.local_addr().unwrap(); thread::spawn(move || { @@ -1045,7 +1045,7 @@ fn parse_errors_send_4xx_response() { #[test] fn illegal_request_length_returns_400_response() { let runtime = Runtime::new().unwrap(); - let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.handle()).unwrap(); + let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.reactor()).unwrap(); let addr = listener.local_addr().unwrap(); thread::spawn(move || { @@ -1075,7 +1075,7 @@ fn illegal_request_length_returns_400_response() { fn max_buf_size() { let _ = pretty_env_logger::try_init(); let runtime = Runtime::new().unwrap(); - let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.handle()).unwrap(); + let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.reactor()).unwrap(); let addr = listener.local_addr().unwrap(); const MAX: usize = 16_000; @@ -1109,7 +1109,7 @@ fn max_buf_size() { fn streaming_body() { let _ = pretty_env_logger::try_init(); let runtime = Runtime::new().unwrap(); - let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.handle()).unwrap(); + let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.reactor()).unwrap(); let addr = listener.local_addr().unwrap(); let (tx, rx) = oneshot::channel();