1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-06-26 19:47:43 +02:00

add ServerConfig to server services

This commit is contained in:
Nikolay Kim
2019-03-09 07:27:56 -08:00
parent ac62e2dbf9
commit d2b96ff877
15 changed files with 163 additions and 45 deletions

View File

@ -1,7 +1,7 @@
use std::{net, thread, time};
use actix_server::Server;
use actix_service::fn_service;
use actix_server::{Server, ServerConfig};
use actix_service::{fn_cfg_factory, fn_service, IntoService};
use net2::TcpBuilder;
fn unused_addr() -> net::SocketAddr {
@ -19,7 +19,27 @@ fn test_bind() {
thread::spawn(move || {
Server::build()
.bind("test", addr, || fn_service(|_| Ok::<_, ()>(())))
.bind("test", addr, move || {
fn_cfg_factory(move |cfg: &ServerConfig| {
assert_eq!(cfg.local_addr(), addr);
Ok::<_, ()>((|_| Ok::<_, ()>(())).into_service())
})
})
.unwrap()
.run()
});
thread::sleep(time::Duration::from_millis(500));
assert!(net::TcpStream::connect(addr).is_ok());
}
#[test]
fn test_bind_no_config() {
let addr = unused_addr();
thread::spawn(move || {
Server::build()
.bind("test", addr, move || fn_service(|_| Ok::<_, ()>(())))
.unwrap()
.run()
});
@ -35,7 +55,12 @@ fn test_listen() {
thread::spawn(move || {
let lst = net::TcpListener::bind(addr).unwrap();
Server::build()
.listen("test", lst, move || fn_service(|_| Ok::<_, ()>(())))
.listen("test", lst, move || {
fn_cfg_factory(move |cfg: &ServerConfig| {
assert_eq!(cfg.local_addr(), addr);
Ok::<_, ()>((|_| Ok::<_, ()>(())).into_service())
})
})
.unwrap()
.run()
});