Skip to content

Commit c210524

Browse files
committed
chore(tests): fix tokio runtime deprecations
1 parent 625e4da commit c210524

File tree

4 files changed

+27
-88
lines changed

4 files changed

+27
-88
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ iovec = "0.1"
3131
log = "0.4"
3232
net2 = "0.2.32"
3333
time = "0.1"
34-
tokio = "0.1.3"
34+
tokio = "0.1.5"
3535
tokio-executor = "0.1.0"
3636
tokio-service = "0.1"
3737
tokio-io = "0.1"

benches/end_to_end.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn get_one_at_a_time(b: &mut test::Bencher) {
2222
let addr = spawn_hello(&mut rt);
2323

2424
let client = hyper::Client::configure()
25-
.build_with_executor(&rt.handle(), rt.executor());
25+
.build_with_executor(&rt.reactor(), rt.executor());
2626

2727
let url: hyper::Uri = format!("http://{}/get", addr).parse().unwrap();
2828

@@ -44,7 +44,7 @@ fn post_one_at_a_time(b: &mut test::Bencher) {
4444
let addr = spawn_hello(&mut rt);
4545

4646
let client = hyper::Client::configure()
47-
.build_with_executor(&rt.handle(), rt.executor());
47+
.build_with_executor(&rt.reactor(), rt.executor());
4848

4949
let url: hyper::Uri = format!("http://{}/post", addr).parse().unwrap();
5050

tests/client.rs

Lines changed: 13 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ macro_rules! test {
186186
if !$set_host {
187187
config = config.set_host(false);
188188
}
189-
let client = config.build_with_executor(&runtime.handle(), runtime.executor());
189+
let client = config.build_with_executor(&runtime.reactor(), runtime.executor());
190190

191191
let body = if let Some(body) = $request_body {
192192
let body: &'static str = body;
@@ -665,7 +665,7 @@ mod dispatch_impl {
665665
let runtime = Runtime::new().unwrap();
666666
let (closes_tx, closes) = mpsc::channel(10);
667667
let client = Client::configure()
668-
.connector(DebugConnector::with_http_and_closes(HttpConnector::new(1, &runtime.handle()), closes_tx))
668+
.connector(DebugConnector::with_http_and_closes(HttpConnector::new(1, &runtime.reactor()), closes_tx))
669669
.executor(runtime.executor());
670670

671671
let (tx1, rx1) = oneshot::channel();
@@ -705,7 +705,7 @@ mod dispatch_impl {
705705
let server = TcpListener::bind("127.0.0.1:0").unwrap();
706706
let addr = server.local_addr().unwrap();
707707
let runtime = Runtime::new().unwrap();
708-
let handle = runtime.handle();
708+
let handle = runtime.reactor();
709709
let (closes_tx, closes) = mpsc::channel(10);
710710

711711
let (tx1, rx1) = oneshot::channel();
@@ -754,7 +754,7 @@ mod dispatch_impl {
754754
let server = TcpListener::bind("127.0.0.1:0").unwrap();
755755
let addr = server.local_addr().unwrap();
756756
let runtime = Runtime::new().unwrap();
757-
let handle = runtime.handle();
757+
let handle = runtime.reactor();
758758
let (closes_tx, mut closes) = mpsc::channel(10);
759759

760760
let (tx1, rx1) = oneshot::channel();
@@ -818,7 +818,7 @@ mod dispatch_impl {
818818
let server = TcpListener::bind("127.0.0.1:0").unwrap();
819819
let addr = server.local_addr().unwrap();
820820
let runtime = Runtime::new().unwrap();
821-
let handle = runtime.handle();
821+
let handle = runtime.reactor();
822822
let (closes_tx, closes) = mpsc::channel(10);
823823

824824
let (tx1, rx1) = oneshot::channel();
@@ -871,7 +871,7 @@ mod dispatch_impl {
871871
let server = TcpListener::bind("127.0.0.1:0").unwrap();
872872
let addr = server.local_addr().unwrap();
873873
let runtime = Runtime::new().unwrap();
874-
let handle = runtime.handle();
874+
let handle = runtime.reactor();
875875
let (closes_tx, closes) = mpsc::channel(10);
876876

877877
let (tx1, rx1) = oneshot::channel();
@@ -925,7 +925,7 @@ mod dispatch_impl {
925925
let server = TcpListener::bind("127.0.0.1:0").unwrap();
926926
let addr = server.local_addr().unwrap();
927927
let runtime = Runtime::new().unwrap();
928-
let handle = runtime.handle();
928+
let handle = runtime.reactor();
929929
let (closes_tx, closes) = mpsc::channel(10);
930930

931931
let (tx1, rx1) = oneshot::channel();
@@ -976,7 +976,7 @@ mod dispatch_impl {
976976
let server = TcpListener::bind("127.0.0.1:0").unwrap();
977977
let addr = server.local_addr().unwrap();
978978
let runtime = Runtime::new().unwrap();
979-
let handle = runtime.handle();
979+
let handle = runtime.reactor();
980980
let (closes_tx, closes) = mpsc::channel(10);
981981

982982
let (tx1, rx1) = oneshot::channel();
@@ -1017,73 +1017,12 @@ mod dispatch_impl {
10171017
let _ = t.select(close).wait();
10181018
}
10191019

1020-
#[test]
1021-
fn conn_drop_prevents_pool_checkout() {
1022-
// a drop might happen for any sort of reason, and we can protect
1023-
// against a lot of them, but if the `runtime` is dropped, we can't
1024-
// really catch that. So, this is case to always check.
1025-
//
1026-
// See https://github.com/hyperium/hyper/issues/1429
1027-
1028-
use std::error::Error;
1029-
let _ = pretty_env_logger::try_init();
1030-
1031-
let server = TcpListener::bind("127.0.0.1:0").unwrap();
1032-
let addr = server.local_addr().unwrap();
1033-
let runtime = Runtime::new().unwrap();
1034-
let handle = runtime.handle().clone();
1035-
1036-
let (tx1, rx1) = oneshot::channel();
1037-
1038-
thread::spawn(move || {
1039-
let mut sock = server.accept().unwrap().0;
1040-
sock.set_read_timeout(Some(Duration::from_secs(5))).unwrap();
1041-
sock.set_write_timeout(Some(Duration::from_secs(5))).unwrap();
1042-
let mut buf = [0; 4096];
1043-
sock.read(&mut buf).expect("read 1");
1044-
sock.write_all(b"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n").unwrap();
1045-
sock.read(&mut buf).expect("read 2");
1046-
let _ = tx1.send(());
1047-
});
1048-
1049-
let uri = format!("http://{}/a", addr).parse::<hyper::Uri>().unwrap();
1050-
1051-
let client = Client::configure().build_with_executor(&handle, runtime.executor());
1052-
1053-
let req = Request::builder()
1054-
.uri(uri.clone())
1055-
.body(Body::empty())
1056-
.unwrap();
1057-
let res = client.request(req).and_then(move |res| {
1058-
assert_eq!(res.status(), hyper::StatusCode::OK);
1059-
res.into_body().into_stream().concat2()
1060-
});
1061-
1062-
res.wait().unwrap();
1063-
1064-
// drop previous runtime
1065-
drop(runtime);
1066-
let timeout = Delay::new(Duration::from_millis(200));
1067-
let rx = rx1.map_err(|_| hyper::Error::Io(io::Error::new(io::ErrorKind::Other, "thread panicked")));
1068-
let rx = rx.and_then(move |_| timeout.map_err(|e| e.into()));
1069-
1070-
let req = Request::builder()
1071-
.uri(uri)
1072-
.body(Body::empty())
1073-
.unwrap();
1074-
let res = client.request(req);
1075-
// this does trigger an 'event loop gone' error, but before, it would
1076-
// panic internally on a `SendError`, which is what we're testing against.
1077-
let err = res.join(rx).map(|r| r.0).wait().unwrap_err();
1078-
assert_eq!(err.description(), "event loop gone");
1079-
}
1080-
10811020
#[test]
10821021
fn client_custom_executor() {
10831022
let server = TcpListener::bind("127.0.0.1:0").unwrap();
10841023
let addr = server.local_addr().unwrap();
10851024
let runtime = Runtime::new().unwrap();
1086-
let handle = runtime.handle();
1025+
let handle = runtime.reactor();
10871026
let (closes_tx, closes) = mpsc::channel(10);
10881027

10891028
let (tx1, rx1) = oneshot::channel();
@@ -1134,7 +1073,7 @@ mod dispatch_impl {
11341073
let _ = pretty_env_logger::try_init();
11351074

11361075
let runtime = Runtime::new().unwrap();
1137-
let handle = runtime.handle();
1076+
let handle = runtime.reactor();
11381077
let connector = DebugConnector::new(&handle);
11391078
let connects = connector.connects.clone();
11401079

@@ -1159,7 +1098,7 @@ mod dispatch_impl {
11591098
let server = TcpListener::bind("127.0.0.1:0").unwrap();
11601099
let addr = server.local_addr().unwrap();
11611100
let runtime = Runtime::new().unwrap();
1162-
let handle = runtime.handle();
1101+
let handle = runtime.reactor();
11631102
let connector = DebugConnector::new(&handle);
11641103
let connects = connector.connects.clone();
11651104

@@ -1221,7 +1160,7 @@ mod dispatch_impl {
12211160
let server = TcpListener::bind("127.0.0.1:0").unwrap();
12221161
let addr = server.local_addr().unwrap();
12231162
let runtime = Runtime::new().unwrap();
1224-
let handle = runtime.handle();
1163+
let handle = runtime.reactor();
12251164

12261165
let connector = DebugConnector::new(&handle);
12271166
let connects = connector.connects.clone();
@@ -1283,7 +1222,7 @@ mod dispatch_impl {
12831222
let server = TcpListener::bind("127.0.0.1:0").unwrap();
12841223
let addr = server.local_addr().unwrap();
12851224
let runtime = Runtime::new().unwrap();
1286-
let handle = runtime.handle();
1225+
let handle = runtime.reactor();
12871226
let connector = DebugConnector::new(&handle)
12881227
.proxy();
12891228

tests/server.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fn get_with_body() {
7878
fn get_implicitly_empty() {
7979
// See https://github.com/hyperium/hyper/issues/1373
8080
let runtime = Runtime::new().unwrap();
81-
let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.handle()).unwrap();
81+
let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.reactor()).unwrap();
8282
let addr = listener.local_addr().unwrap();
8383

8484
thread::spawn(move || {
@@ -755,7 +755,7 @@ fn http_10_request_receives_http_10_response() {
755755
#[test]
756756
fn disable_keep_alive_mid_request() {
757757
let runtime = Runtime::new().unwrap();
758-
let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.handle()).unwrap();
758+
let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.reactor()).unwrap();
759759
let addr = listener.local_addr().unwrap();
760760

761761
let (tx1, rx1) = oneshot::channel();
@@ -800,7 +800,7 @@ fn disable_keep_alive_mid_request() {
800800
fn disable_keep_alive_post_request() {
801801
let _ = pretty_env_logger::try_init();
802802
let runtime = Runtime::new().unwrap();
803-
let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.handle()).unwrap();
803+
let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.reactor()).unwrap();
804804
let addr = listener.local_addr().unwrap();
805805

806806
let (tx1, rx1) = oneshot::channel();
@@ -871,7 +871,7 @@ fn disable_keep_alive_post_request() {
871871
#[test]
872872
fn empty_parse_eof_does_not_return_error() {
873873
let runtime = Runtime::new().unwrap();
874-
let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.handle()).unwrap();
874+
let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.reactor()).unwrap();
875875
let addr = listener.local_addr().unwrap();
876876

877877
thread::spawn(move || {
@@ -892,7 +892,7 @@ fn empty_parse_eof_does_not_return_error() {
892892
#[test]
893893
fn nonempty_parse_eof_returns_error() {
894894
let runtime = Runtime::new().unwrap();
895-
let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.handle()).unwrap();
895+
let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.reactor()).unwrap();
896896
let addr = listener.local_addr().unwrap();
897897

898898
thread::spawn(move || {
@@ -915,7 +915,7 @@ fn nonempty_parse_eof_returns_error() {
915915
#[test]
916916
fn returning_1xx_response_is_error() {
917917
let runtime = Runtime::new().unwrap();
918-
let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.handle()).unwrap();
918+
let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.reactor()).unwrap();
919919
let addr = listener.local_addr().unwrap();
920920

921921
thread::spawn(move || {
@@ -951,7 +951,7 @@ fn upgrades() {
951951
use tokio_io::io::{read_to_end, write_all};
952952
let _ = pretty_env_logger::try_init();
953953
let runtime = Runtime::new().unwrap();
954-
let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.handle()).unwrap();
954+
let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.reactor()).unwrap();
955955
let addr = listener.local_addr().unwrap();
956956
let (tx, rx) = oneshot::channel();
957957

@@ -1016,7 +1016,7 @@ fn upgrades() {
10161016
#[test]
10171017
fn parse_errors_send_4xx_response() {
10181018
let runtime = Runtime::new().unwrap();
1019-
let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.handle()).unwrap();
1019+
let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.reactor()).unwrap();
10201020
let addr = listener.local_addr().unwrap();
10211021

10221022
thread::spawn(move || {
@@ -1045,7 +1045,7 @@ fn parse_errors_send_4xx_response() {
10451045
#[test]
10461046
fn illegal_request_length_returns_400_response() {
10471047
let runtime = Runtime::new().unwrap();
1048-
let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.handle()).unwrap();
1048+
let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.reactor()).unwrap();
10491049
let addr = listener.local_addr().unwrap();
10501050

10511051
thread::spawn(move || {
@@ -1075,7 +1075,7 @@ fn illegal_request_length_returns_400_response() {
10751075
fn max_buf_size() {
10761076
let _ = pretty_env_logger::try_init();
10771077
let runtime = Runtime::new().unwrap();
1078-
let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.handle()).unwrap();
1078+
let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.reactor()).unwrap();
10791079
let addr = listener.local_addr().unwrap();
10801080

10811081
const MAX: usize = 16_000;
@@ -1109,7 +1109,7 @@ fn max_buf_size() {
11091109
fn streaming_body() {
11101110
let _ = pretty_env_logger::try_init();
11111111
let runtime = Runtime::new().unwrap();
1112-
let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.handle()).unwrap();
1112+
let listener = tcp_bind(&"127.0.0.1:0".parse().unwrap(), &runtime.reactor()).unwrap();
11131113
let addr = listener.local_addr().unwrap();
11141114

11151115
let (tx, rx) = oneshot::channel();

0 commit comments

Comments
 (0)