Skip to content

Commit

Permalink
Ref #126: Cleanup/revert unwanted changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielhourt committed May 8, 2019
1 parent 50b20df commit 188f16d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 38 deletions.
3 changes: 3 additions & 0 deletions include/fc/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>, int, fc::optional<int>), 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<typename R, typename... Parameters>
struct optionals_callable : public std::function<R(Parameters...)> {
using std::function<R(Parameters...)>::operator();
Expand Down
5 changes: 3 additions & 2 deletions src/network/http/websocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,6 @@ namespace fc { namespace http {
_server_thread.async( [&](){
auto new_con = std::make_shared<websocket_connection_impl<websocket_server_type::connection_ptr>>( _server.get_con_from_hdl(hdl) );
_on_connection( _connections[hdl] = new_con );
if ( !_closed || _closed->ready() )
_closed = new fc::promise<void>();
}).wait();
});
_server.set_message_handler( [&]( connection_hdl hdl, websocket_server_type::message_ptr msg ){
Expand Down Expand Up @@ -291,6 +289,9 @@ namespace fc { namespace http {
if( _server.is_listening() )
_server.stop_listening();

if ( _connections.size() )
_closed = new fc::promise<void>();

auto cpy_con = _connections;
for( auto item : cpy_con )
_server.close( item.first, 0, "server exit" );
Expand Down
68 changes: 32 additions & 36 deletions tests/api_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<fc::http::websocket_client>();
auto con = client->connect( "ws://localhost:" + std::to_string(listen_port) );
server->stop_listening();
auto apic = std::make_shared<websocket_api_connection>(*con, MAX_DEPTH);
auto remote_login_api = apic->get_remote_api<login_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()
auto client = std::make_shared<fc::http::websocket_client>();
auto con = client->connect( "ws://localhost:" + std::to_string(listen_port) );
server->stop_listening();
auto apic = std::make_shared<websocket_api_connection>(*con, MAX_DEPTH);
auto remote_login_api = apic->get_remote_api<login_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()
}

Expand All @@ -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<fc::http::websocket_client>();
auto con = client->connect( "ws://localhost:" + std::to_string(listen_port) );
server->stop_listening();
auto apic = std::make_shared<websocket_api_connection>(*con, MAX_DEPTH);
auto remote_optionals = apic->get_remote_api<optionals_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\"]");

client->synchronous_close();
server->close();
fc::usleep(fc::milliseconds(50));
client.reset();
server.reset();
} FC_LOG_AND_RETHROW()
auto client = std::make_shared<fc::http::websocket_client>();
auto con = client->connect( "ws://localhost:" + std::to_string(listen_port) );
server->stop_listening();
auto apic = std::make_shared<websocket_api_connection>(*con, MAX_DEPTH);
auto remote_optionals = apic->get_remote_api<optionals_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\"]");

client->synchronous_close();
server->close();
fc::usleep(fc::milliseconds(50));
client.reset();
server.reset();
} FC_LOG_AND_RETHROW()
}

Expand Down

0 comments on commit 188f16d

Please sign in to comment.