lundi 7 décembre 2015

Tests panic when HTTP server starts after old one is closed

I have some tests written, each function starts iron's HTTP server and closes it after test is done:

extern crate iron;

use iron::prelude::*;

fn hello_world(_: &mut Request) -> IronResult<Response> {
    Ok(Response::with((iron::status::Ok, "Hello World")))
}

#[test]
fn test1() {
    let mut server = Iron::new(hello_world).http("localhost:3000").unwrap();
    server.close().unwrap();
}

#[test]
fn test2() {
    let mut server = Iron::new(hello_world).http("localhost:3000").unwrap();
    server.close().unwrap();
}

Doing cargo test I'm having:

Running target/debug/lib-f236975fe924352b

running 2 tests
test test1 ... ok
test test2 ... FAILED

failures:

---- test2 stdout ----
thread 'test2' panicked at 'called `Result::unwrap()` on an `Err` value: Io(Error { repr: Os { code: 98, message: "Address already in use" } })', ../src/libcore/result.rs:736



failures:
test2

test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured

It seems like the port is still in use by the start of the second test.

Aucun commentaire:

Enregistrer un commentaire