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

Fix server arbiter support (#417)

This commit is contained in:
Rob Ede
2021-11-14 19:45:15 +00:00
committed by GitHub
parent ed987eef06
commit 38caa8f088
9 changed files with 266 additions and 173 deletions

View File

@ -33,28 +33,63 @@ fn test_bind() {
})?
.run();
let _ = tx.send((srv.handle(), actix_rt::System::current()));
let _ = tx.send(srv.handle());
srv.await
})
});
let (srv, sys) = rx.recv().unwrap();
let srv = rx.recv().unwrap();
thread::sleep(Duration::from_millis(500));
assert!(net::TcpStream::connect(addr).is_ok());
let _ = srv.stop(true);
h.join().unwrap().unwrap();
}
#[test]
fn plain_tokio_runtime() {
let addr = unused_addr();
let (tx, rx) = mpsc::channel();
let h = thread::spawn(move || {
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap();
rt.block_on(async {
let srv = Server::build()
.workers(1)
.disable_signals()
.bind("test", addr, move || {
fn_service(|_| async { Ok::<_, ()>(()) })
})?
.run();
tx.send(srv.handle()).unwrap();
srv.await
})
});
let srv = rx.recv().unwrap();
thread::sleep(Duration::from_millis(500));
assert!(net::TcpStream::connect(addr).is_ok());
let _ = srv.stop(true);
sys.stop();
h.join().unwrap().unwrap();
}
#[test]
fn test_listen() {
let addr = unused_addr();
let lst = net::TcpListener::bind(addr).unwrap();
let (tx, rx) = mpsc::channel();
let h = thread::spawn(move || {
let lst = net::TcpListener::bind(addr)?;
actix_rt::System::new().block_on(async {
let srv = Server::build()
.disable_signals()
@ -64,19 +99,18 @@ fn test_listen() {
})?
.run();
let _ = tx.send((srv.handle(), actix_rt::System::current()));
let _ = tx.send(srv.handle());
srv.await
})
});
let (srv, sys) = rx.recv().unwrap();
let srv = rx.recv().unwrap();
thread::sleep(Duration::from_millis(500));
assert!(net::TcpStream::connect(addr).is_ok());
let _ = srv.stop(true);
sys.stop();
h.join().unwrap().unwrap();
}
@ -283,12 +317,12 @@ async fn test_service_restart() {
.workers(1)
.run();
let _ = tx.send((srv.handle(), actix_rt::System::current()));
let _ = tx.send(srv.handle());
srv.await
})
});
let (srv, sys) = rx.recv().unwrap();
let srv = rx.recv().unwrap();
for _ in 0..5 {
TcpStream::connect(addr1)
@ -311,7 +345,6 @@ async fn test_service_restart() {
assert!(num2_clone.load(Ordering::SeqCst) > 5);
let _ = srv.stop(false);
sys.stop();
h.join().unwrap().unwrap();
}
@ -388,13 +421,13 @@ async fn worker_restart() {
.workers(2)
.run();
let _ = tx.send((srv.handle(), actix_rt::System::current()));
let _ = tx.send(srv.handle());
srv.await
})
});
let (srv, sys) = rx.recv().unwrap();
let srv = rx.recv().unwrap();
sleep(Duration::from_secs(3)).await;
@ -452,6 +485,5 @@ async fn worker_restart() {
stream.shutdown().await.unwrap();
let _ = srv.stop(false);
sys.stop();
h.join().unwrap().unwrap();
}