1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-08-02 10:45:05 +00:00
actix-web/tests/test_server.rs

50 lines
1.2 KiB
Rust
Raw Normal View History

extern crate actix;
extern crate actix_web;
extern crate tokio_core;
2017-10-22 19:48:43 +00:00
extern crate reqwest;
2017-10-22 19:48:43 +00:00
use std::{net, thread};
use std::str::FromStr;
use actix::*;
use actix_web::*;
2017-10-22 19:48:43 +00:00
use tokio_core::net::TcpListener;
2017-10-22 01:54:24 +00:00
fn create_server<T, A>() -> HttpServer<T, A, Application<()>> {
HttpServer::new(
2017-10-22 01:54:24 +00:00
vec![Application::default("/")
.resource("/", |r|
r.handler(Method::GET, |_, _, _| {
httpcodes::HTTPOk
}))
.finish()])
}
#[test]
fn test_serve() {
2017-10-22 19:48:43 +00:00
thread::spawn(|| {
let sys = System::new("test");
let srv = create_server();
srv.serve::<_, ()>("127.0.0.1:58902").unwrap();
sys.run();
});
assert!(reqwest::get("http://localhost:58906/").unwrap().status().is_success());
}
#[test]
fn test_serve_incoming() {
2017-10-22 19:48:43 +00:00
thread::spawn(|| {
let sys = System::new("test");
2017-10-22 19:48:43 +00:00
let srv = create_server();
let addr = net::SocketAddr::from_str("127.0.0.1:58906").unwrap();
let tcp = TcpListener::bind(&addr, Arbiter::handle()).unwrap();
srv.serve_incoming::<_, ()>(tcp.incoming()).unwrap();
sys.run();
2017-10-22 19:48:43 +00:00
});
2017-10-22 19:48:43 +00:00
assert!(reqwest::get("http://localhost:58906/").unwrap().status().is_success());
}