fix tests for actix-rt break change

This commit is contained in:
fakeshadow 2020-12-27 13:46:50 +08:00
parent cbda928a33
commit c35c295b2d
4 changed files with 40 additions and 29 deletions

View File

@ -133,6 +133,8 @@ actix-multipart = { path = "actix-multipart" }
actix-files = { path = "actix-files" } actix-files = { path = "actix-files" }
awc = { path = "awc" } awc = { path = "awc" }
actix-rt = { git = "https://github.com/actix/actix-net.git" }
[[bench]] [[bench]]
name = "server" name = "server"
harness = false harness = false

View File

@ -62,14 +62,17 @@ pub async fn test_server_with_addr<F: ServiceFactory<TcpStream>>(
// run server in separate thread // run server in separate thread
thread::spawn(move || { thread::spawn(move || {
let sys = System::new("actix-test-server"); let mut sys = System::new("actix-test-server");
let local_addr = tcp.local_addr().unwrap(); let local_addr = tcp.local_addr().unwrap();
Server::build() sys.block_on(async {
.listen("test", tcp, factory)? Server::build()
.workers(1) .listen("test", tcp, factory)
.disable_signals() .unwrap()
.start(); .workers(1)
.disable_signals()
.start()
});
tx.send((System::current(), local_addr)).unwrap(); tx.send((System::current(), local_addr)).unwrap();
sys.run() sys.run()

View File

@ -698,7 +698,7 @@ where
// run server in separate thread // run server in separate thread
thread::spawn(move || { thread::spawn(move || {
let sys = System::new("actix-test-server"); let mut sys = System::new("actix-test-server");
let tcp = net::TcpListener::bind("127.0.0.1:0").unwrap(); let tcp = net::TcpListener::bind("127.0.0.1:0").unwrap();
let local_addr = tcp.local_addr().unwrap(); let local_addr = tcp.local_addr().unwrap();
let factory = factory.clone(); let factory = factory.clone();
@ -788,10 +788,13 @@ where
}), }),
}, },
} }
.unwrap() .unwrap();
.start();
sys.block_on(async {
let srv = srv.run();
tx.send((System::current(), srv, local_addr)).unwrap();
});
tx.send((System::current(), srv, local_addr)).unwrap();
sys.run() sys.run()
}); });

View File

@ -13,26 +13,29 @@ async fn test_start() {
let (tx, rx) = mpsc::channel(); let (tx, rx) = mpsc::channel();
thread::spawn(move || { thread::spawn(move || {
let sys = actix_rt::System::new("test"); let mut sys = actix_rt::System::new("test");
let srv = HttpServer::new(|| { let srv = sys.block_on(async {
App::new().service( HttpServer::new(|| {
web::resource("/").route(web::to(|| HttpResponse::Ok().body("test"))), App::new().service(
) web::resource("/")
}) .route(web::to(|| HttpResponse::Ok().body("test"))),
.workers(1) )
.backlog(1) })
.max_connections(10) .workers(1)
.max_connection_rate(10) .backlog(1)
.keep_alive(10) .max_connections(10)
.client_timeout(5000) .max_connection_rate(10)
.client_shutdown(0) .keep_alive(10)
.server_hostname("localhost") .client_timeout(5000)
.system_exit() .client_shutdown(0)
.disable_signals() .server_hostname("localhost")
.bind(format!("{}", addr)) .system_exit()
.unwrap() .disable_signals()
.run(); .bind(format!("{}", addr))
.unwrap()
.run()
});
let _ = tx.send((srv, actix_rt::System::current())); let _ = tx.send((srv, actix_rt::System::current()));
let _ = sys.run(); let _ = sys.run();