From bf582aa2c1f51d325dce16dc3ce42725b156a9a1 Mon Sep 17 00:00:00 2001 From: Peter Thorson Date: Sat, 8 Jun 2013 18:29:50 -0500 Subject: [PATCH] add unit test for server open handshake timeout --- test/transport/integration.cpp | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/test/transport/integration.cpp b/test/transport/integration.cpp index cc52e51e15..b6bdf5c4fa 100644 --- a/test/transport/integration.cpp +++ b/test/transport/integration.cpp @@ -184,6 +184,17 @@ void check_ec(T * c, websocketpp::lib::error_code ec, //BOOST_CHECK_EQUAL( con->get_remote_close_code(), websocketpp::close::status::normal ); } +template +void check_ec_and_stop(T * c, websocketpp::lib::error_code ec, + websocketpp::connection_hdl hdl) +{ + typename T::connection_ptr con = c->get_con_from_hdl(hdl); + BOOST_CHECK_EQUAL( con->get_ec(), ec ); + //BOOST_CHECK_EQUAL( con->get_local_close_code(), websocketpp::close::status::normal ); + //BOOST_CHECK_EQUAL( con->get_remote_close_code(), websocketpp::close::status::normal ); + c->stop(); +} + template void req_pong_timeout(T * c, std::string expected_payload, websocketpp::connection_hdl hdl, std::string payload) @@ -225,8 +236,7 @@ BOOST_AUTO_TEST_CASE( pong_timeout ) { } } -BOOST_AUTO_TEST_CASE( open_handshake_timeout ) { - server s; +BOOST_AUTO_TEST_CASE( client_open_handshake_timeout ) { client c; // set open handler to fail test @@ -243,3 +253,20 @@ BOOST_AUTO_TEST_CASE( open_handshake_timeout ) { run_client(c, "http://localhost:9005"); } +BOOST_AUTO_TEST_CASE( server_open_handshake_timeout ) { + server s; + + // set open handler to fail test + s.set_open_handler(bind(&fail_on_open,::_1)); + // set fail hander to test for the right fail error code + s.set_fail_handler(bind(&check_ec_and_stop,&s, + websocketpp::error::open_handshake_timeout,::_1)); + + websocketpp::lib::thread sthread(websocketpp::lib::bind(&run_server,&s,9005,false)); + websocketpp::lib::thread tthread(websocketpp::lib::bind(&run_test_timer,6)); + tthread.detach(); + + run_dummy_client("9005"); + + sthread.join(); +}