From: Marcin Siodelski Date: Mon, 29 May 2017 11:30:12 +0000 (+0200) Subject: [5189] Miscellanous corrections. X-Git-Tag: trac5243_base~4^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=193cd31c8295d35876efb1fbba3640a3c19fa279;p=thirdparty%2Fkea.git [5189] Miscellanous corrections. --- diff --git a/src/bin/agent/ca_command_mgr.cc b/src/bin/agent/ca_command_mgr.cc index 1e19fe4140..21555448b2 100644 --- a/src/bin/agent/ca_command_mgr.cc +++ b/src/bin/agent/ca_command_mgr.cc @@ -30,6 +30,7 @@ using namespace isc::process; namespace { /// @brief Client side connection timeout. +/// @todo Make it configurable. const long CONNECTION_TIMEOUT = 5000; } @@ -206,7 +207,8 @@ CtrlAgentCommandMgr::forwardCommand(const std::string& service, // Capture error code and parsed data. received_ec = ec; received_feed = feed; - // Stop the IO service so as we can continue. + // Got the IO service so stop IO service. This causes to + // stop IO service when all handlers have been invoked. io_service->stopWork(); }, ClientConnection::Timeout(CONNECTION_TIMEOUT)); io_service->run(); diff --git a/src/bin/agent/ca_command_mgr.h b/src/bin/agent/ca_command_mgr.h index cad7614a82..819fa3399c 100644 --- a/src/bin/agent/ca_command_mgr.h +++ b/src/bin/agent/ca_command_mgr.h @@ -11,7 +11,6 @@ #include #include #include -#include namespace isc { namespace agent { diff --git a/src/bin/agent/tests/ca_command_mgr_unittests.cc b/src/bin/agent/tests/ca_command_mgr_unittests.cc index ff163ee358..5b2b98c29f 100644 --- a/src/bin/agent/tests/ca_command_mgr_unittests.cc +++ b/src/bin/agent/tests/ca_command_mgr_unittests.cc @@ -229,9 +229,9 @@ public: bindServerSocket(server_response, true); // The client side communication is synchronous. To be able to respond - // to this we need to run the server side socket at the same time. - // Running IO service in a thread guarantees that the server responds - // as soon as it receives the control command. + // to this we need to run the server side socket at the same time as the + // client. Running IO service in a thread guarantees that the server + //responds as soon as it receives the control command. isc::util::thread::Thread th(boost::bind(&IOService::run, getIOService().get())); @@ -243,13 +243,15 @@ public: ConstElementPtr answer = mgr_.handleCommand("foo", ConstElementPtr(), command); + // Cancel all asynchronous operations and let the handlers to be invoked + // with operation_aborted error code. server_socket_->stopServer(); getIOService()->stopWork(); + // Wait for the thread to finish. th.wait(); EXPECT_EQ(expected_responses, server_socket_->getResponseNum()); - checkAnswer(answer, expected_result0, expected_result1, expected_result2); } @@ -367,9 +369,12 @@ TEST_F(CtrlAgentCommandMgrTest, forwardListCommands) { ConstElementPtr answer = mgr_.handleCommand("list-commands", ConstElementPtr(), command); + // Cancel all asynchronous operations and let the handlers to be invoked + // with operation_aborted error code. server_socket_->stopServer(); getIOService()->stopWork(); + // Wait for the thread to finish. th.wait(); // Answer of 3 is specific to the stub response we send when the diff --git a/src/lib/asiolink/tests/unix_domain_socket_unittest.cc b/src/lib/asiolink/tests/unix_domain_socket_unittest.cc index bc298d04b5..353f9e9830 100644 --- a/src/lib/asiolink/tests/unix_domain_socket_unittest.cc +++ b/src/lib/asiolink/tests/unix_domain_socket_unittest.cc @@ -132,7 +132,7 @@ TEST_F(UnixDomainSocketTest, asyncSendReceive) { connect_handler_invoked = true; // Operation aborted indicates that IO service has been stopped. This // shouldn't happen here. - if (ec && ec.value() != boost::asio::error::operation_aborted) { + if (ec && (ec.value() != boost::asio::error::operation_aborted)) { ADD_FAILURE() << "error occurred while asynchronously connecting" " via unix domain socket: " << ec.message(); } diff --git a/src/lib/asiolink/testutils/test_server_unix_socket.cc b/src/lib/asiolink/testutils/test_server_unix_socket.cc index 3dcb869ff0..d995c7a26d 100644 --- a/src/lib/asiolink/testutils/test_server_unix_socket.cc +++ b/src/lib/asiolink/testutils/test_server_unix_socket.cc @@ -257,6 +257,9 @@ TestServerUnixSocket::bindServerSocket(const bool use_thread) { server_acceptor_.listen(); accept(); + // When threads are in use, we need to post a handler which will be invoked + // when the thread has already started and the IO service is running. The + // main thread can move forward when it receives this signal from the handler. if (use_thread) { io_service_.post(boost::bind(&TestServerUnixSocket::signalRunning, this)); diff --git a/src/lib/asiolink/unix_domain_socket.cc b/src/lib/asiolink/unix_domain_socket.cc index c6436a8a66..04f51c0d10 100644 --- a/src/lib/asiolink/unix_domain_socket.cc +++ b/src/lib/asiolink/unix_domain_socket.cc @@ -105,7 +105,7 @@ public: /// @brief Asynchronously receive data over the socket. /// /// This method schedules asynchronous receive and installs the - /// @ref UnixDomainSocket::receiveHandler is a callback. + /// @ref UnixDomainSocketImpl::receiveHandler is a callback. /// /// @param data Pointer to a buffer into which the data should be read. /// @param length Length of the buffer. diff --git a/src/lib/asiolink/unix_domain_socket.h b/src/lib/asiolink/unix_domain_socket.h index db5ca294a9..0bb2164929 100644 --- a/src/lib/asiolink/unix_domain_socket.h +++ b/src/lib/asiolink/unix_domain_socket.h @@ -80,7 +80,7 @@ public: /// /// @param data Pointer to data to be sent. /// @param length Number of bytes to be sent. - /// @param handler Callback to be invoked when data have been sent or an + /// @param handler Callback to be invoked when data have been sent or /// sending error is signalled. void asyncSend(const void* data, const size_t length, const Handler& handler); diff --git a/src/lib/config/tests/client_connection_unittests.cc b/src/lib/config/tests/client_connection_unittests.cc index 3d9f7cd63e..a87e01977e 100644 --- a/src/lib/config/tests/client_connection_unittests.cc +++ b/src/lib/config/tests/client_connection_unittests.cc @@ -26,6 +26,7 @@ const std::string TEST_SOCKET = "test-socket"; /// @brief Test timeout in ms. const long TEST_TIMEOUT = 10000; +// Test fixture class for @ref ClientConnection. class ClientConnectionTest : public ::testing::Test { public: