change test to expose race condition on worker shutdown

This commit is contained in:
fakeshadow 2021-04-30 11:27:46 +08:00
parent e4d4ae21ee
commit 7fa2a99074
1 changed files with 26 additions and 24 deletions

View File

@ -23,25 +23,25 @@ fn test_bind() {
let (tx, rx) = mpsc::channel(); let (tx, rx) = mpsc::channel();
let h = thread::spawn(move || { let h = thread::spawn(move || {
let sys = actix_rt::System::new(); actix_rt::System::new().block_on(async {
let srv = sys.block_on(lazy(|_| { let srv = Server::build()
Server::build()
.workers(1) .workers(1)
.disable_signals() .disable_signals()
.bind("test", addr, move || fn_service(|_| ok::<_, ()>(()))) .bind("test", addr, move || fn_service(|_| ok::<_, ()>(())))
.unwrap() .unwrap()
.run() .run();
}));
let _ = tx.send((srv, actix_rt::System::current())); let _ = tx.send(srv.clone());
let _ = sys.run(); srv.await
})
}); });
let (_, sys) = rx.recv().unwrap();
thread::sleep(Duration::from_millis(500)); let srv = rx.recv().unwrap();
assert!(net::TcpStream::connect(addr).is_ok());
sys.stop(); net::TcpStream::connect(addr).unwrap();
let _ = h.join();
let _ = srv.stop(true);
h.join().unwrap().unwrap();
} }
#[test] #[test]
@ -50,25 +50,27 @@ fn test_listen() {
let (tx, rx) = mpsc::channel(); let (tx, rx) = mpsc::channel();
let h = thread::spawn(move || { let h = thread::spawn(move || {
let sys = actix_rt::System::new();
let lst = net::TcpListener::bind(addr).unwrap(); let lst = net::TcpListener::bind(addr).unwrap();
sys.block_on(async {
Server::build() actix_rt::System::new().block_on(async {
let srv = Server::build()
.disable_signals() .disable_signals()
.workers(1) .workers(1)
.listen("test", lst, move || fn_service(|_| ok::<_, ()>(()))) .listen("test", lst, move || fn_service(|_| ok::<_, ()>(())))
.unwrap() .unwrap()
.run(); .run();
let _ = tx.send(actix_rt::System::current());
});
let _ = sys.run();
});
let sys = rx.recv().unwrap();
thread::sleep(Duration::from_millis(500)); let _ = tx.send(srv.clone());
assert!(net::TcpStream::connect(addr).is_ok()); srv.await
sys.stop(); })
let _ = h.join(); });
let srv = rx.recv().unwrap();
net::TcpStream::connect(addr).unwrap();
let _ = srv.stop(true);
h.join().unwrap().unwrap();
} }
#[test] #[test]