Browse Source

[1543] Check it aborts on errors from releaseSocket

It happens to work already.
Michal 'vorner' Vaner 13 years ago
parent
commit
6868aeaa6c

+ 26 - 4
src/lib/server_common/tests/portconfig_unittest.cc

@@ -308,11 +308,33 @@ TEST_F(InstallListenAddressesDeathTest, inconsistent) {
     EXPECT_DEATH({
                     try {
                         installListenAddresses(deathAddresses, store_, dnss_);
-                    }
-                    // Prevent exceptions killing the application, we need to
-                    // make sure it dies the real hard way
-                    catch (...) {};
+                    } catch (...) {
+                        // Prevent exceptions killing the application, we need
+                        // to make sure it dies the real hard way
+                    };
                  }, "");
 }
 
+// If we are unable to tell the boss we closed a socket, we abort, as we are
+// not consistent with the boss most probably.
+TEST_F(InstallListenAddressesDeathTest, cantClose) {
+    installListenAddresses(valid_, store_, dnss_);
+    AddressList empty;
+    // Instruct it to fail on close
+    sock_requestor_.break_release_ = true;
+    EXPECT_DEATH({
+                    try {
+                        // Setting to empty will close all current sockets.
+                        // And thanks to the break_release_, the close will
+                        // throw, which will make it crash.
+                        installListenAddresses(empty, store_, dnss_);
+                    } catch (...) {
+                        // To make sure it is killed by abort, not by some
+                        // (unhandled) exception
+                    };
+                }, "");
+    // And reset it back, so it can safely clean up itself.
+    sock_requestor_.break_release_ = false;
+}
+
 }

+ 14 - 2
src/lib/testutils/socket_request.h

@@ -62,8 +62,8 @@ public:
     TestSocketRequestor(asiodns::DNSService& dnss,
                         server_common::portconfig::AddressList& store,
                         uint16_t expect_port) :
-        last_token_(0), break_rollback_(false), dnss_(dnss), store_(store),
-        expect_port_(expect_port)
+        last_token_(0), break_rollback_(false), break_release_(false),
+        dnss_(dnss), store_(store), expect_port_(expect_port)
     {
         // Prepare the requestor (us) for the test
         server_common::initTestSocketRequestor(this);
@@ -106,11 +106,23 @@ public:
     /// ::1 address is requested.
     bool break_rollback_;
 
+    /// \brief Throw on releaseSocket
+    ///
+    /// If this is set to true, the releaseSocket will throw SocketError.
+    /// Defaults to false.
+    bool break_release_;
+
     /// \brief Release a socket
     ///
     /// This only stores the token passed.
     /// \param token The socket to release
+    ///
+    /// \throw SocketError in case the break_release_ is set to true. This is
+    ///     to test exception handling.
     void releaseSocket(const std::string& token) {
+        if (break_release_) {
+            isc_throw(SocketError, "Fatal test socket error");
+        }
         released_tokens_.push_back(token);
     }