Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
The initial error was during compile time because of passing None for
the request `data` parameter. The docs were updated to reflect that
`None` must be parameterized like `None::<u8>`.

Having resolved that, there was a runtime error for the tests where one
of them would fail because the specified port was already used.
Presumably the tests run in parallel. The StackListener type was updated
to take a `port: u16` argument which it will attempt to listen on. This
isn't an ideal solution, and another issue will be filed to address it.

Resolves #1.
  • Loading branch information
jwilm committed Nov 12, 2015
1 parent a6cf29d commit 9adbc57
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ impl ::std::fmt::Display for Error {
/// `rustc_serialize::Encodable`, and the result type must implement `rustc_serialize::Decodable`.
/// This can usually be achieved with `#[derive(RustcEncodable)]` and `#[derive(RustcDecodable)]`.
///
/// **Note:** If not providing data, you must provide a parameterized `None` such as `None::<u8>`.
///
/// # Example
///
/// ```no_run
Expand Down
34 changes: 18 additions & 16 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,23 @@ struct ResponseData {
pong: bool
}

const HOST: &'static str = "0.0.0.0:12345";
fn url(frag: &str) -> String {
format!("http://{}{}", HOST, frag)
}

struct StackListener {
server: ::hyper::server::Listening
server: ::hyper::server::Listening,
host: String,
}

impl StackListener {
pub fn new() -> StackListener {
pub fn new(port: u16) -> StackListener {
let host = format!("0.0.0.0:{}", port);
StackListener {
server: PingServer::build().listen_with(HOST, 1, Protocol::Http).unwrap()
server: PingServer::build().listen_with(&host[..], 1, Protocol::Http).unwrap(),
host: host
}
}

pub fn url(&self, path: &str) -> String {
format!("http://{}{}", self.host, path)
}
}

impl Drop for StackListener {
Expand All @@ -63,22 +65,22 @@ impl Drop for StackListener {

#[test]
#[allow(unused_variables)]
fn ping_pong() {
let server = StackListener::new();
fn with_data() {
let server = StackListener::new(40918);

let req = RequestData { ping: true };

// When this fails, the error I get it "called Option::unwrap() on a None value" which is not
// helpful for resolving what the problem is.
let res: ResponseData = request(Method::Post, &(url("/ping"))[..], Some(req)).unwrap().unwrap();
let url = server.url("/ping");
let res: ResponseData = request(Method::Post, &url[..], Some(req)).unwrap().unwrap();
}

#[test]
#[allow(unused_variables)]
fn ping_pong_none_data() {
let server = StackListener::new();
fn none_data() {
let server = StackListener::new(40919);

// When this fails, the error I get it "called Option::unwrap() on a None value" which is not
// helpful for resolving what the problem is.
let res: ResponseData = request(Method::Post, &(url("/ping"))[..], None).unwrap().unwrap();
let url = server.url("/ping");
let res: ResponseData = request(Method::Post, &url[..], None::<u8>).unwrap().unwrap();
}

0 comments on commit 9adbc57

Please sign in to comment.