From c316a99746b4c535228f736e5a434fa64a790e0c Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Tue, 27 Feb 2018 20:04:01 -0800 Subject: [PATCH] stop server test --- tests/test_server.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/test_server.rs b/tests/test_server.rs index ad2028a2..a7ca7318 100644 --- a/tests/test_server.rs +++ b/tests/test_server.rs @@ -93,6 +93,37 @@ fn test_start() { } } +#[test] +fn test_shutdown() { + let _ = test::TestServer::unused_addr(); + let (tx, rx) = mpsc::channel(); + + thread::spawn(move || { + let sys = System::new("test"); + let srv = HttpServer::new( + || vec![Application::new() + .resource("/", |r| r.method(Method::GET).h(httpcodes::HTTPOk))]); + + let srv = srv.bind("127.0.0.1:0").unwrap(); + let addr = srv.addrs()[0]; + let srv_addr = srv.shutdown_timeout(1).start(); + let _ = tx.send((addr, srv_addr)); + sys.run(); + }); + let (addr, srv_addr) = rx.recv().unwrap(); + + let mut sys = System::new("test-server"); + + { + let req = client::ClientRequest::get(format!("http://{}/", addr).as_str()).finish().unwrap(); + let response = sys.run_until_complete(req.send()).unwrap(); + srv_addr.do_send(server::StopServer{graceful: true}); + assert!(response.status().is_success()); + } + + assert!(net::TcpStream::connect(addr).is_err()); +} + #[test] fn test_simple() { let mut srv = test::TestServer::new(|app| app.handler(httpcodes::HTTPOk));