@@ -954,6 +954,60 @@ mod dispatch_impl {
|
||||
assert_eq!(closes.load(Ordering::Relaxed), 1);
|
||||
}
|
||||
|
||||
#[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 `Core` 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 mut core = Core::new().unwrap();
|
||||
let handle = core.handle();
|
||||
|
||||
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::<hyper::Uri>().unwrap();
|
||||
|
||||
let client = Client::new(&handle);
|
||||
let res = client.get(uri.clone()).and_then(move |res| {
|
||||
assert_eq!(res.status(), hyper::StatusCode::Ok);
|
||||
res.body().concat2()
|
||||
});
|
||||
|
||||
core.run(res).unwrap();
|
||||
|
||||
// drop previous Core
|
||||
core = Core::new().unwrap();
|
||||
let timeout = Timeout::new(Duration::from_millis(200), &core.handle()).unwrap();
|
||||
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 res = client.get(uri);
|
||||
// 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 = core.run(res.join(rx).map(|r| r.0)).unwrap_err();
|
||||
assert_eq!(err.description(), "event loop gone");
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[test]
|
||||
fn client_custom_executor() {
|
||||
let server = TcpListener::bind("127.0.0.1:0").unwrap();
|
||||
|
||||
Reference in New Issue
Block a user