From: Marcin Siodelski Date: Thu, 13 Apr 2017 07:12:44 +0000 (+0200) Subject: [5217] Ignore EINPROGRESS errors in the unitests using async_connect. X-Git-Tag: trac5243x_base~11^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=657cdc1bfe102badf71e45f5632c9aa515702dea;p=thirdparty%2Fkea.git [5217] Ignore EINPROGRESS errors in the unitests using async_connect. --- diff --git a/src/lib/asiolink/tests/tcp_acceptor_unittest.cc b/src/lib/asiolink/tests/tcp_acceptor_unittest.cc index 8edb1b8c65..fbfe5e6dc3 100644 --- a/src/lib/asiolink/tests/tcp_acceptor_unittest.cc +++ b/src/lib/asiolink/tests/tcp_acceptor_unittest.cc @@ -93,9 +93,18 @@ public: /// @param ec Error code. void connectHandler(const boost::system::error_code& ec) { if (ec) { - ADD_FAILURE() << "error occurred while connecting: " - << ec.message(); - io_service_.stop(); + // One would expect that async_connect wouldn't return EINPROGRESS + // error code, but simply wait for the connection to get + // established before the handler is invoked. It turns out, however, + // that on some OSes the connect handler may receive this error code + // which doesn't neccessarily indicate a problem. Making an attempt + // to write and read from this socket will typically succeed. So, + // we ignore this error. + if (ec.value() != boost::asio::error::in_progress) { + ADD_FAILURE() << "error occurred while connecting: " + << ec.message(); + io_service_.stop(); + } } } diff --git a/src/lib/asiolink/tests/tcp_socket_unittest.cc b/src/lib/asiolink/tests/tcp_socket_unittest.cc index 3ccf82042c..1e0784d489 100644 --- a/src/lib/asiolink/tests/tcp_socket_unittest.cc +++ b/src/lib/asiolink/tests/tcp_socket_unittest.cc @@ -22,14 +22,15 @@ #include #include -#include +#include #include +#include +#include +#include #include #include #include -#include -#include -#include +#include #include using namespace boost::asio; @@ -355,7 +356,15 @@ TEST(TCPSocket, sequenceTest) { EXPECT_EQ(0, server_cb.getCode()); EXPECT_EQ(TCPCallback::OPEN, client_cb.called()); - EXPECT_EQ(0, client_cb.getCode()); + + // On some operating system the async_connect may return EINPROGRESS. + // This doesn't neccessarily indicate an error. In most cases trying + // to asynchrouonsly write and read from the socket would work just + // fine. + if ((client_cb.getCode()) != 0 && (client_cb.getCode() != EINPROGRESS)) { + ADD_FAILURE() << "expected error code of 0 or " << EINPROGRESS + << " as a result of async_connect, got " << client_cb.getCode(); + } // Step 2. Get the client to write to the server asynchronously. The // server will loop reading the data synchronously. diff --git a/src/lib/http/tests/listener_unittests.cc b/src/lib/http/tests/listener_unittests.cc index c9250f44e3..2149a83595 100644 --- a/src/lib/http/tests/listener_unittests.cc +++ b/src/lib/http/tests/listener_unittests.cc @@ -133,11 +133,21 @@ public: tcp::endpoint endpoint(address::from_string(SERVER_ADDRESS), SERVER_PORT); socket_.async_connect(endpoint, - [this, request](const boost::system::error_code& ec) { + [this, request](const boost::system::error_code& ec) { if (ec) { - ADD_FAILURE() << "error occurred while connecting: " - << ec.message(); - io_service_.stop(); + // One would expect that async_connect wouldn't return + // EINPROGRESS error code, but simply wait for the connection + // to get established before the handler is invoked. It turns out, + // however, that on some OSes the connect handler may receive this + // error code which doesn't neccessarily indicate a problem. + // Making an attempt to write and read from this socket will + // typically succeed. So, we ignore this error. + if (ec.value() != boost::asio::error::in_progress) { + ADD_FAILURE() << "error occurred while connecting: " + << ec.message(); + io_service_.stop(); + return; + } } sendRequest(request); });