Skip to content

Commit

Permalink
fix(std.http): Don't return NotReady if the http stream is broken
Browse files Browse the repository at this point in the history
  • Loading branch information
Marwes committed Jan 27, 2019
1 parent 82838a9 commit a93ed23
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
45 changes: 23 additions & 22 deletions examples/http/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extern crate tokio;

use std::{env, fs::File, io::Read};

use futures::{future, Future};
use futures::{future, prelude::*};

use gluon::{
new_vm,
Expand Down Expand Up @@ -74,39 +74,40 @@ mod tests {
use std::str;

use self::hyper::Client;
use futures::Stream;
use tokio::runtime::Runtime;

fn wait_for_server(port: u16) -> impl Future<Item = (), Error = failure::Error> {
let future =
move || Client::new().get(format!("http://localhost:{}", port).parse().unwrap());

let retry_strategy = tokio_retry::strategy::FixedInterval::from_millis(400).take(40);

tokio_retry::Retry::spawn(retry_strategy, future)
.from_err::<failure::Error>()
.and_then(|response| {
response
.into_body()
.concat2()
.map(|body| {
assert_eq!(str::from_utf8(&body).unwrap(), "Hello World");
})
.from_err::<failure::Error>()
})
}

#[test]
fn hello_world() {
let mut runtime = Runtime::new().unwrap();

let port = 12235;
let port = 12234;
let thread = new_vm();

let start_server = future::lazy(move || start(&thread, port));

let future =
move || Client::new().get(format!("http://localhost:{}", port).parse().unwrap());

let retry_strategy = tokio_retry::strategy::FixedInterval::from_millis(400).take(40);

runtime
.block_on(
start_server
.select(
tokio_retry::Retry::spawn(retry_strategy, future)
.from_err::<failure::Error>()
.and_then(|response| {
response
.into_body()
.concat2()
.map(|body| {
assert_eq!(str::from_utf8(&body).unwrap(), "Hello World");
})
.from_err::<failure::Error>()
}),
)
.select(wait_for_server(port))
.map_err(|(err, _)| err),
)
.unwrap_or_else(|err| panic!("{}", err));
Expand All @@ -116,7 +117,7 @@ mod tests {
fn echo() {
let mut runtime = Runtime::new().unwrap();

let port = 12234;
let port = 12235;
let thread = new_vm();
let start_server = future::lazy(move || start(&thread, port));

Expand Down
9 changes: 4 additions & 5 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,16 @@ fn write_response(
return Ok(Async::NotReady);
}
Ok(Async::Ready(_)) => (),
Err(_) => {
info!("Could not send http response");
return Ok(Async::Ready(IO::Value(())));
Err(err) => {
info!("Could not send http response {}", err);
return Ok(IO::Exception(err.to_string()).into());
}
}
match sender.send_data(chunk) {
Ok(()) => Ok(Async::Ready(IO::Value(()))),
Err(chunk) => {
info!("Could not send http response");
unsent_chunk = Some(chunk);
Ok(Async::NotReady)
Ok(IO::Exception("Could not send http response".into()).into())
}
}
})
Expand Down

0 comments on commit a93ed23

Please sign in to comment.