Skip to content

Commit

Permalink
Attempt to fix tests
Browse files Browse the repository at this point in the history
An exception was getting thrown during the handshake process that wasn't properly being thrown.
Since poll() only ran during the handshake, I've moved the handling in that case to wait_for_handshake().
  • Loading branch information
Vultraz committed Aug 5, 2019
1 parent 1e9d649 commit 6593751
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/wesnothd_connection.cpp
Expand Up @@ -78,7 +78,17 @@ wesnothd_connection::wesnothd_connection(const std::string& host, const std::str

// Starts the worker thread. Do this *after* the above async_resolve call or it will just exit immediately!
worker_thread_ = std::thread([this]() {
io_service_.run();
try {
io_service_.run();
} catch(const boost::system::system_error& err) {
try {
// Attempt to pass the exception on to the handshake promise.
handshake_finished_.set_exception(std::current_exception());
} catch(const std::future_error&) {
// Handshake already complete. Do nothing.
}
}

LOG_NW << "wesnothd_connection::io_service::run() returned\n";
});

Expand Down Expand Up @@ -165,7 +175,17 @@ void wesnothd_connection::wait_for_handshake()
{
MPTEST_LOG;
LOG_NW << "Waiting for handshake" << std::endl;
handshake_finished_.get_future().wait();

try {
handshake_finished_.get_future().get();
} catch(const boost::system::system_error& err) {
if(err.code() == boost::asio::error::operation_aborted || err.code() == boost::asio::error::eof) {
return;
}

WRN_NW << __func__ << " Rethrowing: " << err.code() << "\n";
throw error(err.code());
}
}

// main thread
Expand Down

0 comments on commit 6593751

Please sign in to comment.