Fix refused client connection due to servers not yet started

The server thread in a unit test may not have enough time to start and the
ongoing client connection will be refused. Fix this by adding sleep.
This commit is contained in:
Alex Korotkin
2017-05-16 18:13:11 +03:00
parent 37ce8abc77
commit 7be37565ca
+16 -2
View File
@@ -375,6 +375,8 @@ BOOST_AUTO_TEST_CASE( pong_no_timeout ) {
websocketpp::lib::thread sthread(websocketpp::lib::bind(&run_server,&s,9005,false));
sleep(1); // give the server thread some time to start
// Run a client that closes the connection after 1 seconds
run_time_limited_client(c, "http://localhost:9005", 1, false);
@@ -401,6 +403,8 @@ BOOST_AUTO_TEST_CASE( pong_timeout ) {
websocketpp::lib::thread tthread(websocketpp::lib::bind(&run_test_timer,10));
tthread.detach();
sleep(1); // give the server thread some time to start
run_client(c, "http://localhost:9005",false);
sthread.join();
@@ -420,6 +424,8 @@ BOOST_AUTO_TEST_CASE( client_open_handshake_timeout ) {
sthread.detach();
tthread.detach();
sleep(1); // give the server thread some time to start
run_client(c, "http://localhost:9005");
}
@@ -436,6 +442,8 @@ BOOST_AUTO_TEST_CASE( server_open_handshake_timeout ) {
websocketpp::lib::thread tthread(websocketpp::lib::bind(&run_test_timer,10));
tthread.detach();
sleep(1); // give the server thread some time to start
run_dummy_client("9005");
sthread.join();
@@ -459,6 +467,8 @@ BOOST_AUTO_TEST_CASE( client_self_initiated_close_handshake_timeout ) {
websocketpp::lib::thread tthread(websocketpp::lib::bind(&run_test_timer,10));
tthread.detach();
sleep(1); // give the server thread some time to start
run_client(c, "http://localhost:9005", false);
sthread.join();
@@ -491,7 +501,9 @@ BOOST_AUTO_TEST_CASE( server_self_initiated_close_handshake_timeout ) {
websocketpp::lib::thread tthread(websocketpp::lib::bind(&run_test_timer,10));
tthread.detach();
run_client(c, "http://localhost:9005",false);
sleep(1); // give the server thread some time to start
run_client(c, "http://localhost:9005", false);
sthread.join();
}
@@ -569,7 +581,9 @@ BOOST_AUTO_TEST_CASE( stop_listening ) {
websocketpp::lib::thread tthread(websocketpp::lib::bind(&run_test_timer,5));
tthread.detach();
run_client(c, "http://localhost:9005",false);
sleep(1); // give the server thread some time to start
run_client(c, "http://localhost:9005", false);
sthread.join();
}