FC Updates from BitShares and myself #21

Closed
nathanielhourt wants to merge 687 commits from dapp-support into latest-fc
Showing only changes of commit a3f8f2f004 - Show all commits

View file

@ -10,6 +10,7 @@ BOOST_AUTO_TEST_CASE(websocket_test)
{
fc::http::websocket_client client;
fc::http::websocket_connection_ptr s_conn, c_conn;
int port;
{
fc::http::websocket_server server;
server.on_connection([&]( const fc::http::websocket_connection_ptr& c ){
@ -19,11 +20,26 @@ BOOST_AUTO_TEST_CASE(websocket_test)
});
});
server.listen( 8090 );
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 )
{
// if the port is busy, listen() will throw a std::exception, do nothing here.
}
}
BOOST_REQUIRE( listen_ok );
server.start_accept();
std::string echo;
c_conn = client.connect( "ws://localhost:8090" );
c_conn = client.connect( "ws://localhost:" + fc::to_string(port) );
c_conn->on_message_handler([&](const std::string& s){
echo = s;
});
@ -43,7 +59,7 @@ BOOST_AUTO_TEST_CASE(websocket_test)
//std::cerr << e.to_string() << "\n";
}
c_conn = client.connect( "ws://localhost:8090" );
c_conn = client.connect( "ws://localhost:" + fc::to_string(port) );
c_conn->on_message_handler([&](const std::string& s){
echo = s;
});
@ -55,19 +71,21 @@ BOOST_AUTO_TEST_CASE(websocket_test)
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) {
std::cerr << e.to_string() << "\n";
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:8090" );
BOOST_FAIL("expected assertion failure");
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 << e.to_string() << "\n";
} catch (const fc::exception& e) {
BOOST_FAIL("Unexpected exception: " + e.to_string());
std::cerr << "Excepted fc::exception : " << e.to_string() << "\n";
} catch (const std::exception& e) {
BOOST_FAIL("Unexpected exception: " + std::string(e.what()));
BOOST_FAIL("Unexpected exception : " + std::string(e.what()));
}
}