FC Updates from BitShares and myself #21

Closed
nathanielhourt wants to merge 687 commits from dapp-support into latest-fc
2 changed files with 10 additions and 46 deletions
Showing only changes of commit b8a03d3a51 - Show all commits

View file

@ -207,7 +207,7 @@ 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 )
if ( !_closed || _closed->ready() )
_closed = new fc::promise<void>();
}).wait();
});
@ -216,7 +216,6 @@ namespace fc { namespace http {
auto current_con = _connections.find(hdl);
assert( current_con != _connections.end() );
wdump(("server")(msg->get_payload()));
//std::cerr<<"recv: "<<msg->get_payload()<<"\n";
auto payload = msg->get_payload();
std::shared_ptr<websocket_connection> con = current_con->second;
++_pending_messages;

View file

@ -20,21 +20,8 @@ BOOST_AUTO_TEST_CASE(websocket_test)
});
});
bool listen_ok = false;
for( int i = 0; !listen_ok && i < 5; ++i )
{
port = std::rand() % 50000 + 10000;
try
{
server.listen( port );
listen_ok = true;
}
catch( std::exception& ignore )
{
// if the port is busy, listen() will throw a std::exception, do nothing here.
}
}
BOOST_REQUIRE( listen_ok );
server.listen( 0 );
port = server.get_listening_port();
server.start_accept();
@ -44,49 +31,27 @@ BOOST_AUTO_TEST_CASE(websocket_test)
echo = s;
});
c_conn->send_message( "hello world" );
fc::usleep( fc::seconds(1) );
fc::usleep( fc::milliseconds(100) );
BOOST_CHECK_EQUAL("echo: hello world", echo);
c_conn->send_message( "again" );
fc::usleep( fc::seconds(1) );
fc::usleep( fc::milliseconds(100) );
BOOST_CHECK_EQUAL("echo: again", echo);
s_conn->close(0, "test");
fc::usleep( fc::seconds(1) );
try {
c_conn->send_message( "again" );
BOOST_FAIL("expected assertion failure");
} catch (const fc::exception& e) {
//std::cerr << e.to_string() << "\n";
}
fc::usleep( fc::milliseconds(100) );
BOOST_CHECK_THROW(c_conn->send_message( "again" ), fc::exception);
c_conn = client.connect( "ws://localhost:" + fc::to_string(port) );
c_conn->on_message_handler([&](const std::string& s){
echo = s;
});
c_conn->send_message( "hello world" );
fc::usleep( fc::seconds(1) );
fc::usleep( fc::milliseconds(100) );
BOOST_CHECK_EQUAL("echo: hello world", echo);
}
try {
c_conn->send_message( "again" );
BOOST_FAIL("expected assertion failure");
} catch (const fc::assert_exception& e) {
std::cerr << "Expected assertion failure : " << e.to_string() << "\n";
} catch (const fc::exception& e) {
BOOST_FAIL("Unexpected exception : " + e.to_string());
} catch (const std::exception& e) {
BOOST_FAIL("Unexpected exception : " + std::string(e.what()));
}
try {
c_conn = client.connect( "ws://localhost:" + fc::to_string(port) );
BOOST_FAIL("expected fc::exception (fail to connect)");
} catch (const fc::exception& e) {
std::cerr << "Excepted fc::exception : " << e.to_string() << "\n";
} catch (const std::exception& e) {
BOOST_FAIL("Unexpected exception : " + std::string(e.what()));
}
BOOST_CHECK_THROW(c_conn->send_message( "again" ), fc::assert_exception);
BOOST_CHECK_THROW(client.connect( "ws://localhost:" + fc::to_string(port) ), fc::exception);
}
BOOST_AUTO_TEST_SUITE_END()