Revert "refactor(lib): convert to futures 0.2.0-beta (#1470)"
This reverts commit a12f7beed9.
Much sadness 😢.
This commit is contained in:
341
tests/client.rs
341
tests/client.rs
@@ -5,6 +5,7 @@ extern crate futures;
|
||||
extern crate futures_timer;
|
||||
extern crate net2;
|
||||
extern crate tokio;
|
||||
extern crate tokio_io;
|
||||
extern crate pretty_env_logger;
|
||||
|
||||
use std::io::{self, Read, Write};
|
||||
@@ -14,9 +15,8 @@ use std::time::Duration;
|
||||
|
||||
use hyper::{Body, Client, Method, Request, StatusCode};
|
||||
|
||||
use futures::{FutureExt, StreamExt};
|
||||
use futures::channel::oneshot;
|
||||
use futures::executor::block_on;
|
||||
use futures::{Future, Stream};
|
||||
use futures::sync::oneshot;
|
||||
use tokio::reactor::Handle;
|
||||
use tokio::runtime::Runtime;
|
||||
use tokio::net::{ConnectFuture, TcpStream};
|
||||
@@ -111,7 +111,11 @@ macro_rules! test {
|
||||
assert_eq!(res.headers()[$response_header_name], $response_header_val);
|
||||
)*
|
||||
|
||||
let body = block_on(res.into_body().into_stream().concat())
|
||||
let body = res
|
||||
.into_body()
|
||||
.into_stream()
|
||||
.concat2()
|
||||
.wait()
|
||||
.expect("body concat wait");
|
||||
|
||||
let expected_res_body = Option::<&[u8]>::from($response_body)
|
||||
@@ -182,7 +186,7 @@ macro_rules! test {
|
||||
if !$set_host {
|
||||
config = config.set_host(false);
|
||||
}
|
||||
let client = config.build(&runtime.handle());
|
||||
let client = config.build_with_executor(&runtime.handle(), runtime.executor());
|
||||
|
||||
let body = if let Some(body) = $request_body {
|
||||
let body: &'static str = body;
|
||||
@@ -199,7 +203,7 @@ macro_rules! test {
|
||||
.body(body)
|
||||
.expect("request builder");
|
||||
|
||||
let res = client.request(req).with_executor(runtime.executor());
|
||||
let res = client.request(req);
|
||||
|
||||
let (tx, rx) = oneshot::channel();
|
||||
|
||||
@@ -226,7 +230,7 @@ macro_rules! test {
|
||||
|
||||
let rx = rx.map_err(|_| hyper::Error::Io(io::Error::new(io::ErrorKind::Other, "thread panicked")));
|
||||
|
||||
block_on(res.join(rx).map(|r| r.0))
|
||||
res.join(rx).map(|r| r.0).wait()
|
||||
});
|
||||
}
|
||||
|
||||
@@ -638,15 +642,12 @@ mod dispatch_impl {
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
use futures::{self, Future, FutureExt, Stream, StreamExt};
|
||||
use futures::channel::{mpsc, oneshot};
|
||||
use futures::io::{AsyncRead, AsyncWrite};
|
||||
use futures::future::lazy;
|
||||
use futures::executor::block_on;
|
||||
use futures::task;
|
||||
use futures::{self, Future};
|
||||
use futures::sync::{mpsc, oneshot};
|
||||
use futures_timer::Delay;
|
||||
use tokio::net::TcpStream;
|
||||
use tokio::runtime::Runtime;
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
use hyper::client::connect::{Connect, Connected, Destination, HttpConnector};
|
||||
use hyper::Client;
|
||||
@@ -665,7 +666,7 @@ mod dispatch_impl {
|
||||
let (closes_tx, closes) = mpsc::channel(10);
|
||||
let client = Client::configure()
|
||||
.connector(DebugConnector::with_http_and_closes(HttpConnector::new(1, &runtime.handle()), closes_tx))
|
||||
.build();
|
||||
.executor(runtime.executor());
|
||||
|
||||
let (tx1, rx1) = oneshot::channel();
|
||||
|
||||
@@ -685,15 +686,15 @@ mod dispatch_impl {
|
||||
.uri(&*format!("http://{}/a", addr))
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
let res = client.request(req).with_executor(runtime.executor()).and_then(move |res| {
|
||||
let res = client.request(req).and_then(move |res| {
|
||||
assert_eq!(res.status(), hyper::StatusCode::OK);
|
||||
Delay::new(Duration::from_secs(1))
|
||||
.err_into()
|
||||
.from_err()
|
||||
});
|
||||
let rx = rx1.map_err(|_| hyper::Error::Io(io::Error::new(io::ErrorKind::Other, "thread panicked")));
|
||||
block_on(res.join(rx).map(|r| r.0)).unwrap();
|
||||
res.join(rx).map(|r| r.0).wait().unwrap();
|
||||
|
||||
block_on(closes.next()).unwrap().0.expect("closes");
|
||||
closes.into_future().wait().unwrap().0.expect("closes");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -724,25 +725,25 @@ mod dispatch_impl {
|
||||
let res = {
|
||||
let client = Client::configure()
|
||||
.connector(DebugConnector::with_http_and_closes(HttpConnector::new(1, &handle), closes_tx))
|
||||
.build();
|
||||
.executor(runtime.executor());
|
||||
|
||||
let req = Request::builder()
|
||||
.uri(&*format!("http://{}/a", addr))
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
client.request(req).with_executor(runtime.executor()).and_then(move |res| {
|
||||
client.request(req).and_then(move |res| {
|
||||
assert_eq!(res.status(), hyper::StatusCode::OK);
|
||||
res.into_body().into_stream().concat()
|
||||
res.into_body().into_stream().concat2()
|
||||
}).and_then(|_| {
|
||||
Delay::new(Duration::from_secs(1))
|
||||
.err_into()
|
||||
.from_err()
|
||||
})
|
||||
};
|
||||
// client is dropped
|
||||
let rx = rx1.map_err(|_| hyper::Error::Io(io::Error::new(io::ErrorKind::Other, "thread panicked")));
|
||||
block_on(res.join(rx).map(|r| r.0)).unwrap();
|
||||
res.join(rx).map(|r| r.0).wait().unwrap();
|
||||
|
||||
block_on(closes.next()).unwrap().0.expect("closes");
|
||||
closes.into_future().wait().unwrap().0.expect("closes");
|
||||
}
|
||||
|
||||
|
||||
@@ -772,41 +773,41 @@ mod dispatch_impl {
|
||||
|
||||
// prevent this thread from closing until end of test, so the connection
|
||||
// stays open and idle until Client is dropped
|
||||
let _ = block_on(client_drop_rx);
|
||||
let _ = client_drop_rx.wait();
|
||||
});
|
||||
|
||||
let client = Client::configure()
|
||||
.connector(DebugConnector::with_http_and_closes(HttpConnector::new(1, &handle), closes_tx))
|
||||
.build();
|
||||
.executor(runtime.executor());
|
||||
|
||||
let req = Request::builder()
|
||||
.uri(&*format!("http://{}/a", addr))
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
let res = client.request(req).with_executor(runtime.executor()).and_then(move |res| {
|
||||
let res = client.request(req).and_then(move |res| {
|
||||
assert_eq!(res.status(), hyper::StatusCode::OK);
|
||||
res.into_body().into_stream().concat()
|
||||
res.into_body().into_stream().concat2()
|
||||
});
|
||||
let rx = rx1.map_err(|_| hyper::Error::Io(io::Error::new(io::ErrorKind::Other, "thread panicked")));
|
||||
block_on(res.join(rx).map(|r| r.0)).unwrap();
|
||||
res.join(rx).map(|r| r.0).wait().unwrap();
|
||||
|
||||
// not closed yet, just idle
|
||||
{
|
||||
block_on(lazy(|cx| {
|
||||
assert!(closes.poll_next(cx).unwrap().is_pending());
|
||||
Ok::<_, ()>(())
|
||||
})).unwrap();
|
||||
futures::future::poll_fn(|| {
|
||||
assert!(closes.poll()?.is_not_ready());
|
||||
Ok::<_, ()>(().into())
|
||||
}).wait().unwrap();
|
||||
}
|
||||
drop(client);
|
||||
|
||||
let t = Delay::new(Duration::from_millis(100))
|
||||
.map(|_| panic!("time out"));
|
||||
let close = closes.next()
|
||||
let close = closes.into_future()
|
||||
.map(|(opt, _)| {
|
||||
opt.expect("closes");
|
||||
})
|
||||
.map_err(|_| panic!("closes dropped"));
|
||||
let _ = block_on(t.select(close));
|
||||
let _ = t.select(close).wait();
|
||||
}
|
||||
|
||||
|
||||
@@ -835,32 +836,32 @@ mod dispatch_impl {
|
||||
|
||||
// prevent this thread from closing until end of test, so the connection
|
||||
// stays open and idle until Client is dropped
|
||||
let _ = block_on(client_drop_rx);
|
||||
let _ = client_drop_rx.wait();
|
||||
});
|
||||
|
||||
let res = {
|
||||
let client = Client::configure()
|
||||
.connector(DebugConnector::with_http_and_closes(HttpConnector::new(1, &handle), closes_tx))
|
||||
.build();
|
||||
.executor(runtime.executor());
|
||||
|
||||
let req = Request::builder()
|
||||
.uri(&*format!("http://{}/a", addr))
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
client.request(req).with_executor(runtime.executor())
|
||||
client.request(req)
|
||||
};
|
||||
|
||||
//let rx = rx1.map_err(|_| hyper::Error::Io(io::Error::new(io::ErrorKind::Other, "thread panicked")));
|
||||
block_on(res.select(rx1)).unwrap();
|
||||
res.select2(rx1).wait().unwrap();
|
||||
// res now dropped
|
||||
let t = Delay::new(Duration::from_millis(100))
|
||||
.map(|_| panic!("time out"));
|
||||
let close = closes.next()
|
||||
let close = closes.into_future()
|
||||
.map(|(opt, _)| {
|
||||
opt.expect("closes");
|
||||
})
|
||||
.map_err(|_| panic!("closes dropped"));
|
||||
let _ = block_on(t.select(close));
|
||||
let _ = t.select(close).wait();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -887,33 +888,33 @@ mod dispatch_impl {
|
||||
|
||||
// prevent this thread from closing until end of test, so the connection
|
||||
// stays open and idle until Client is dropped
|
||||
let _ = block_on(client_drop_rx);
|
||||
let _ = client_drop_rx.wait();
|
||||
});
|
||||
|
||||
let res = {
|
||||
let client = Client::configure()
|
||||
.connector(DebugConnector::with_http_and_closes(HttpConnector::new(1, &handle), closes_tx))
|
||||
.build();
|
||||
.executor(runtime.executor());
|
||||
|
||||
let req = Request::builder()
|
||||
.uri(&*format!("http://{}/a", addr))
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
// notably, havent read body yet
|
||||
client.request(req).with_executor(runtime.executor())
|
||||
client.request(req)
|
||||
};
|
||||
|
||||
let rx = rx1.map_err(|_| hyper::Error::Io(io::Error::new(io::ErrorKind::Other, "thread panicked")));
|
||||
block_on(res.join(rx).map(|r| r.0)).unwrap();
|
||||
res.join(rx).map(|r| r.0).wait().unwrap();
|
||||
|
||||
let t = Delay::new(Duration::from_millis(100))
|
||||
.map(|_| panic!("time out"));
|
||||
let close = closes.next()
|
||||
let close = closes.into_future()
|
||||
.map(|(opt, _)| {
|
||||
opt.expect("closes");
|
||||
})
|
||||
.map_err(|_| panic!("closes dropped"));
|
||||
let _ = block_on(t.select(close));
|
||||
let _ = t.select(close).wait();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -938,33 +939,33 @@ mod dispatch_impl {
|
||||
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();
|
||||
let _ = tx1.send(());
|
||||
let _ = block_on(rx2);
|
||||
let _ = rx2.wait();
|
||||
});
|
||||
|
||||
let client = Client::configure()
|
||||
.connector(DebugConnector::with_http_and_closes(HttpConnector::new(1, &handle), closes_tx))
|
||||
.keep_alive(false)
|
||||
.build();
|
||||
.executor(runtime.executor());
|
||||
|
||||
let req = Request::builder()
|
||||
.uri(&*format!("http://{}/a", addr))
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
let res = client.request(req).with_executor(runtime.executor()).and_then(move |res| {
|
||||
let res = client.request(req).and_then(move |res| {
|
||||
assert_eq!(res.status(), hyper::StatusCode::OK);
|
||||
res.into_body().into_stream().concat()
|
||||
res.into_body().into_stream().concat2()
|
||||
});
|
||||
let rx = rx1.map_err(|_| hyper::Error::Io(io::Error::new(io::ErrorKind::Other, "thread panicked")));
|
||||
block_on(res.join(rx).map(|r| r.0)).unwrap();
|
||||
res.join(rx).map(|r| r.0).wait().unwrap();
|
||||
|
||||
let t = Delay::new(Duration::from_millis(100))
|
||||
.map(|_| panic!("time out"));
|
||||
let close = closes.next()
|
||||
let close = closes.into_future()
|
||||
.map(|(opt, _)| {
|
||||
opt.expect("closes");
|
||||
})
|
||||
.map_err(|_| panic!("closes dropped"));
|
||||
let _ = block_on(t.select(close));
|
||||
let _ = t.select(close).wait();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -992,28 +993,28 @@ mod dispatch_impl {
|
||||
|
||||
let client = Client::configure()
|
||||
.connector(DebugConnector::with_http_and_closes(HttpConnector::new(1, &handle), closes_tx))
|
||||
.build();
|
||||
.executor(runtime.executor());
|
||||
|
||||
let req = Request::builder()
|
||||
.uri(&*format!("http://{}/a", addr))
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
let res = client.request(req).with_executor(runtime.executor()).and_then(move |res| {
|
||||
let res = client.request(req).and_then(move |res| {
|
||||
assert_eq!(res.status(), hyper::StatusCode::OK);
|
||||
res.into_body().into_stream().concat()
|
||||
res.into_body().into_stream().concat2()
|
||||
});
|
||||
let rx = rx1.map_err(|_| hyper::Error::Io(io::Error::new(io::ErrorKind::Other, "thread panicked")));
|
||||
block_on(res.join(rx).map(|r| r.0)).unwrap();
|
||||
res.join(rx).map(|r| r.0).wait().unwrap();
|
||||
|
||||
|
||||
let t = Delay::new(Duration::from_millis(100))
|
||||
.map(|_| panic!("time out"));
|
||||
let close = closes.next()
|
||||
let close = closes.into_future()
|
||||
.map(|(opt, _)| {
|
||||
opt.expect("closes");
|
||||
})
|
||||
.map_err(|_| panic!("closes dropped"));
|
||||
let _ = block_on(t.select(close));
|
||||
let _ = t.select(close).wait();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1025,13 +1026,11 @@ mod dispatch_impl {
|
||||
// See https://github.com/hyperium/hyper/issues/1429
|
||||
|
||||
use std::error::Error;
|
||||
use tokio::prelude::Future;
|
||||
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 executor = runtime.executor();
|
||||
let handle = runtime.handle().clone();
|
||||
|
||||
let (tx1, rx1) = oneshot::channel();
|
||||
@@ -1043,27 +1042,27 @@ mod dispatch_impl {
|
||||
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");
|
||||
sock.read(&mut buf).expect("read 2");
|
||||
let _ = tx1.send(());
|
||||
});
|
||||
|
||||
let uri = format!("http://{}/a", addr).parse::<hyper::Uri>().unwrap();
|
||||
|
||||
let client = Client::configure().build(&handle);
|
||||
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).with_executor(executor.clone()).and_then(move |res| {
|
||||
let res = client.request(req).and_then(move |res| {
|
||||
assert_eq!(res.status(), hyper::StatusCode::OK);
|
||||
res.into_body().into_stream().concat()
|
||||
res.into_body().into_stream().concat2()
|
||||
});
|
||||
|
||||
block_on(res).unwrap();
|
||||
res.wait().unwrap();
|
||||
|
||||
// shut down runtime
|
||||
runtime.shutdown_now().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()));
|
||||
@@ -1072,10 +1071,10 @@ mod dispatch_impl {
|
||||
.uri(uri)
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
let res = client.request(req).with_executor(executor);
|
||||
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 = block_on(res.join(rx).map(|r| r.0)).unwrap_err();
|
||||
let err = res.join(rx).map(|r| r.0).wait().unwrap_err();
|
||||
assert_eq!(err.description(), "event loop gone");
|
||||
}
|
||||
|
||||
@@ -1101,31 +1100,31 @@ mod dispatch_impl {
|
||||
|
||||
let client = Client::configure()
|
||||
.connector(DebugConnector::with_http_and_closes(HttpConnector::new(1, &handle), closes_tx))
|
||||
.build();
|
||||
.executor(runtime.executor());
|
||||
|
||||
let req = Request::builder()
|
||||
.uri(&*format!("http://{}/a", addr))
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
let res = client.request(req).with_executor(runtime.executor()).and_then(move |res| {
|
||||
let res = client.request(req).and_then(move |res| {
|
||||
assert_eq!(res.status(), hyper::StatusCode::OK);
|
||||
res.into_body().into_stream().concat()
|
||||
res.into_body().into_stream().concat2()
|
||||
});
|
||||
let rx = rx1.map_err(|_| hyper::Error::Io(io::Error::new(io::ErrorKind::Other, "thread panicked")));
|
||||
|
||||
let timeout = Delay::new(Duration::from_millis(200));
|
||||
let rx = rx.and_then(move |_| timeout.map_err(|e| e.into()));
|
||||
block_on(res.join(rx).map(|r| r.0)).unwrap();
|
||||
res.join(rx).map(|r| r.0).wait().unwrap();
|
||||
|
||||
|
||||
let t = Delay::new(Duration::from_millis(100))
|
||||
.map(|_| panic!("time out"));
|
||||
let close = closes.next()
|
||||
let close = closes.into_future()
|
||||
.map(|(opt, _)| {
|
||||
opt.expect("closes");
|
||||
})
|
||||
.map_err(|_| panic!("closes dropped"));
|
||||
let _ = block_on(t.select(close));
|
||||
let _ = t.select(close).wait();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1141,14 +1140,14 @@ mod dispatch_impl {
|
||||
|
||||
let client = Client::configure()
|
||||
.connector(connector)
|
||||
.build();
|
||||
.executor(runtime.executor());
|
||||
|
||||
assert_eq!(connects.load(Ordering::Relaxed), 0);
|
||||
let req = Request::builder()
|
||||
.uri("http://hyper.local/a")
|
||||
.body(Default::default())
|
||||
.unwrap();
|
||||
let _fut = client.request(req).with_executor(runtime.executor());
|
||||
let _fut = client.request(req);
|
||||
// internal Connect::connect should have been lazy, and not
|
||||
// triggered an actual connect yet.
|
||||
assert_eq!(connects.load(Ordering::Relaxed), 0);
|
||||
@@ -1166,7 +1165,7 @@ mod dispatch_impl {
|
||||
|
||||
let client = Client::configure()
|
||||
.connector(connector)
|
||||
.build();
|
||||
.executor(runtime.executor());
|
||||
|
||||
let (tx1, rx1) = oneshot::channel();
|
||||
let (tx2, rx2) = oneshot::channel();
|
||||
@@ -1196,8 +1195,8 @@ mod dispatch_impl {
|
||||
.uri(&*format!("http://{}/a", addr))
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
let res = client.request(req).with_executor(runtime.executor());
|
||||
block_on(res.join(rx).map(|r| r.0)).unwrap();
|
||||
let res = client.request(req);
|
||||
res.join(rx).map(|r| r.0).wait().unwrap();
|
||||
|
||||
assert_eq!(connects.load(Ordering::SeqCst), 1);
|
||||
|
||||
@@ -1210,8 +1209,8 @@ mod dispatch_impl {
|
||||
.uri(&*format!("http://{}/b", addr))
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
let res = client.request(req).with_executor(runtime.executor());
|
||||
block_on(res.join(rx).map(|r| r.0)).unwrap();
|
||||
let res = client.request(req);
|
||||
res.join(rx).map(|r| r.0).wait().unwrap();
|
||||
|
||||
assert_eq!(connects.load(Ordering::SeqCst), 1, "second request should still only have 1 connect");
|
||||
}
|
||||
@@ -1229,7 +1228,7 @@ mod dispatch_impl {
|
||||
|
||||
let client = Client::configure()
|
||||
.connector(connector)
|
||||
.build();
|
||||
.executor(runtime.executor());
|
||||
|
||||
let (tx1, rx1) = oneshot::channel();
|
||||
let (tx2, rx2) = oneshot::channel();
|
||||
@@ -1262,8 +1261,8 @@ mod dispatch_impl {
|
||||
.uri(&*format!("http://{}/a", addr))
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
let res = client.request(req).with_executor(runtime.executor());
|
||||
block_on(res.join(rx).map(|r| r.0)).unwrap();
|
||||
let res = client.request(req);
|
||||
res.join(rx).map(|r| r.0).wait().unwrap();
|
||||
|
||||
assert_eq!(connects.load(Ordering::Relaxed), 1);
|
||||
|
||||
@@ -1272,8 +1271,8 @@ mod dispatch_impl {
|
||||
.uri(&*format!("http://{}/b", addr))
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
let res = client.request(req).with_executor(runtime.executor());
|
||||
block_on(res.join(rx).map(|r| r.0)).unwrap();
|
||||
let res = client.request(req);
|
||||
res.join(rx).map(|r| r.0).wait().unwrap();
|
||||
|
||||
assert_eq!(connects.load(Ordering::Relaxed), 2);
|
||||
}
|
||||
@@ -1290,7 +1289,7 @@ mod dispatch_impl {
|
||||
|
||||
let client = Client::configure()
|
||||
.connector(connector)
|
||||
.build();
|
||||
.executor(runtime.executor());
|
||||
|
||||
let (tx1, rx1) = oneshot::channel();
|
||||
thread::spawn(move || {
|
||||
@@ -1313,8 +1312,8 @@ mod dispatch_impl {
|
||||
.uri(&*format!("http://{}/foo/bar", addr))
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
let res = client.request(req).with_executor(runtime.executor());
|
||||
block_on(res.join(rx).map(|r| r.0)).unwrap();
|
||||
let res = client.request(req);
|
||||
res.join(rx).map(|r| r.0).wait().unwrap();
|
||||
}
|
||||
|
||||
|
||||
@@ -1370,25 +1369,33 @@ mod dispatch_impl {
|
||||
}
|
||||
}
|
||||
|
||||
impl Write for DebugStream {
|
||||
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
||||
self.0.write(buf)
|
||||
}
|
||||
|
||||
fn flush(&mut self) -> io::Result<()> {
|
||||
self.0.flush()
|
||||
}
|
||||
}
|
||||
|
||||
impl AsyncWrite for DebugStream {
|
||||
fn poll_write(&mut self, cx: &mut task::Context, buf: &[u8]) -> futures::Poll<usize, io::Error> {
|
||||
self.0.poll_write(cx, buf)
|
||||
fn shutdown(&mut self) -> futures::Poll<(), io::Error> {
|
||||
AsyncWrite::shutdown(&mut self.0)
|
||||
}
|
||||
|
||||
fn poll_flush(&mut self, cx: &mut task::Context) -> futures::Poll<(), io::Error> {
|
||||
self.0.poll_flush(cx)
|
||||
}
|
||||
|
||||
fn poll_close(&mut self, cx: &mut task::Context) -> futures::Poll<(), io::Error> {
|
||||
self.0.poll_close(cx)
|
||||
fn write_buf<B: ::bytes::Buf>(&mut self, buf: &mut B) -> futures::Poll<usize, io::Error> {
|
||||
self.0.write_buf(buf)
|
||||
}
|
||||
}
|
||||
|
||||
impl AsyncRead for DebugStream {
|
||||
fn poll_read(&mut self, cx: &mut task::Context, buf: &mut [u8]) -> futures::Poll<usize, io::Error> {
|
||||
self.0.poll_read(cx, buf)
|
||||
impl Read for DebugStream {
|
||||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||||
self.0.read(buf)
|
||||
}
|
||||
}
|
||||
|
||||
impl AsyncRead for DebugStream {}
|
||||
}
|
||||
|
||||
mod conn {
|
||||
@@ -1397,15 +1404,13 @@ mod conn {
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
use futures::{FutureExt, Poll, StreamExt};
|
||||
use futures::future::{poll_fn, lazy};
|
||||
use futures::channel::oneshot;
|
||||
use futures::task;
|
||||
use futures::io::{AsyncRead, AsyncWrite};
|
||||
use futures::executor::block_on;
|
||||
use futures::{Async, Future, Poll, Stream};
|
||||
use futures::future::poll_fn;
|
||||
use futures::sync::oneshot;
|
||||
use futures_timer::Delay;
|
||||
use tokio::runtime::Runtime;
|
||||
use tokio::net::TcpStream;
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
use hyper::{self, Request};
|
||||
use hyper::client::conn;
|
||||
@@ -1437,11 +1442,11 @@ mod conn {
|
||||
let _ = tx1.send(());
|
||||
});
|
||||
|
||||
let tcp = block_on(tcp_connect(&addr)).unwrap();
|
||||
let tcp = tcp_connect(&addr).wait().unwrap();
|
||||
|
||||
let (mut client, conn) = block_on(conn::handshake(tcp)).unwrap();
|
||||
let (mut client, conn) = conn::handshake(tcp).wait().unwrap();
|
||||
|
||||
runtime.spawn2(conn.map(|_| ()).map_err(|e| panic!("conn error: {}", e)));
|
||||
runtime.spawn(conn.map(|_| ()).map_err(|e| panic!("conn error: {}", e)));
|
||||
|
||||
let req = Request::builder()
|
||||
.uri("/a")
|
||||
@@ -1449,13 +1454,13 @@ mod conn {
|
||||
.unwrap();
|
||||
let res = client.send_request(req).and_then(move |res| {
|
||||
assert_eq!(res.status(), hyper::StatusCode::OK);
|
||||
res.into_body().into_stream().concat()
|
||||
res.into_body().into_stream().concat2()
|
||||
});
|
||||
let rx = rx1.map_err(|_| hyper::Error::Io(io::Error::new(io::ErrorKind::Other, "thread panicked")));
|
||||
|
||||
let timeout = Delay::new(Duration::from_millis(200));
|
||||
let rx = rx.and_then(move |_| timeout.map_err(|e| e.into()));
|
||||
block_on(res.join(rx).map(|r| r.0)).unwrap();
|
||||
res.join(rx).map(|r| r.0).wait().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1482,11 +1487,11 @@ mod conn {
|
||||
let _ = tx1.send(());
|
||||
});
|
||||
|
||||
let tcp = block_on(tcp_connect(&addr)).unwrap();
|
||||
let tcp = tcp_connect(&addr).wait().unwrap();
|
||||
|
||||
let (mut client, conn) = block_on(conn::handshake(tcp)).unwrap();
|
||||
let (mut client, conn) = conn::handshake(tcp).wait().unwrap();
|
||||
|
||||
runtime.spawn2(conn.map(|_| ()).map_err(|e| panic!("conn error: {}", e)));
|
||||
runtime.spawn(conn.map(|_| ()).map_err(|e| panic!("conn error: {}", e)));
|
||||
|
||||
let req = Request::builder()
|
||||
.uri("http://hyper.local/a")
|
||||
@@ -1495,13 +1500,13 @@ mod conn {
|
||||
|
||||
let res = client.send_request(req).and_then(move |res| {
|
||||
assert_eq!(res.status(), hyper::StatusCode::OK);
|
||||
res.into_body().into_stream().concat()
|
||||
res.into_body().into_stream().concat2()
|
||||
});
|
||||
let rx = rx1.map_err(|_| hyper::Error::Io(io::Error::new(io::ErrorKind::Other, "thread panicked")));
|
||||
|
||||
let timeout = Delay::new(Duration::from_millis(200));
|
||||
let rx = rx.and_then(move |_| timeout.map_err(|e| e.into()));
|
||||
block_on(res.join(rx).map(|r| r.0)).unwrap();
|
||||
res.join(rx).map(|r| r.0).wait().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1523,11 +1528,11 @@ mod conn {
|
||||
let _ = tx1.send(());
|
||||
});
|
||||
|
||||
let tcp = block_on(tcp_connect(&addr)).unwrap();
|
||||
let tcp = tcp_connect(&addr).wait().unwrap();
|
||||
|
||||
let (mut client, conn) = block_on(conn::handshake(tcp)).unwrap();
|
||||
let (mut client, conn) = conn::handshake(tcp).wait().unwrap();
|
||||
|
||||
runtime.spawn2(conn.map(|_| ()).map_err(|e| panic!("conn error: {}", e)));
|
||||
runtime.spawn(conn.map(|_| ()).map_err(|e| panic!("conn error: {}", e)));
|
||||
|
||||
let req = Request::builder()
|
||||
.uri("/a")
|
||||
@@ -1535,10 +1540,10 @@ mod conn {
|
||||
.unwrap();
|
||||
let res1 = client.send_request(req).and_then(move |res| {
|
||||
assert_eq!(res.status(), hyper::StatusCode::OK);
|
||||
res.into_body().into_stream().concat()
|
||||
res.into_body().into_stream().concat2()
|
||||
});
|
||||
|
||||
// pipelined request will hit Pending, and thus should return an Error::Cancel
|
||||
// pipelined request will hit NotReady, and thus should return an Error::Cancel
|
||||
let req = Request::builder()
|
||||
.uri("/b")
|
||||
.body(Default::default())
|
||||
@@ -1557,12 +1562,12 @@ mod conn {
|
||||
|
||||
let timeout = Delay::new(Duration::from_millis(200));
|
||||
let rx = rx.and_then(move |_| timeout.map_err(|e| e.into()));
|
||||
block_on(res1.join(res2).join(rx).map(|r| r.0)).unwrap();
|
||||
res1.join(res2).join(rx).map(|r| r.0).wait().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn upgrade() {
|
||||
use futures::io::{AsyncReadExt, AsyncWriteExt};
|
||||
use tokio_io::io::{read_to_end, write_all};
|
||||
let _ = ::pretty_env_logger::try_init();
|
||||
|
||||
let server = TcpListener::bind("127.0.0.1:0").unwrap();
|
||||
@@ -1590,18 +1595,18 @@ mod conn {
|
||||
sock.write_all(b"bar=foo").expect("write 2");
|
||||
});
|
||||
|
||||
let tcp = block_on(tcp_connect(&addr)).unwrap();
|
||||
let tcp = tcp_connect(&addr).wait().unwrap();
|
||||
|
||||
let io = DebugStream {
|
||||
tcp: tcp,
|
||||
shutdown_called: false,
|
||||
};
|
||||
|
||||
let (mut client, mut conn) = block_on(conn::handshake(io)).unwrap();
|
||||
let (mut client, mut conn) = conn::handshake(io).wait().unwrap();
|
||||
|
||||
{
|
||||
let until_upgrade = poll_fn(|cx| {
|
||||
conn.poll_without_shutdown(cx)
|
||||
let until_upgrade = poll_fn(|| {
|
||||
conn.poll_without_shutdown()
|
||||
});
|
||||
|
||||
let req = Request::builder()
|
||||
@@ -1611,20 +1616,20 @@ mod conn {
|
||||
let res = client.send_request(req).and_then(move |res| {
|
||||
assert_eq!(res.status(), hyper::StatusCode::SWITCHING_PROTOCOLS);
|
||||
assert_eq!(res.headers()["Upgrade"], "foobar");
|
||||
res.into_body().into_stream().concat()
|
||||
res.into_body().into_stream().concat2()
|
||||
});
|
||||
|
||||
let rx = rx1.map_err(|_| hyper::Error::Io(io::Error::new(io::ErrorKind::Other, "thread panicked")));
|
||||
|
||||
let timeout = Delay::new(Duration::from_millis(200));
|
||||
let rx = rx.and_then(move |_| timeout.map_err(|e| e.into()));
|
||||
block_on(until_upgrade.join(res).join(rx).map(|r| r.0)).unwrap();
|
||||
until_upgrade.join(res).join(rx).map(|r| r.0).wait().unwrap();
|
||||
|
||||
// should not be ready now
|
||||
block_on(lazy(|cx| {
|
||||
assert!(client.poll_ready(cx).unwrap().is_pending());
|
||||
Ok::<_, ()>(())
|
||||
})).unwrap();
|
||||
poll_fn(|| {
|
||||
assert!(client.poll_ready().unwrap().is_not_ready());
|
||||
Ok::<_, ()>(Async::Ready(()))
|
||||
}).wait().unwrap();
|
||||
}
|
||||
|
||||
let parts = conn.into_parts();
|
||||
@@ -1633,16 +1638,16 @@ mod conn {
|
||||
|
||||
assert_eq!(buf, b"foobar=ready"[..]);
|
||||
assert!(!io.shutdown_called, "upgrade shouldn't shutdown AsyncWrite");
|
||||
assert!(block_on(poll_fn(|cx| client.poll_ready(cx))).is_err());
|
||||
assert!(client.poll_ready().is_err());
|
||||
|
||||
let io = block_on(io.write_all(b"foo=bar")).unwrap().0;
|
||||
let vec = block_on(io.read_to_end(vec![])).unwrap().1;
|
||||
let io = write_all(io, b"foo=bar").wait().unwrap().0;
|
||||
let vec = read_to_end(io, vec![]).wait().unwrap().1;
|
||||
assert_eq!(vec, b"bar=foo");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn connect_method() {
|
||||
use futures::io::{AsyncReadExt, AsyncWriteExt};
|
||||
use tokio_io::io::{read_to_end, write_all};
|
||||
let _ = ::pretty_env_logger::try_init();
|
||||
|
||||
let server = TcpListener::bind("127.0.0.1:0").unwrap();
|
||||
@@ -1669,18 +1674,18 @@ mod conn {
|
||||
sock.write_all(b"bar=foo").expect("write 2");
|
||||
});
|
||||
|
||||
let tcp = block_on(tcp_connect(&addr)).unwrap();
|
||||
let tcp = tcp_connect(&addr).wait().unwrap();
|
||||
|
||||
let io = DebugStream {
|
||||
tcp: tcp,
|
||||
shutdown_called: false,
|
||||
};
|
||||
|
||||
let (mut client, mut conn) = block_on(conn::handshake(io)).unwrap();
|
||||
let (mut client, mut conn) = conn::handshake(io).wait().unwrap();
|
||||
|
||||
{
|
||||
let until_tunneled = poll_fn(|cx| {
|
||||
conn.poll_without_shutdown(cx)
|
||||
let until_tunneled = poll_fn(|| {
|
||||
conn.poll_without_shutdown()
|
||||
});
|
||||
|
||||
let req = Request::builder()
|
||||
@@ -1691,7 +1696,7 @@ mod conn {
|
||||
let res = client.send_request(req)
|
||||
.and_then(move |res| {
|
||||
assert_eq!(res.status(), hyper::StatusCode::OK);
|
||||
res.into_body().into_stream().concat()
|
||||
res.into_body().into_stream().concat2()
|
||||
})
|
||||
.map(|body| {
|
||||
assert_eq!(body.as_ref(), b"");
|
||||
@@ -1701,13 +1706,13 @@ mod conn {
|
||||
|
||||
let timeout = Delay::new(Duration::from_millis(200));
|
||||
let rx = rx.and_then(move |_| timeout.map_err(|e| e.into()));
|
||||
block_on(until_tunneled.join(res).join(rx).map(|r| r.0)).unwrap();
|
||||
until_tunneled.join(res).join(rx).map(|r| r.0).wait().unwrap();
|
||||
|
||||
// should not be ready now
|
||||
block_on(lazy(|cx| {
|
||||
assert!(client.poll_ready(cx).unwrap().is_pending());
|
||||
Ok::<_, ()>(())
|
||||
})).unwrap();
|
||||
poll_fn(|| {
|
||||
assert!(client.poll_ready().unwrap().is_not_ready());
|
||||
Ok::<_, ()>(Async::Ready(()))
|
||||
}).wait().unwrap();
|
||||
}
|
||||
|
||||
let parts = conn.into_parts();
|
||||
@@ -1716,10 +1721,10 @@ mod conn {
|
||||
|
||||
assert_eq!(buf, b"foobar=ready"[..]);
|
||||
assert!(!io.shutdown_called, "tunnel shouldn't shutdown AsyncWrite");
|
||||
assert!(block_on(poll_fn(|cx| client.poll_ready(cx))).is_err());
|
||||
assert!(client.poll_ready().is_err());
|
||||
|
||||
let io = block_on(io.write_all(b"foo=bar")).unwrap().0;
|
||||
let vec = block_on(io.read_to_end(vec![])).unwrap().1;
|
||||
let io = write_all(io, b"foo=bar").wait().unwrap().0;
|
||||
let vec = read_to_end(io, vec![]).wait().unwrap().1;
|
||||
assert_eq!(vec, b"bar=foo");
|
||||
}
|
||||
|
||||
@@ -1728,24 +1733,28 @@ mod conn {
|
||||
shutdown_called: bool,
|
||||
}
|
||||
|
||||
impl Write for DebugStream {
|
||||
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
||||
self.tcp.write(buf)
|
||||
}
|
||||
|
||||
fn flush(&mut self) -> io::Result<()> {
|
||||
self.tcp.flush()
|
||||
}
|
||||
}
|
||||
|
||||
impl AsyncWrite for DebugStream {
|
||||
fn poll_write(&mut self, cx: &mut task::Context, buf: &[u8]) -> Poll<usize, io::Error> {
|
||||
self.tcp.poll_write(cx, buf)
|
||||
}
|
||||
|
||||
fn poll_flush(&mut self, cx: &mut task::Context) -> Poll<(), io::Error> {
|
||||
self.tcp.poll_flush(cx)
|
||||
}
|
||||
|
||||
fn poll_close(&mut self, cx: &mut task::Context) -> Poll<(), io::Error> {
|
||||
fn shutdown(&mut self) -> Poll<(), io::Error> {
|
||||
self.shutdown_called = true;
|
||||
self.tcp.poll_close(cx)
|
||||
AsyncWrite::shutdown(&mut self.tcp)
|
||||
}
|
||||
}
|
||||
|
||||
impl AsyncRead for DebugStream {
|
||||
fn poll_read(&mut self, cx: &mut task::Context, buf: &mut [u8]) -> Poll<usize, io::Error> {
|
||||
self.tcp.poll_read(cx, buf)
|
||||
impl Read for DebugStream {
|
||||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||||
self.tcp.read(buf)
|
||||
}
|
||||
}
|
||||
|
||||
impl AsyncRead for DebugStream {}
|
||||
}
|
||||
|
||||
132
tests/server.rs
132
tests/server.rs
@@ -8,6 +8,7 @@ extern crate net2;
|
||||
extern crate spmc;
|
||||
extern crate pretty_env_logger;
|
||||
extern crate tokio;
|
||||
extern crate tokio_io;
|
||||
|
||||
use std::net::{TcpStream, Shutdown, SocketAddr};
|
||||
use std::io::{self, Read, Write};
|
||||
@@ -18,18 +19,16 @@ use std::net::{TcpListener as StdTcpListener};
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
use futures::{Future, FutureExt, StreamExt};
|
||||
use futures::{Future, Stream};
|
||||
use futures::future::{self, FutureResult, Either};
|
||||
use futures::channel::oneshot;
|
||||
use futures::executor::block_on;
|
||||
use futures::task;
|
||||
use futures::io::{AsyncRead, AsyncWrite};
|
||||
use futures::sync::oneshot;
|
||||
use futures_timer::Delay;
|
||||
use http::header::{HeaderName, HeaderValue};
|
||||
//use net2::TcpBuilder;
|
||||
use tokio::net::TcpListener;
|
||||
use tokio::runtime::Runtime;
|
||||
use tokio::reactor::Handle;
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
|
||||
use hyper::{Body, Request, Response, StatusCode};
|
||||
@@ -92,14 +91,14 @@ fn get_implicitly_empty() {
|
||||
});
|
||||
|
||||
let fut = listener.incoming()
|
||||
.next()
|
||||
.into_future()
|
||||
.map_err(|_| unreachable!())
|
||||
.and_then(|(item, _incoming)| {
|
||||
let socket = item.unwrap();
|
||||
Http::<hyper::Chunk>::new().serve_connection(socket, GetImplicitlyEmpty)
|
||||
});
|
||||
|
||||
block_on(fut).unwrap();
|
||||
fut.wait().unwrap();
|
||||
|
||||
struct GetImplicitlyEmpty;
|
||||
|
||||
@@ -112,7 +111,7 @@ fn get_implicitly_empty() {
|
||||
fn call(&self, req: Request<Body>) -> Self::Future {
|
||||
Box::new(req.into_body()
|
||||
.into_stream()
|
||||
.concat()
|
||||
.concat2()
|
||||
.map(|buf| {
|
||||
assert!(buf.is_empty());
|
||||
Response::new(Body::empty())
|
||||
@@ -766,34 +765,34 @@ fn disable_keep_alive_mid_request() {
|
||||
let mut req = connect(&addr);
|
||||
req.write_all(b"GET / HTTP/1.1\r\n").unwrap();
|
||||
tx1.send(()).unwrap();
|
||||
block_on(rx2).unwrap();
|
||||
rx2.wait().unwrap();
|
||||
req.write_all(b"Host: localhost\r\n\r\n").unwrap();
|
||||
let mut buf = vec![];
|
||||
req.read_to_end(&mut buf).unwrap();
|
||||
});
|
||||
|
||||
let fut = listener.incoming()
|
||||
.next()
|
||||
.into_future()
|
||||
.map_err(|_| unreachable!())
|
||||
.and_then(|(item, _incoming)| {
|
||||
let socket = item.unwrap();
|
||||
Http::<hyper::Chunk>::new().serve_connection(socket, HelloWorld)
|
||||
.select(rx1)
|
||||
.select2(rx1)
|
||||
.then(|r| {
|
||||
match r {
|
||||
Ok(Either::Left(_)) => panic!("expected rx first"),
|
||||
Ok(Either::Right(((), mut conn))) => {
|
||||
Ok(Either::A(_)) => panic!("expected rx first"),
|
||||
Ok(Either::B(((), mut conn))) => {
|
||||
conn.disable_keep_alive();
|
||||
tx2.send(()).unwrap();
|
||||
conn
|
||||
}
|
||||
Err(Either::Left((e, _))) => panic!("unexpected error {}", e),
|
||||
Err(Either::Right((e, _))) => panic!("unexpected error {}", e),
|
||||
Err(Either::A((e, _))) => panic!("unexpected error {}", e),
|
||||
Err(Either::B((e, _))) => panic!("unexpected error {}", e),
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
block_on(fut).unwrap();
|
||||
fut.wait().unwrap();
|
||||
child.join().unwrap();
|
||||
}
|
||||
|
||||
@@ -834,7 +833,7 @@ fn disable_keep_alive_post_request() {
|
||||
let dropped = Dropped::new();
|
||||
let dropped2 = dropped.clone();
|
||||
let fut = listener.incoming()
|
||||
.next()
|
||||
.into_future()
|
||||
.map_err(|_| unreachable!())
|
||||
.and_then(|(item, _incoming)| {
|
||||
let socket = item.expect("accepted socket");
|
||||
@@ -843,28 +842,28 @@ fn disable_keep_alive_post_request() {
|
||||
_debug: dropped2,
|
||||
};
|
||||
Http::<hyper::Chunk>::new().serve_connection(transport, HelloWorld)
|
||||
.select(rx1)
|
||||
.select2(rx1)
|
||||
.then(|r| {
|
||||
match r {
|
||||
Ok(Either::Left(_)) => panic!("expected rx first"),
|
||||
Ok(Either::Right(((), mut conn))) => {
|
||||
Ok(Either::A(_)) => panic!("expected rx first"),
|
||||
Ok(Either::B(((), mut conn))) => {
|
||||
conn.disable_keep_alive();
|
||||
conn
|
||||
}
|
||||
Err(Either::Left((e, _))) => panic!("unexpected error {}", e),
|
||||
Err(Either::Right((e, _))) => panic!("unexpected error {}", e),
|
||||
Err(Either::A((e, _))) => panic!("unexpected error {}", e),
|
||||
Err(Either::B((e, _))) => panic!("unexpected error {}", e),
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
assert!(!dropped.load());
|
||||
block_on(fut).unwrap();
|
||||
fut.wait().unwrap();
|
||||
// we must poll the Core one more time in order for Windows to drop
|
||||
// the read-blocked socket.
|
||||
//
|
||||
// See https://github.com/carllerche/mio/issues/776
|
||||
let timeout = Delay::new(Duration::from_millis(10));
|
||||
block_on(timeout).unwrap();
|
||||
timeout.wait().unwrap();
|
||||
assert!(dropped.load());
|
||||
child.join().unwrap();
|
||||
}
|
||||
@@ -880,14 +879,14 @@ fn empty_parse_eof_does_not_return_error() {
|
||||
});
|
||||
|
||||
let fut = listener.incoming()
|
||||
.next()
|
||||
.into_future()
|
||||
.map_err(|_| unreachable!())
|
||||
.and_then(|(item, _incoming)| {
|
||||
let socket = item.unwrap();
|
||||
Http::<hyper::Chunk>::new().serve_connection(socket, HelloWorld)
|
||||
});
|
||||
|
||||
block_on(fut).unwrap();
|
||||
fut.wait().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -902,7 +901,7 @@ fn nonempty_parse_eof_returns_error() {
|
||||
});
|
||||
|
||||
let fut = listener.incoming()
|
||||
.next()
|
||||
.into_future()
|
||||
.map_err(|_| unreachable!())
|
||||
.and_then(|(item, _incoming)| {
|
||||
let socket = item.unwrap();
|
||||
@@ -910,7 +909,7 @@ fn nonempty_parse_eof_returns_error() {
|
||||
.map(|_| ())
|
||||
});
|
||||
|
||||
block_on(fut).unwrap_err();
|
||||
fut.wait().unwrap_err();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -930,7 +929,7 @@ fn returning_1xx_response_is_error() {
|
||||
});
|
||||
|
||||
let fut = listener.incoming()
|
||||
.next()
|
||||
.into_future()
|
||||
.map_err(|_| unreachable!())
|
||||
.and_then(|(item, _incoming)| {
|
||||
let socket = item.unwrap();
|
||||
@@ -944,12 +943,12 @@ fn returning_1xx_response_is_error() {
|
||||
.map(|_| ())
|
||||
});
|
||||
|
||||
block_on(fut).unwrap_err();
|
||||
fut.wait().unwrap_err();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn upgrades() {
|
||||
use futures::io::{AsyncReadExt, AsyncWriteExt};
|
||||
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();
|
||||
@@ -978,7 +977,7 @@ fn upgrades() {
|
||||
});
|
||||
|
||||
let fut = listener.incoming()
|
||||
.next()
|
||||
.into_future()
|
||||
.map_err(|_| -> hyper::Error { unreachable!() })
|
||||
.and_then(|(item, _incoming)| {
|
||||
let socket = item.unwrap();
|
||||
@@ -993,24 +992,24 @@ fn upgrades() {
|
||||
}));
|
||||
|
||||
let mut conn_opt = Some(conn);
|
||||
future::poll_fn(move |cx| {
|
||||
try_ready!(conn_opt.as_mut().unwrap().poll_without_shutdown(cx));
|
||||
future::poll_fn(move || {
|
||||
try_ready!(conn_opt.as_mut().unwrap().poll_without_shutdown());
|
||||
// conn is done with HTTP now
|
||||
Ok(conn_opt.take().unwrap().into())
|
||||
})
|
||||
});
|
||||
|
||||
let conn = block_on(fut).unwrap();
|
||||
let conn = fut.wait().unwrap();
|
||||
|
||||
// wait so that we don't write until other side saw 101 response
|
||||
block_on(rx).unwrap();
|
||||
rx.wait().unwrap();
|
||||
|
||||
let parts = conn.into_parts();
|
||||
let io = parts.io;
|
||||
assert_eq!(parts.read_buf, "eagerly optimistic");
|
||||
|
||||
let io = block_on(io.write_all(b"foo=bar")).unwrap().0;
|
||||
let vec = block_on(io.read_to_end(vec![])).unwrap().1;
|
||||
let io = write_all(io, b"foo=bar").wait().unwrap().0;
|
||||
let vec = read_to_end(io, vec![]).wait().unwrap().1;
|
||||
assert_eq!(vec, b"bar=foo");
|
||||
}
|
||||
|
||||
@@ -1031,7 +1030,7 @@ fn parse_errors_send_4xx_response() {
|
||||
});
|
||||
|
||||
let fut = listener.incoming()
|
||||
.next()
|
||||
.into_future()
|
||||
.map_err(|_| unreachable!())
|
||||
.and_then(|(item, _incoming)| {
|
||||
let socket = item.unwrap();
|
||||
@@ -1040,7 +1039,7 @@ fn parse_errors_send_4xx_response() {
|
||||
.map(|_| ())
|
||||
});
|
||||
|
||||
block_on(fut).unwrap_err();
|
||||
fut.wait().unwrap_err();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1060,7 +1059,7 @@ fn illegal_request_length_returns_400_response() {
|
||||
});
|
||||
|
||||
let fut = listener.incoming()
|
||||
.next()
|
||||
.into_future()
|
||||
.map_err(|_| unreachable!())
|
||||
.and_then(|(item, _incoming)| {
|
||||
let socket = item.unwrap();
|
||||
@@ -1069,7 +1068,7 @@ fn illegal_request_length_returns_400_response() {
|
||||
.map(|_| ())
|
||||
});
|
||||
|
||||
block_on(fut).unwrap_err();
|
||||
fut.wait().unwrap_err();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1093,7 +1092,7 @@ fn max_buf_size() {
|
||||
});
|
||||
|
||||
let fut = listener.incoming()
|
||||
.next()
|
||||
.into_future()
|
||||
.map_err(|_| unreachable!())
|
||||
.and_then(|(item, _incoming)| {
|
||||
let socket = item.unwrap();
|
||||
@@ -1103,7 +1102,7 @@ fn max_buf_size() {
|
||||
.map(|_| ())
|
||||
});
|
||||
|
||||
block_on(fut).unwrap_err();
|
||||
fut.wait().unwrap_err();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1137,7 +1136,7 @@ fn streaming_body() {
|
||||
let rx = rx.map_err(|_| panic!("thread panicked"));
|
||||
|
||||
let fut = listener.incoming()
|
||||
.next()
|
||||
.into_future()
|
||||
.map_err(|_| unreachable!())
|
||||
.and_then(|(item, _incoming)| {
|
||||
let socket = item.unwrap();
|
||||
@@ -1153,7 +1152,7 @@ fn streaming_body() {
|
||||
.map(|_| ())
|
||||
});
|
||||
|
||||
block_on(fut.join(rx)).unwrap();
|
||||
fut.join(rx).wait().unwrap();
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
@@ -1293,7 +1292,7 @@ impl Service for TestService {
|
||||
Ok(())
|
||||
}).then(move |result| {
|
||||
let msg = match result {
|
||||
Ok(_) => Msg::End,
|
||||
Ok(()) => Msg::End,
|
||||
Err(e) => Msg::Error(e),
|
||||
};
|
||||
tx2.lock().unwrap().send(msg).unwrap();
|
||||
@@ -1380,7 +1379,7 @@ fn serve_with_options(options: ServeOptions) -> Serve {
|
||||
|
||||
let thread_name = format!("test-server-{:?}", dur);
|
||||
let thread = thread::Builder::new().name(thread_name).spawn(move || {
|
||||
tokio::runtime::run2(::futures::future::lazy(move |_| {
|
||||
tokio::run(::futures::future::lazy(move || {
|
||||
let srv = Http::new()
|
||||
.keep_alive(keep_alive)
|
||||
.pipeline(pipeline)
|
||||
@@ -1391,7 +1390,7 @@ fn serve_with_options(options: ServeOptions) -> Serve {
|
||||
}).unwrap();
|
||||
addr_tx.send(srv.local_addr().unwrap()).unwrap();
|
||||
srv.run_until(shutdown_rx.then(|_| Ok(())))
|
||||
.map_err(|err| panic!("error {}", err))
|
||||
.map_err(|err| println!("error {}", err))
|
||||
}))
|
||||
}).unwrap();
|
||||
|
||||
@@ -1421,26 +1420,31 @@ struct DebugStream<T, D> {
|
||||
_debug: D,
|
||||
}
|
||||
|
||||
impl<T: Read, D> Read for DebugStream<T, D> {
|
||||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||||
self.stream.read(buf)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Write, D> Write for DebugStream<T, D> {
|
||||
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
||||
self.stream.write(buf)
|
||||
}
|
||||
|
||||
fn flush(&mut self) -> io::Result<()> {
|
||||
self.stream.flush()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl<T: AsyncWrite, D> AsyncWrite for DebugStream<T, D> {
|
||||
fn poll_write(&mut self, cx: &mut task::Context, buf: &[u8]) -> futures::Poll<usize, io::Error> {
|
||||
self.stream.poll_write(cx, buf)
|
||||
}
|
||||
|
||||
fn poll_flush(&mut self, cx: &mut task::Context) -> futures::Poll<(), io::Error> {
|
||||
self.stream.poll_flush(cx)
|
||||
}
|
||||
|
||||
fn poll_close(&mut self, cx: &mut task::Context) -> futures::Poll<(), io::Error> {
|
||||
self.stream.poll_close(cx)
|
||||
fn shutdown(&mut self) -> futures::Poll<(), io::Error> {
|
||||
self.stream.shutdown()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl<T: AsyncRead, D> AsyncRead for DebugStream<T, D> {
|
||||
fn poll_read(&mut self, cx: &mut task::Context, buf: &mut [u8]) -> futures::Poll<usize, io::Error> {
|
||||
self.stream.poll_read(cx, buf)
|
||||
}
|
||||
}
|
||||
impl<T: AsyncRead, D> AsyncRead for DebugStream<T, D> {}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Dropped(Arc<AtomicBool>);
|
||||
|
||||
Reference in New Issue
Block a user