BIND 10 trac805, updated. ddb94ad8340db3f41ede1a4509db23df5288cc05 [805] Test when rollback doesn't work

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Dec 21 16:00:08 UTC 2011


The branch, trac805 has been updated
       via  ddb94ad8340db3f41ede1a4509db23df5288cc05 (commit)
       via  9ec8253a3af8de3f85b1bce0ebabc88b7fa5a746 (commit)
      from  e40c9f512e4e0a388890e81b2825a51d8ce10739 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit ddb94ad8340db3f41ede1a4509db23df5288cc05
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Wed Dec 21 16:59:20 2011 +0100

    [805] Test when rollback doesn't work
    
    * The test fails
    * It should at last return and get to some consistent state (eg. not
      listening on anything).

commit 9ec8253a3af8de3f85b1bce0ebabc88b7fa5a746
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Wed Dec 21 16:50:57 2011 +0100

    [805] Update the documentation

-----------------------------------------------------------------------

Summary of changes:
 src/lib/server_common/portconfig.h                 |   14 ++++--
 src/lib/server_common/tests/portconfig_unittest.cc |   49 ++++++++++++++++++-
 2 files changed, 56 insertions(+), 7 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/server_common/portconfig.h b/src/lib/server_common/portconfig.h
index e4e7bf6..0c0fa6a 100644
--- a/src/lib/server_common/portconfig.h
+++ b/src/lib/server_common/portconfig.h
@@ -96,10 +96,12 @@ parseAddresses(isc::data::ConstElementPtr addresses,
  *
  * If it fails to set up the new addresses, it attempts to roll back to the
  * previous addresses (but it still propagates the exception). If the rollback
- * fails as well, it aborts the application (it assumes if it can't listen
- * on the new addresses nor on the old ones, the application is useless anyway
- * and should be restarted by Boss, not to mention that the internal state is
- * probably broken).
+ * fails as well, it doesn't abort the application (to allow reconfiguration),
+ * but removes all the sockets it listened on. One of the exceptions is
+ * propagated.
+ *
+ * The ports are requested from the socket creator through boss. Therefore
+ * you need to initialize the SocketRequestor before using this function.
  *
  * \param newAddresses are the addresses you want to listen on.
  * \param addressStore is the place you store your current addresses. It is
@@ -109,7 +111,11 @@ parseAddresses(isc::data::ConstElementPtr addresses,
  *     the new sockets are handled using this dnsService (and all current
  *     sockets on the service are closed first).
  * \throw asiolink::IOError when initialization or closing of socket fails.
+ * \throw isc::server_common::SocketRequestor::Socket error when the
+ *     boss/socket creator doesn't want to give us the socket.
  * \throw std::bad_alloc when allocation fails.
+ * \throw isc::InvalidOperation when the function is called and the
+ *     SocketRequestor isn't initialized yet.
  */
 void
 installListenAddresses(const AddressList& newAddresses,
diff --git a/src/lib/server_common/tests/portconfig_unittest.cc b/src/lib/server_common/tests/portconfig_unittest.cc
index 18036d5..e6c45a6 100644
--- a/src/lib/server_common/tests/portconfig_unittest.cc
+++ b/src/lib/server_common/tests/portconfig_unittest.cc
@@ -144,7 +144,7 @@ struct InstallListenAddresses : public ::testing::Test,
     public SocketRequestor {
     InstallListenAddresses() :
         dnss_(ios_, NULL, NULL, NULL),
-        last_token_(0)
+        last_token_(0), break_rollback_(false)
     {
         valid_.push_back(AddressPair("127.0.0.1", 5288));
         valid_.push_back(AddressPair("::1", 5288));
@@ -163,6 +163,8 @@ struct InstallListenAddresses : public ::testing::Test,
     vector<string> given_tokens_;
     // Last token number and fd given out
     size_t last_token_;
+    // Should we break the rollback?
+    bool break_rollback_;
     // Check that the store_ addresses are the same as expected
     void checkAddresses(const AddressList& expected, const string& name) {
         SCOPED_TRACE(name);
@@ -185,6 +187,15 @@ struct InstallListenAddresses : public ::testing::Test,
         if (address == "192.0.2.2") {
             isc_throw(SocketError, "This address is not allowed");
         }
+        if (address == "::1" && break_rollback_) {
+            // This is valid address, but in case we need to break the
+            // rollback, it needs to be busy or whatever
+            //
+            // We break the second address to see the first one was
+            // allocated and then returned
+            isc_throw(SocketError,
+                      "This address is available, but not for you");
+        }
         const string proto(protocol == TCP ? "TCP" : "UDP");
         size_t number = ++ last_token_;
         EXPECT_EQ(5288, port);
@@ -308,7 +319,39 @@ TEST_F(InstallListenAddresses, rollback) {
     checkTokens(released1, released_tokens_, "Released after rollback");
 }
 
-// TODO: Test where rollback fails, test it does return whatever it
-// requested during the rollback.
+// Try it at last returns everything when even the rollback fails.
+TEST_F(InstallListenAddresses, brokenRollback) {
+    EXPECT_NO_THROW(installListenAddresses(valid_, store_, dnss_));
+    checkAddresses(valid_, "Before rollback");
+    // Don't check the tokens now, we already do it in rollback and valid tests
+    given_tokens_.clear();
+    break_rollback_ = true;
+    EXPECT_THROW(installListenAddresses(invalid_, store_, dnss_), exception);
+    // No addresses here
+    EXPECT_TRUE(store_.empty());
+    // These should be requested in the first part of the failure to bind
+    // and the second pair in the first part of rollback
+    const char* tokens[] = {
+        "TCP:127.0.0.1:5288:5",
+        "UDP:127.0.0.1:5288:6",
+        "TCP:127.0.0.1:5288:7",
+        "UDP:127.0.0.1:5288:8",
+        NULL
+    };
+    // The first set should be returned, as well as all the ones we request now
+    const char* released[] = {
+        "TCP:127.0.0.1:5288:1",
+        "UDP:127.0.0.1:5288:2",
+        "TCP:::1:5288:3",
+        "UDP:::1:5288:4",
+        "TCP:127.0.0.1:5288:5",
+        "UDP:127.0.0.1:5288:6",
+        "TCP:127.0.0.1:5288:7",
+        "UDP:127.0.0.1:5288:8",
+        NULL
+    };
+    checkTokens(tokens, given_tokens_, "given");
+    checkTokens(released, released_tokens_, "released");
+}
 
 }




More information about the bind10-changes mailing list