mirror of
https://github.com/actix/actix-web.git
synced 2024-11-18 15:41:17 +00:00
restore server start test
This commit is contained in:
parent
29adc20581
commit
3abd0db6b1
2 changed files with 25 additions and 2 deletions
|
@ -81,7 +81,7 @@ impl TestServer {
|
|||
// run server in separate thread
|
||||
let join = thread::spawn(move || {
|
||||
let sys = System::new("actix-test-server");
|
||||
let tcp = net::TcpListener::bind("0.0.0.0:0").unwrap();
|
||||
let tcp = net::TcpListener::bind("127.0.0.1:0").unwrap();
|
||||
let local_addr = tcp.local_addr().unwrap();
|
||||
let tcp = TcpListener::from_listener(tcp, &local_addr, Arbiter::handle()).unwrap();
|
||||
|
||||
|
@ -113,7 +113,7 @@ impl TestServer {
|
|||
let join = thread::spawn(move || {
|
||||
let sys = System::new("actix-test-server");
|
||||
|
||||
let tcp = net::TcpListener::bind("0.0.0.0:0").unwrap();
|
||||
let tcp = net::TcpListener::bind("127.0.0.1:0").unwrap();
|
||||
let local_addr = tcp.local_addr().unwrap();
|
||||
let tcp = TcpListener::from_listener(tcp, &local_addr, Arbiter::handle()).unwrap();
|
||||
|
||||
|
@ -135,6 +135,12 @@ impl TestServer {
|
|||
}
|
||||
}
|
||||
|
||||
/// Get firat available unused address
|
||||
pub fn unused_addr() -> net::SocketAddr {
|
||||
let tcp = net::TcpListener::bind("127.0.0.1:0").unwrap();
|
||||
tcp.local_addr().unwrap()
|
||||
}
|
||||
|
||||
/// Construct test server url
|
||||
pub fn url(&self, uri: &str) -> String {
|
||||
if uri.starts_with('/') {
|
|
@ -3,10 +3,27 @@ extern crate actix_web;
|
|||
extern crate tokio_core;
|
||||
extern crate reqwest;
|
||||
|
||||
use std::thread;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
use actix_web::*;
|
||||
use actix::System;
|
||||
|
||||
#[test]
|
||||
fn test_start() {
|
||||
let addr = test::TestServer::unused_addr();
|
||||
let srv_addr = addr.clone();
|
||||
thread::spawn(move || {
|
||||
let sys = System::new("test");
|
||||
let srv = HttpServer::new(
|
||||
|| vec![Application::new()
|
||||
.resource("/", |r| r.method(Method::GET).h(httpcodes::HTTPOk))]);
|
||||
srv.bind(srv_addr).unwrap().start();
|
||||
sys.run();
|
||||
});
|
||||
assert!(reqwest::get(&format!("http://{}/", addr)).unwrap().status().is_success());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_simple() {
|
||||
|
|
Loading…
Reference in a new issue