From: Marcin Siodelski Date: Thu, 24 May 2018 12:25:30 +0000 (+0200) Subject: [5576] Fixing freezing control agent forward tests. X-Git-Tag: trac5382a_base~9^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=03bcfe1dc573faac879a48cb346e096c706f70c6;p=thirdparty%2Fkea.git [5576] Fixing freezing control agent forward tests. --- diff --git a/src/bin/agent/tests/ca_command_mgr_unittests.cc b/src/bin/agent/tests/ca_command_mgr_unittests.cc index 45ebc5131f..ba692c4573 100644 --- a/src/bin/agent/tests/ca_command_mgr_unittests.cc +++ b/src/bin/agent/tests/ca_command_mgr_unittests.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2017-2018 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -242,14 +242,20 @@ 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(); + // Stop IO service immediatelly and let the thread die. + getIOService()->stop(); // Wait for the thread to finish. th.wait(); + // Cancel all asynchronous operations on the server. + server_socket_->stopServer(); + + // We have some cancelled operations for which we need to invoke the + // handlers with the operation_aborted error code. + getIOService()->get_io_service().reset(); + getIOService()->poll(); + EXPECT_EQ(expected_responses, server_socket_->getResponseNum()); checkAnswer(answer, expected_result0, expected_result1, expected_result2); } @@ -376,14 +382,20 @@ 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(); + // Stop IO service immediatelly and let the thread die. + getIOService()->stop(); // Wait for the thread to finish. th.wait(); + // Cancel all asynchronous operations on the server. + server_socket_->stopServer(); + + // We have some cancelled operations for which we need to invoke the + // handlers with the operation_aborted error code. + getIOService()->get_io_service().reset(); + getIOService()->poll(); + // Answer of 3 is specific to the stub response we send when the // command is forwarded. So having this value returned means that // the command was forwarded as expected. diff --git a/src/lib/asiolink/testutils/test_server_unix_socket.cc b/src/lib/asiolink/testutils/test_server_unix_socket.cc index c72b1270d7..3064d81b65 100644 --- a/src/lib/asiolink/testutils/test_server_unix_socket.cc +++ b/src/lib/asiolink/testutils/test_server_unix_socket.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2017-2018 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -60,7 +60,12 @@ public: /// @brief Closes the socket. void stop() { - socket_->close(); + try { + socket_->close(); + + } catch (...) { + // ignore errors when closing the socket. + } } /// @brief Handler invoked when data have been received over the socket. @@ -78,6 +83,8 @@ public: size_t bytes_transferred) { // This is most likely due to the abort. if (ec) { + // An error occurred so let's close the socket. + stop(); return; } @@ -92,7 +99,12 @@ public: boost::asio::buffer(response.c_str(), response.size())); } - start(); + /// @todo We're taking simplistic approach and send a response right away + /// after receiving data over the socket. Therefore, after responding we + /// do not schedule another read. We could extend this logic slightly to + /// parse the received data and see when we've got enough data before we + /// send a response. However, the current unit tests don't really require + /// that. // Invoke callback function to notify that the response has been sent. sent_response_callback_();