]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5576] Fixing freezing control agent forward tests.
authorMarcin Siodelski <marcin@isc.org>
Thu, 24 May 2018 12:25:30 +0000 (14:25 +0200)
committerMarcin Siodelski <marcin@isc.org>
Thu, 24 May 2018 12:25:30 +0000 (14:25 +0200)
src/bin/agent/tests/ca_command_mgr_unittests.cc
src/lib/asiolink/testutils/test_server_unix_socket.cc

index 45ebc5131fad00c4f09f3e5a32531bbc61961c62..ba692c457377d1f0c0cfb7019402dd1ced87b402 100644 (file)
@@ -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.
index c72b1270d7726b2aeaf1e9b8bd4f68f49091035f..3064d81b65c5b052e4e4fb6c47e3940d27150ecb 100644 (file)
@@ -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_();