From afb96a0e7ebc9bd6569af97888d6e8ef59f418f5 Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Wed, 8 May 2019 12:09:44 -0500 Subject: [PATCH] Ref #126: Cleanup/revert unwanted changes --- include/fc/api.hpp | 3 ++ src/network/http/websocket.cpp | 5 +-- tests/api_tests.cpp | 62 ++++++++++++++++------------------ 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/include/fc/api.hpp b/include/fc/api.hpp index d75a159..5e582ad 100644 --- a/include/fc/api.hpp +++ b/include/fc/api.hpp @@ -28,6 +28,9 @@ namespace fc { /// whereas normally the last two arguments must be provided, this template allows them to be omitted. /// Note that this only applies to trailing optional arguments, i.e. given a callable taking /// (fc::optional, int, fc::optional), only the last argument can be omitted. + /// + /// A discussion of how exactly this works is available here: + /// https://github.com/bitshares/bitshares-fc/pull/126#issuecomment-490566060 template struct optionals_callable : public std::function { using std::function::operator(); diff --git a/src/network/http/websocket.cpp b/src/network/http/websocket.cpp index dbff4bc..6d479bf 100644 --- a/src/network/http/websocket.cpp +++ b/src/network/http/websocket.cpp @@ -207,8 +207,6 @@ namespace fc { namespace http { _server_thread.async( [&](){ auto new_con = std::make_shared>( _server.get_con_from_hdl(hdl) ); _on_connection( _connections[hdl] = new_con ); - if ( !_closed || _closed->ready() ) - _closed = new fc::promise(); }).wait(); }); _server.set_message_handler( [&]( connection_hdl hdl, websocket_server_type::message_ptr msg ){ @@ -291,6 +289,9 @@ namespace fc { namespace http { if( _server.is_listening() ) _server.stop_listening(); + if ( _connections.size() ) + _closed = new fc::promise(); + auto cpy_con = _connections; for( auto item : cpy_con ) _server.close( item.first, 0, "server exit" ); diff --git a/tests/api_tests.cpp b/tests/api_tests.cpp index 9f9b3a4..5c1147c 100644 --- a/tests/api_tests.cpp +++ b/tests/api_tests.cpp @@ -77,24 +77,22 @@ BOOST_AUTO_TEST_CASE(login_test) { auto listen_port = server->get_listening_port(); server->start_accept(); - try { - auto client = std::make_shared(); - auto con = client->connect( "ws://localhost:" + std::to_string(listen_port) ); - server->stop_listening(); - auto apic = std::make_shared(con, MAX_DEPTH); - auto remote_login_api = apic->get_remote_api(); - auto remote_calc = remote_login_api->get_calc(); - bool remote_triggered = false; - remote_calc->on_result( [&remote_triggered]( uint32_t r ) { remote_triggered = true; } ); - BOOST_CHECK_EQUAL(remote_calc->add( 4, 5 ), 9); - BOOST_CHECK(remote_triggered); + auto client = std::make_shared(); + auto con = client->connect( "ws://localhost:" + std::to_string(listen_port) ); + server->stop_listening(); + auto apic = std::make_shared(con, MAX_DEPTH); + auto remote_login_api = apic->get_remote_api(); + auto remote_calc = remote_login_api->get_calc(); + bool remote_triggered = false; + remote_calc->on_result( [&remote_triggered]( uint32_t r ) { remote_triggered = true; } ); + BOOST_CHECK_EQUAL(remote_calc->add( 4, 5 ), 9); + BOOST_CHECK(remote_triggered); - client->synchronous_close(); - server->close(); - fc::usleep(fc::milliseconds(50)); - client.reset(); - server.reset(); - } FC_LOG_AND_RETHROW() + client->synchronous_close(); + server->close(); + fc::usleep(fc::milliseconds(50)); + client.reset(); + server.reset(); } FC_LOG_AND_RETHROW() } @@ -118,24 +116,22 @@ BOOST_AUTO_TEST_CASE(optionals_test) { auto listen_port = server->get_listening_port(); server->start_accept(); - try { - auto client = std::make_shared(); - auto con = client->connect( "ws://localhost:" + std::to_string(listen_port) ); - server->stop_listening(); - auto apic = std::make_shared(*con, MAX_DEPTH); - auto remote_optionals = apic->get_remote_api(); + auto client = std::make_shared(); + auto con = client->connect( "ws://localhost:" + std::to_string(listen_port) ); + server->stop_listening(); + auto apic = std::make_shared(*con, MAX_DEPTH); + auto remote_optionals = apic->get_remote_api(); - BOOST_CHECK_EQUAL(remote_optionals->foo("a"), "[\"a\",null,null]"); - BOOST_CHECK_EQUAL(remote_optionals->foo("a", "b"), "[\"a\",\"b\",null]"); - BOOST_CHECK_EQUAL(remote_optionals->foo("a", "b", "c"), "[\"a\",\"b\",\"c\"]"); - BOOST_CHECK_EQUAL(remote_optionals->foo("a", {}, "c"), "[\"a\",null,\"c\"]"); + BOOST_CHECK_EQUAL(remote_optionals->foo("a"), "[\"a\",null,null]"); + BOOST_CHECK_EQUAL(remote_optionals->foo("a", "b"), "[\"a\",\"b\",null]"); + BOOST_CHECK_EQUAL(remote_optionals->foo("a", "b", "c"), "[\"a\",\"b\",\"c\"]"); + BOOST_CHECK_EQUAL(remote_optionals->foo("a", {}, "c"), "[\"a\",null,\"c\"]"); - client->synchronous_close(); - server->close(); - fc::usleep(fc::milliseconds(50)); - client.reset(); - server.reset(); - } FC_LOG_AND_RETHROW() + client->synchronous_close(); + server->close(); + fc::usleep(fc::milliseconds(50)); + client.reset(); + server.reset(); } FC_LOG_AND_RETHROW() }