From 7be37565ca585b4d8b0d7ff79e259e54486514c4 Mon Sep 17 00:00:00 2001 From: Alex Korotkin Date: Tue, 16 May 2017 18:13:11 +0300 Subject: [PATCH] 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. --- test/transport/integration.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/test/transport/integration.cpp b/test/transport/integration.cpp index f886fbf..ddbb982 100644 --- a/test/transport/integration.cpp +++ b/test/transport/integration.cpp @@ -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(); }