]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2131] Clear attempts on entry and always request
authorFrancis Dupont <fdupont@isc.org>
Thu, 4 Nov 2021 15:57:22 +0000 (16:57 +0100)
committerFrancis Dupont <fdupont@isc.org>
Wed, 10 Nov 2021 11:42:23 +0000 (12:42 +0100)
12 files changed:
src/bin/d2/nc_add.cc
src/bin/d2/nc_remove.cc
src/bin/d2/simple_add.cc
src/bin/d2/simple_remove.cc
src/bin/d2/tests/d2_update_mgr_unittests.cc
src/bin/d2/tests/nc_add_unittests.cc
src/bin/d2/tests/nc_remove_unittests.cc
src/bin/d2/tests/simple_add_unittests.cc
src/bin/d2/tests/simple_remove_unittests.cc
src/lib/d2srv/nc_trans.cc
src/lib/d2srv/nc_trans.h
src/lib/d2srv/tests/nc_trans_unittests.cc

index 4a1661ac77b6dfd1f384336052e06b2a89b972f4..2d47d57b8b5c53a86741bae29b2d9a010d070819 100644 (file)
@@ -172,28 +172,26 @@ NameAddTransaction::selectingFwdServerHandler() {
 void
 NameAddTransaction::addingFwdAddrsHandler() {
     if (doOnEntry()) {
-        // Clear the request on initial transition. This allows us to reuse
-        // the request on retries if necessary.
-        clearDnsUpdateRequest();
+        // Clear the update attempts count on initial transition.
+        clearUpdateAttempts();
     }
+    // No reuse of the request on retries.
+    clearDnsUpdateRequest();
 
     switch(getNextEvent()) {
     case SERVER_SELECTED_EVT:
-        if (!getDnsUpdateRequest()) {
-            // Request hasn't been constructed yet, so build it.
-            try {
-                buildAddFwdAddressRequest();
-            } catch (const std::exception& ex) {
-                // While unlikely, the build might fail if we have invalid
-                // data.  Should that be the case, we need to fail the
-                // transaction.
-                LOG_ERROR(d2_to_dns_logger, DHCP_DDNS_FORWARD_ADD_BUILD_FAILURE)
-                          .arg(getRequestId())
-                          .arg(getNcr()->toText())
-                          .arg(ex.what());
-                transition(PROCESS_TRANS_FAILED_ST, UPDATE_FAILED_EVT);
-                break;
-            }
+        try {
+            buildAddFwdAddressRequest();
+        } catch (const std::exception& ex) {
+            // While unlikely, the build might fail if we have invalid
+            // data.  Should that be the case, we need to fail the
+            // transaction.
+            LOG_ERROR(d2_to_dns_logger, DHCP_DDNS_FORWARD_ADD_BUILD_FAILURE)
+                .arg(getRequestId())
+                .arg(getNcr()->toText())
+                .arg(ex.what());
+            transition(PROCESS_TRANS_FAILED_ST, UPDATE_FAILED_EVT);
+            break;
         }
 
         // Call sendUpdate() to initiate the async send. Note it also sets
@@ -287,29 +285,27 @@ NameAddTransaction::addingFwdAddrsHandler() {
 void
 NameAddTransaction::replacingFwdAddrsHandler() {
     if (doOnEntry()) {
-        // Clear the request on initial transition. This allows us to reuse
-        // the request on retries if necessary.
-        clearDnsUpdateRequest();
+        // Clear the update attempts count on initial transition.
+        clearUpdateAttempts();
     }
+    // No reuse of the request on retries.
+    clearDnsUpdateRequest();
 
     switch(getNextEvent()) {
     case FQDN_IN_USE_EVT:
     case SERVER_SELECTED_EVT:
-        if (!getDnsUpdateRequest()) {
-            // Request hasn't been constructed yet, so build it.
-            try {
-                buildReplaceFwdAddressRequest();
-            } catch (const std::exception& ex) {
-                // While unlikely, the build might fail if we have invalid
-                // data.  Should that be the case, we need to fail the
-                // transaction.
-                LOG_ERROR(d2_to_dns_logger, DHCP_DDNS_FORWARD_REPLACE_BUILD_FAILURE)
-                          .arg(getRequestId())
-                          .arg(getNcr()->toText())
-                          .arg(ex.what());
-                transition(PROCESS_TRANS_FAILED_ST, UPDATE_FAILED_EVT);
-                break;
-            }
+        try {
+            buildReplaceFwdAddressRequest();
+        } catch (const std::exception& ex) {
+            // While unlikely, the build might fail if we have invalid
+            // data.  Should that be the case, we need to fail the
+            // transaction.
+            LOG_ERROR(d2_to_dns_logger, DHCP_DDNS_FORWARD_REPLACE_BUILD_FAILURE)
+                .arg(getRequestId())
+                .arg(getNcr()->toText())
+                .arg(ex.what());
+            transition(PROCESS_TRANS_FAILED_ST, UPDATE_FAILED_EVT);
+            break;
         }
 
         // Call sendUpdate() to initiate the async send. Note it also sets
@@ -439,28 +435,26 @@ NameAddTransaction::selectingRevServerHandler() {
 void
 NameAddTransaction::replacingRevPtrsHandler() {
     if (doOnEntry()) {
-        // Clear the request on initial transition. This allows us to reuse
-        // the request on retries if necessary.
-        clearDnsUpdateRequest();
+        // Clear the update attempts count on initial transition.
+        clearUpdateAttempts();
     }
+    // No reuse of the request on retries.
+    clearDnsUpdateRequest();
 
     switch(getNextEvent()) {
     case SERVER_SELECTED_EVT:
-        if (!getDnsUpdateRequest()) {
-            // Request hasn't been constructed yet, so build it.
-            try {
-                buildReplaceRevPtrsRequest();
-            } catch (const std::exception& ex) {
-                // While unlikely, the build might fail if we have invalid
-                // data.  Should that be the case, we need to fail the
-                // transaction.
-                LOG_ERROR(d2_to_dns_logger, DHCP_DDNS_REVERSE_REPLACE_BUILD_FAILURE)
-                          .arg(getRequestId())
-                          .arg(getNcr()->toText())
-                          .arg(ex.what());
-                transition(PROCESS_TRANS_FAILED_ST, UPDATE_FAILED_EVT);
-                break;
-            }
+        try {
+            buildReplaceRevPtrsRequest();
+        } catch (const std::exception& ex) {
+            // While unlikely, the build might fail if we have invalid
+            // data.  Should that be the case, we need to fail the
+            // transaction.
+            LOG_ERROR(d2_to_dns_logger, DHCP_DDNS_REVERSE_REPLACE_BUILD_FAILURE)
+                .arg(getRequestId())
+                .arg(getNcr()->toText())
+                .arg(ex.what());
+            transition(PROCESS_TRANS_FAILED_ST, UPDATE_FAILED_EVT);
+            break;
         }
 
         // Call sendUpdate() to initiate the async send. Note it also sets
index 8c158598d32e15ebb5ac59909c31633929bfd8bc..6cc468fe69dc171804db132d7882b7e7e40a933f 100644 (file)
@@ -176,29 +176,27 @@ NameRemoveTransaction::selectingFwdServerHandler() {
 void
 NameRemoveTransaction::removingFwdAddrsHandler() {
     if (doOnEntry()) {
-        // Clear the request on initial transition. This allows us to reuse
-        // the request on retries if necessary.
-        clearDnsUpdateRequest();
+        // Clear the update attempts count on initial transition.
+        clearUpdateAttempts();
     }
+    // No reuse of the request on retries.
+    clearDnsUpdateRequest();
 
     switch(getNextEvent()) {
     case SERVER_SELECTED_EVT:
-        if (!getDnsUpdateRequest()) {
-            // Request hasn't been constructed yet, so build it.
-            try {
-                buildRemoveFwdAddressRequest();
-            } catch (const std::exception& ex) {
-                // While unlikely, the build might fail if we have invalid
-                // data.  Should that be the case, we need to fail the
-                // transaction.
-                LOG_ERROR(d2_to_dns_logger,
-                          DHCP_DDNS_FORWARD_REMOVE_ADDRS_BUILD_FAILURE)
-                          .arg(getRequestId())
-                          .arg(getNcr()->toText())
-                          .arg(ex.what());
-                transition(PROCESS_TRANS_FAILED_ST, UPDATE_FAILED_EVT);
-                break;
-            }
+        try {
+            buildRemoveFwdAddressRequest();
+        } catch (const std::exception& ex) {
+            // While unlikely, the build might fail if we have invalid
+            // data.  Should that be the case, we need to fail the
+            // transaction.
+            LOG_ERROR(d2_to_dns_logger,
+                      DHCP_DDNS_FORWARD_REMOVE_ADDRS_BUILD_FAILURE)
+                .arg(getRequestId())
+                .arg(getNcr()->toText())
+                .arg(ex.what());
+            transition(PROCESS_TRANS_FAILED_ST, UPDATE_FAILED_EVT);
+            break;
         }
 
         // Call sendUpdate() to initiate the async send. Note it also sets
@@ -286,30 +284,28 @@ NameRemoveTransaction::removingFwdAddrsHandler() {
 void
 NameRemoveTransaction::removingFwdRRsHandler() {
     if (doOnEntry()) {
-        // Clear the request on initial transition. This allows us to reuse
-        // the request on retries if necessary.
-        clearDnsUpdateRequest();
+        // Clear the update attempts count on initial transition.
+        clearUpdateAttempts();
     }
+    // No reuse of the request on retries.
+    clearDnsUpdateRequest();
 
     switch(getNextEvent()) {
     case UPDATE_OK_EVT:
     case SERVER_SELECTED_EVT:
-        if (!getDnsUpdateRequest()) {
-            // Request hasn't been constructed yet, so build it.
-            try {
-                buildRemoveFwdRRsRequest();
-            } catch (const std::exception& ex) {
-                // While unlikely, the build might fail if we have invalid
-                // data.  Should that be the case, we need to fail the
-                // transaction.
-                LOG_ERROR(d2_to_dns_logger,
-                          DHCP_DDNS_FORWARD_REMOVE_RRS_BUILD_FAILURE)
-                          .arg(getRequestId())
-                          .arg(getNcr()->toText())
-                          .arg(ex.what());
-                transition(PROCESS_TRANS_FAILED_ST, UPDATE_FAILED_EVT);
-                break;
-            }
+        try {
+            buildRemoveFwdRRsRequest();
+        } catch (const std::exception& ex) {
+            // While unlikely, the build might fail if we have invalid
+            // data.  Should that be the case, we need to fail the
+            // transaction.
+            LOG_ERROR(d2_to_dns_logger,
+                      DHCP_DDNS_FORWARD_REMOVE_RRS_BUILD_FAILURE)
+                .arg(getRequestId())
+                .arg(getNcr()->toText())
+                .arg(ex.what());
+            transition(PROCESS_TRANS_FAILED_ST, UPDATE_FAILED_EVT);
+            break;
         }
 
         // Call sendUpdate() to initiate the async send. Note it also sets
@@ -446,28 +442,26 @@ NameRemoveTransaction::selectingRevServerHandler() {
 void
 NameRemoveTransaction::removingRevPtrsHandler() {
     if (doOnEntry()) {
-        // Clear the request on initial transition. This allows us to reuse
-        // the request on retries if necessary.
-        clearDnsUpdateRequest();
+        // Clear the update attempts count on initial transition.
+        clearUpdateAttempts();
     }
+    // No reuse of the request on retries.
+    clearDnsUpdateRequest();
 
     switch(getNextEvent()) {
     case SERVER_SELECTED_EVT:
-        if (!getDnsUpdateRequest()) {
-            // Request hasn't been constructed yet, so build it.
-            try {
-                buildRemoveRevPtrsRequest();
-            } catch (const std::exception& ex) {
-                // While unlikely, the build might fail if we have invalid
-                // data.  Should that be the case, we need to fail the
-                // transaction.
-                LOG_ERROR(d2_to_dns_logger, DHCP_DDNS_REVERSE_REMOVE_BUILD_FAILURE)
-                          .arg(getRequestId())
-                          .arg(getNcr()->toText())
-                          .arg(ex.what());
-                transition(PROCESS_TRANS_FAILED_ST, UPDATE_FAILED_EVT);
-                break;
-            }
+        try {
+            buildRemoveRevPtrsRequest();
+        } catch (const std::exception& ex) {
+            // While unlikely, the build might fail if we have invalid
+            // data.  Should that be the case, we need to fail the
+            // transaction.
+            LOG_ERROR(d2_to_dns_logger, DHCP_DDNS_REVERSE_REMOVE_BUILD_FAILURE)
+                .arg(getRequestId())
+                .arg(getNcr()->toText())
+                .arg(ex.what());
+            transition(PROCESS_TRANS_FAILED_ST, UPDATE_FAILED_EVT);
+            break;
         }
 
         // Call sendUpdate() to initiate the async send. Note it also sets
index 7c7b0cf2c426a28953e180f118a05eb86cf6f50c..dcf0415c4b27e0ae5327ad2b309b6a1e90c323f1 100644 (file)
@@ -167,28 +167,26 @@ SimpleAddTransaction::selectingFwdServerHandler() {
 void
 SimpleAddTransaction::replacingFwdAddrsHandler() {
     if (doOnEntry()) {
-        // Clear the request on initial transition. This allows us to reuse
-        // the request on retries if necessary.
-        clearDnsUpdateRequest();
+        // Clear the update attempts count on initial transition.
+        clearUpdateAttempts();
     }
+    // No reuse of the request on retries.
+    clearDnsUpdateRequest();
 
     switch(getNextEvent()) {
     case SERVER_SELECTED_EVT:
-        if (!getDnsUpdateRequest()) {
-            // Request hasn't been constructed yet, so build it.
-            try {
-                buildReplaceFwdAddressRequest();
-            } catch (const std::exception& ex) {
-                // While unlikely, the build might fail if we have invalid
-                // data.  Should that be the case, we need to fail the
-                // transaction.
-                LOG_ERROR(d2_to_dns_logger, DHCP_DDNS_FORWARD_ADD_BUILD_FAILURE)
-                          .arg(getRequestId())
-                          .arg(getNcr()->toText())
-                          .arg(ex.what());
-                transition(PROCESS_TRANS_FAILED_ST, UPDATE_FAILED_EVT);
-                break;
-            }
+        try {
+            buildReplaceFwdAddressRequest();
+        } catch (const std::exception& ex) {
+            // While unlikely, the build might fail if we have invalid
+            // data.  Should that be the case, we need to fail the
+            // transaction.
+            LOG_ERROR(d2_to_dns_logger, DHCP_DDNS_FORWARD_ADD_BUILD_FAILURE)
+                .arg(getRequestId())
+                .arg(getNcr()->toText())
+                .arg(ex.what());
+            transition(PROCESS_TRANS_FAILED_ST, UPDATE_FAILED_EVT);
+            break;
         }
 
         // Call sendUpdate() to initiate the async send. Note it also sets
@@ -306,28 +304,26 @@ SimpleAddTransaction::selectingRevServerHandler() {
 void
 SimpleAddTransaction::replacingRevPtrsHandler() {
     if (doOnEntry()) {
-        // Clear the request on initial transition. This allows us to reuse
-        // the request on retries if necessary.
-        clearDnsUpdateRequest();
+        // Clear the update attempts count on initial transition.
+        clearUpdateAttempts();
     }
+    // No reuse of the request on retries.
+    clearDnsUpdateRequest();
 
     switch(getNextEvent()) {
     case SERVER_SELECTED_EVT:
-        if (!getDnsUpdateRequest()) {
-            // Request hasn't been constructed yet, so build it.
-            try {
-                buildReplaceRevPtrsRequest();
-            } catch (const std::exception& ex) {
-                // While unlikely, the build might fail if we have invalid
-                // data.  Should that be the case, we need to fail the
-                // transaction.
-                LOG_ERROR(d2_to_dns_logger, DHCP_DDNS_REVERSE_REPLACE_BUILD_FAILURE)
-                          .arg(getRequestId())
-                          .arg(getNcr()->toText())
-                          .arg(ex.what());
-                transition(PROCESS_TRANS_FAILED_ST, UPDATE_FAILED_EVT);
-                break;
-            }
+        try {
+            buildReplaceRevPtrsRequest();
+        } catch (const std::exception& ex) {
+            // While unlikely, the build might fail if we have invalid
+            // data.  Should that be the case, we need to fail the
+            // transaction.
+            LOG_ERROR(d2_to_dns_logger, DHCP_DDNS_REVERSE_REPLACE_BUILD_FAILURE)
+                .arg(getRequestId())
+                .arg(getNcr()->toText())
+                .arg(ex.what());
+            transition(PROCESS_TRANS_FAILED_ST, UPDATE_FAILED_EVT);
+            break;
         }
 
         // Call sendUpdate() to initiate the async send. Note it also sets
index e780080d71b478c2910646c0925e5184782c507c..823628e47893eab2ce20bf79e5d672ec3f58137e 100644 (file)
@@ -170,30 +170,28 @@ SimpleRemoveTransaction::selectingFwdServerHandler() {
 void
 SimpleRemoveTransaction::removingFwdRRsHandler() {
     if (doOnEntry()) {
-        // Clear the request on initial transition. This allows us to reuse
-        // the request on retries if necessary.
-        clearDnsUpdateRequest();
+        // Clear the update attempts count on initial transition.
+        clearUpdateAttempts();
     }
+    // No reuse of the request on retries.
+    clearDnsUpdateRequest();
 
     switch(getNextEvent()) {
     case UPDATE_OK_EVT:
     case SERVER_SELECTED_EVT:
-        if (!getDnsUpdateRequest()) {
-            // Request hasn't been constructed yet, so build it.
-            try {
-                buildRemoveFwdRRsRequest();
-            } catch (const std::exception& ex) {
-                // While unlikely, the build might fail if we have invalid
-                // data.  Should that be the case, we need to fail the
-                // transaction.
-                LOG_ERROR(d2_to_dns_logger,
-                          DHCP_DDNS_FORWARD_REMOVE_RRS_BUILD_FAILURE)
-                          .arg(getRequestId())
-                          .arg(getNcr()->toText())
-                          .arg(ex.what());
-                transition(PROCESS_TRANS_FAILED_ST, UPDATE_FAILED_EVT);
-                break;
-            }
+        try {
+            buildRemoveFwdRRsRequest();
+        } catch (const std::exception& ex) {
+            // While unlikely, the build might fail if we have invalid
+            // data.  Should that be the case, we need to fail the
+            // transaction.
+            LOG_ERROR(d2_to_dns_logger,
+                      DHCP_DDNS_FORWARD_REMOVE_RRS_BUILD_FAILURE)
+                .arg(getRequestId())
+                .arg(getNcr()->toText())
+                .arg(ex.what());
+            transition(PROCESS_TRANS_FAILED_ST, UPDATE_FAILED_EVT);
+            break;
         }
 
         // Call sendUpdate() to initiate the async send. Note it also sets
@@ -286,7 +284,6 @@ SimpleRemoveTransaction::removingFwdRRsHandler() {
     }
 }
 
-
 void
 SimpleRemoveTransaction::selectingRevServerHandler() {
     switch(getNextEvent()) {
@@ -320,28 +317,26 @@ SimpleRemoveTransaction::selectingRevServerHandler() {
 void
 SimpleRemoveTransaction::removingRevPtrsHandler() {
     if (doOnEntry()) {
-        // Clear the request on initial transition. This allows us to reuse
-        // the request on retries if necessary.
-        clearDnsUpdateRequest();
+        // Clear the update attempts count on initial transition.
+        clearUpdateAttempts();
     }
+    // No reuse of the request on retries.
+    clearDnsUpdateRequest();
 
     switch(getNextEvent()) {
     case SERVER_SELECTED_EVT:
-        if (!getDnsUpdateRequest()) {
-            // Request hasn't been constructed yet, so build it.
-            try {
-                buildRemoveRevPtrsRequest();
-            } catch (const std::exception& ex) {
-                // While unlikely, the build might fail if we have invalid
-                // data.  Should that be the case, we need to fail the
-                // transaction.
-                LOG_ERROR(d2_to_dns_logger, DHCP_DDNS_REVERSE_REMOVE_BUILD_FAILURE)
-                          .arg(getRequestId())
-                          .arg(getNcr()->toText())
-                          .arg(ex.what());
-                transition(PROCESS_TRANS_FAILED_ST, UPDATE_FAILED_EVT);
-                break;
-            }
+        try {
+            buildRemoveRevPtrsRequest();
+        } catch (const std::exception& ex) {
+            // While unlikely, the build might fail if we have invalid
+            // data.  Should that be the case, we need to fail the
+            // transaction.
+            LOG_ERROR(d2_to_dns_logger, DHCP_DDNS_REVERSE_REMOVE_BUILD_FAILURE)
+                .arg(getRequestId())
+                .arg(getNcr()->toText())
+                .arg(ex.what());
+            transition(PROCESS_TRANS_FAILED_ST, UPDATE_FAILED_EVT);
+            break;
         }
 
         // Call sendUpdate() to initiate the async send. Note it also sets
index ce2bb3e90257b6bcd334c382f989083061368254..d79b4538f0b6fadbda9182a6da98356c8408747e 100644 (file)
@@ -232,8 +232,8 @@ public:
             // value).  This is roughly ten times the number for the longest
             // test (currently, multiTransactionTimeout).
             if (passes > max_passes) {
-                ADD_FAILURE() << "processALL failed, too many passes: "
-                    << passes <<  ", total handlers executed: " << handlers;
+                FAIL() << "processALL failed, too many passes: "
+                       << passes <<  ", total handlers executed: " << handlers;
             }
         }
     }
index ec8351aed2565fa81ed6b0aef1363719d200fbe4..3f36b46737f1595688a8cdf89bf4679769cb0a5c 100644 (file)
@@ -714,24 +714,9 @@ TEST_F(NameAddTransactionTest, addingFwdAddrsHandler_Timeout) {
     // and then transition to selecting a new server.
     int max_tries = NameChangeTransaction::MAX_UPDATE_TRIES_PER_SERVER;
     for (int i = 1; i <= max_tries; ++i) {
-        const D2UpdateMessagePtr prev_msg = name_add->getDnsUpdateRequest();
-
         // Run addingFwdAddrsHandler to send the request.
         EXPECT_NO_THROW(name_add->addingFwdAddrsHandler());
 
-        const D2UpdateMessagePtr curr_msg = name_add->getDnsUpdateRequest();
-        if (i == 1) {
-            // First time out we should build the message.
-            EXPECT_FALSE(prev_msg);
-            EXPECT_TRUE(curr_msg);
-        } else {
-            // Subsequent passes should reuse the request. We are only
-            // looking to check that we have not replaced the pointer value
-            // with a new pointer.  This tests the on_entry() logic which
-            // clears the request ONLY upon initial entry into the state.
-            EXPECT_TRUE(prev_msg == curr_msg);
-        }
-
         // Simulate a server IO timeout.
         name_add->setDnsUpdateStatus(DNSClient::TIMEOUT);
         name_add->postNextEvent(NameChangeTransaction::IO_COMPLETED_EVT);
@@ -1059,24 +1044,9 @@ TEST_F(NameAddTransactionTest, replacingFwdAddrsHandler_Timeout) {
     // and then transition to selecting a new server.
     int max_tries = NameChangeTransaction::MAX_UPDATE_TRIES_PER_SERVER;
     for (int i = 1; i <= max_tries; ++i) {
-        const D2UpdateMessagePtr prev_msg = name_add->getDnsUpdateRequest();
-
         // Run replacingFwdAddrsHandler to send the request.
         EXPECT_NO_THROW(name_add->replacingFwdAddrsHandler());
 
-        const D2UpdateMessagePtr curr_msg = name_add->getDnsUpdateRequest();
-        if (i == 1) {
-            // First time out we should build the message.
-            EXPECT_FALSE(prev_msg);
-            EXPECT_TRUE(curr_msg);
-        } else {
-            // Subsequent passes should reuse the request. We are only
-            // looking to check that we have not replaced the pointer value
-            // with a new pointer.  This tests the on_entry() logic which
-            // clears the request ONLY upon initial entry into the state.
-            EXPECT_TRUE(prev_msg == curr_msg);
-        }
-
         // Simulate a server IO timeout.
         name_add->setDnsUpdateStatus(DNSClient::TIMEOUT);
         name_add->postNextEvent(NameChangeTransaction::IO_COMPLETED_EVT);
@@ -1127,24 +1097,9 @@ TEST_F(NameAddTransactionTest, replacingFwdAddrsHandler_CorruptResponse) {
     // and then transition to selecting a new server.
     int max_tries = NameChangeTransaction::MAX_UPDATE_TRIES_PER_SERVER;
     for (int i = 1; i <= max_tries; ++i) {
-        const D2UpdateMessagePtr prev_msg = name_add->getDnsUpdateRequest();
-
         // Run replacingFwdAddrsHandler to send the request.
         EXPECT_NO_THROW(name_add->replacingFwdAddrsHandler());
 
-        const D2UpdateMessagePtr curr_msg = name_add->getDnsUpdateRequest();
-        if (i == 1) {
-            // First time out we should build the message.
-            EXPECT_FALSE(prev_msg);
-            EXPECT_TRUE(curr_msg);
-        } else {
-            // Subsequent passes should reuse the request. We are only
-            // looking to check that we have not replaced the pointer value
-            // with a new pointer.  This tests the on_entry() logic which
-            // clears the request ONLY upon initial entry into the state.
-            EXPECT_TRUE(prev_msg == curr_msg);
-        }
-
         // Simulate a corrupt server response.
         name_add->setDnsUpdateStatus(DNSClient::INVALID_RESPONSE);
         name_add->postNextEvent(NameChangeTransaction::IO_COMPLETED_EVT);
@@ -1371,24 +1326,9 @@ TEST_F(NameAddTransactionTest, replacingRevPtrsHandler_Timeout) {
     // and then transition to selecting a new server.
     int max_tries = NameChangeTransaction::MAX_UPDATE_TRIES_PER_SERVER;
     for (int i = 1; i <= max_tries; ++i) {
-        const D2UpdateMessagePtr prev_msg = name_add->getDnsUpdateRequest();
-
         // Run replacingRevPtrsHandler to send the request.
         EXPECT_NO_THROW(name_add->replacingRevPtrsHandler());
 
-        const D2UpdateMessagePtr curr_msg = name_add->getDnsUpdateRequest();
-        if (i == 1) {
-            // First time out we should build the message.
-            EXPECT_FALSE(prev_msg);
-            EXPECT_TRUE(curr_msg);
-        } else {
-            // Subsequent passes should reuse the request. We are only
-            // looking to check that we have not replaced the pointer value
-            // with a new pointer.  This tests the on_entry() logic which
-            // clears the request ONLY upon initial entry into the state.
-            EXPECT_TRUE(prev_msg == curr_msg);
-        }
-
         // Simulate a server IO timeout.
         name_add->setDnsUpdateStatus(DNSClient::TIMEOUT);
         name_add->postNextEvent(NameChangeTransaction::IO_COMPLETED_EVT);
@@ -1438,24 +1378,9 @@ TEST_F(NameAddTransactionTest, replacingRevPtrsHandler_CorruptResponse) {
     // and then transition to selecting a new server.
     int max_tries = NameChangeTransaction::MAX_UPDATE_TRIES_PER_SERVER;
     for (int i = 1; i <= max_tries; ++i) {
-        const D2UpdateMessagePtr prev_msg = name_add->getDnsUpdateRequest();
-
         // Run replacingRevPtrsHandler to send the request.
         EXPECT_NO_THROW(name_add->replacingRevPtrsHandler());
 
-        const D2UpdateMessagePtr curr_msg = name_add->getDnsUpdateRequest();
-        if (i == 1) {
-            // First time out we should build the message.
-            EXPECT_FALSE(prev_msg);
-            EXPECT_TRUE(curr_msg);
-        } else {
-            // Subsequent passes should reuse the request. We are only
-            // looking to check that we have not replaced the pointer value
-            // with a new pointer.  This tests the on_entry() logic which
-            // clears the request ONLY upon initial entry into the state.
-            EXPECT_TRUE(prev_msg == curr_msg);
-        }
-
         // Simulate a server corrupt response.
         name_add->setDnsUpdateStatus(DNSClient::INVALID_RESPONSE);
         name_add->postNextEvent(NameChangeTransaction::IO_COMPLETED_EVT);
index 3889c7cbab72c134e64add83aa29730f19825395..4373811f17cd8cf97f39a7c48d33c12e8498df83 100644 (file)
@@ -692,24 +692,9 @@ TEST_F(NameRemoveTransactionTest, removingFwdAddrsHandler_Timeout) {
     // and then transition to selecting a new server.
     int max_tries = NameChangeTransaction::MAX_UPDATE_TRIES_PER_SERVER;
     for (int i = 1; i <= max_tries; ++i) {
-        const D2UpdateMessagePtr prev_msg = name_remove->getDnsUpdateRequest();
-
         // Run removingFwdAddrsHandler to send the request.
         EXPECT_NO_THROW(name_remove->removingFwdAddrsHandler());
 
-        const D2UpdateMessagePtr curr_msg = name_remove->getDnsUpdateRequest();
-        if (i == 1) {
-            // First time around we should build the message.
-            EXPECT_FALSE(prev_msg);
-            EXPECT_TRUE(curr_msg);
-        } else {
-            // Subsequent passes should reuse the request. We are only
-            // looking to check that we have not replaced the pointer value
-            // with a new pointer.  This tests the on_entry() logic which
-            // clears the request ONLY upon initial entry into the state.
-            EXPECT_TRUE(prev_msg == curr_msg);
-        }
-
         // Simulate a server IO timeout.
         name_remove->setDnsUpdateStatus(DNSClient::TIMEOUT);
         name_remove->postNextEvent(NameChangeTransaction::IO_COMPLETED_EVT);
@@ -1045,24 +1030,9 @@ TEST_F(NameRemoveTransactionTest, removingFwdRRsHandler_Timeout) {
     // and then transition to selecting a new server.
     int max_tries = NameChangeTransaction::MAX_UPDATE_TRIES_PER_SERVER;
     for (int i = 1; i <= max_tries; ++i) {
-        const D2UpdateMessagePtr prev_msg = name_remove->getDnsUpdateRequest();
-
         // Run removingFwdRRsHandler to send the request.
         EXPECT_NO_THROW(name_remove->removingFwdRRsHandler());
 
-        const D2UpdateMessagePtr curr_msg = name_remove->getDnsUpdateRequest();
-        if (i == 1) {
-            // First time around we should build the message.
-            EXPECT_FALSE(prev_msg);
-            EXPECT_TRUE(curr_msg);
-        } else {
-            // Subsequent passes should reuse the request. We are only
-            // looking to check that we have not replaced the pointer value
-            // with a new pointer.  This tests the on_entry() logic which
-            // clears the request ONLY upon initial entry into the state.
-            EXPECT_TRUE(prev_msg == curr_msg);
-        }
-
         // Simulate a server IO timeout.
         name_remove->setDnsUpdateStatus(DNSClient::TIMEOUT);
         name_remove->postNextEvent(NameChangeTransaction::IO_COMPLETED_EVT);
@@ -1115,24 +1085,9 @@ TEST_F(NameRemoveTransactionTest, removingFwdRRsHandler_InvalidResponse) {
     // and then transition to selecting a new server.
     int max_tries = NameChangeTransaction::MAX_UPDATE_TRIES_PER_SERVER;
     for (int i = 1; i <= max_tries; ++i) {
-        const D2UpdateMessagePtr prev_msg = name_remove->getDnsUpdateRequest();
-
         // Run removingFwdRRsHandler to send the request.
         EXPECT_NO_THROW(name_remove->removingFwdRRsHandler());
 
-        const D2UpdateMessagePtr curr_msg = name_remove->getDnsUpdateRequest();
-        if (i == 1) {
-            // First time around we should build the message.
-            EXPECT_FALSE(prev_msg);
-            EXPECT_TRUE(curr_msg);
-        } else {
-            // Subsequent passes should reuse the request. We are only
-            // looking to check that we have not replaced the pointer value
-            // with a new pointer.  This tests the on_entry() logic which
-            // clears the request ONLY upon initial entry into the state.
-            EXPECT_TRUE(prev_msg == curr_msg);
-        }
-
         // Simulate a corrupt server response.
         name_remove->setDnsUpdateStatus(DNSClient::INVALID_RESPONSE);
         name_remove->postNextEvent(NameChangeTransaction::IO_COMPLETED_EVT);
@@ -1419,24 +1374,9 @@ TEST_F(NameRemoveTransactionTest, removingRevPtrsHandler_Timeout) {
     // and then transition to selecting a new server.
     int max_tries = NameChangeTransaction::MAX_UPDATE_TRIES_PER_SERVER;
     for (int i = 1; i <= max_tries; ++i) {
-        const D2UpdateMessagePtr prev_msg = name_remove->getDnsUpdateRequest();
-
         // Run removingRevPtrsHandler to send the request.
         EXPECT_NO_THROW(name_remove->removingRevPtrsHandler());
 
-        const D2UpdateMessagePtr curr_msg = name_remove->getDnsUpdateRequest();
-        if (i == 1) {
-            // First time around we should build the message.
-            EXPECT_FALSE(prev_msg);
-            EXPECT_TRUE(curr_msg);
-        } else {
-            // Subsequent passes should reuse the request. We are only
-            // looking to check that we have not replaced the pointer value
-            // with a new pointer.  This tests the on_entry() logic which
-            // clears the request ONLY upon initial entry into the state.
-            EXPECT_TRUE(prev_msg == curr_msg);
-        }
-
         // Simulate a server IO timeout.
         name_remove->setDnsUpdateStatus(DNSClient::TIMEOUT);
         name_remove->postNextEvent(NameChangeTransaction::IO_COMPLETED_EVT);
@@ -1488,24 +1428,9 @@ TEST_F(NameRemoveTransactionTest, removingRevPtrsHandler_CorruptResponse) {
     // and then transition to selecting a new server.
     int max_tries = NameChangeTransaction::MAX_UPDATE_TRIES_PER_SERVER;
     for (int i = 1; i <= max_tries; ++i) {
-        const D2UpdateMessagePtr prev_msg = name_remove->getDnsUpdateRequest();
-
         // Run removingRevPtrsHandler to send the request.
         EXPECT_NO_THROW(name_remove->removingRevPtrsHandler());
 
-        const D2UpdateMessagePtr curr_msg = name_remove->getDnsUpdateRequest();
-        if (i == 1) {
-            // First time around we should build the message.
-            EXPECT_FALSE(prev_msg);
-            EXPECT_TRUE(curr_msg);
-        } else {
-            // Subsequent passes should reuse the request. We are only
-            // looking to check that we have not replaced the pointer value
-            // with a new pointer.  This tests the on_entry() logic which
-            // clears the request ONLY upon initial entry into the state.
-            EXPECT_TRUE(prev_msg == curr_msg);
-        }
-
         // Simulate a server corrupt response.
         name_remove->setDnsUpdateStatus(DNSClient::INVALID_RESPONSE);
         name_remove->postNextEvent(NameChangeTransaction::IO_COMPLETED_EVT);
index 54bc7fabe5288928d428b9e3d0d902c04e2f46e6..c47a2b6f4b3464002d7bc08e9316cf6f851637b1 100644 (file)
@@ -598,24 +598,9 @@ TEST_F(SimpleAddTransactionTest, replacingFwdAddrsHandler_Timeout) {
     // and then transition to selecting a new server.
     int max_tries = NameChangeTransaction::MAX_UPDATE_TRIES_PER_SERVER;
     for (int i = 1; i <= max_tries; ++i) {
-        const D2UpdateMessagePtr prev_msg = name_add->getDnsUpdateRequest();
-
         // Run replacingFwdAddrsHandler to send the request.
         EXPECT_NO_THROW(name_add->replacingFwdAddrsHandler());
 
-        const D2UpdateMessagePtr curr_msg = name_add->getDnsUpdateRequest();
-        if (i == 1) {
-            // First time out we should build the message.
-            EXPECT_FALSE(prev_msg);
-            EXPECT_TRUE(curr_msg);
-        } else {
-            // Subsequent passes should reuse the request. We are only
-            // looking to check that we have not replaced the pointer value
-            // with a new pointer.  This tests the on_entry() logic which
-            // clears the request ONLY upon initial entry into the state.
-            EXPECT_TRUE(prev_msg == curr_msg);
-        }
-
         // Simulate a server IO timeout.
         name_add->setDnsUpdateStatus(DNSClient::TIMEOUT);
         name_add->postNextEvent(NameChangeTransaction::IO_COMPLETED_EVT);
@@ -662,24 +647,9 @@ TEST_F(SimpleAddTransactionTest, replacingFwdAddrsHandler_CorruptResponse) {
     // and then transition to selecting a new server.
     int max_tries = NameChangeTransaction::MAX_UPDATE_TRIES_PER_SERVER;
     for (int i = 1; i <= max_tries; ++i) {
-        const D2UpdateMessagePtr prev_msg = name_add->getDnsUpdateRequest();
-
         // Run replacingFwdAddrsHandler to send the request.
         EXPECT_NO_THROW(name_add->replacingFwdAddrsHandler());
 
-        const D2UpdateMessagePtr curr_msg = name_add->getDnsUpdateRequest();
-        if (i == 1) {
-            // First time out we should build the message.
-            EXPECT_FALSE(prev_msg);
-            EXPECT_TRUE(curr_msg);
-        } else {
-            // Subsequent passes should reuse the request. We are only
-            // looking to check that we have not replaced the pointer value
-            // with a new pointer.  This tests the on_entry() logic which
-            // clears the request ONLY upon initial entry into the state.
-            EXPECT_TRUE(prev_msg == curr_msg);
-        }
-
         // Simulate a corrupt server response.
         name_add->setDnsUpdateStatus(DNSClient::INVALID_RESPONSE);
         name_add->postNextEvent(NameChangeTransaction::IO_COMPLETED_EVT);
@@ -886,24 +856,9 @@ TEST_F(SimpleAddTransactionTest, replacingRevPtrsHandler_Timeout) {
     // and then transition to selecting a new server.
     int max_tries = NameChangeTransaction::MAX_UPDATE_TRIES_PER_SERVER;
     for (int i = 1; i <= max_tries; ++i) {
-        const D2UpdateMessagePtr prev_msg = name_add->getDnsUpdateRequest();
-
         // Run replacingRevPtrsHandler to send the request.
         EXPECT_NO_THROW(name_add->replacingRevPtrsHandler());
 
-        const D2UpdateMessagePtr curr_msg = name_add->getDnsUpdateRequest();
-        if (i == 1) {
-            // First time out we should build the message.
-            EXPECT_FALSE(prev_msg);
-            EXPECT_TRUE(curr_msg);
-        } else {
-            // Subsequent passes should reuse the request. We are only
-            // looking to check that we have not replaced the pointer value
-            // with a new pointer.  This tests the on_entry() logic which
-            // clears the request ONLY upon initial entry into the state.
-            EXPECT_TRUE(prev_msg == curr_msg);
-        }
-
         // Simulate a server IO timeout.
         name_add->setDnsUpdateStatus(DNSClient::TIMEOUT);
         name_add->postNextEvent(NameChangeTransaction::IO_COMPLETED_EVT);
@@ -949,24 +904,9 @@ TEST_F(SimpleAddTransactionTest, replacingRevPtrsHandler_CorruptResponse) {
     // and then transition to selecting a new server.
     int max_tries = NameChangeTransaction::MAX_UPDATE_TRIES_PER_SERVER;
     for (int i = 1; i <= max_tries; ++i) {
-        const D2UpdateMessagePtr prev_msg = name_add->getDnsUpdateRequest();
-
         // Run replacingRevPtrsHandler to send the request.
         EXPECT_NO_THROW(name_add->replacingRevPtrsHandler());
 
-        const D2UpdateMessagePtr curr_msg = name_add->getDnsUpdateRequest();
-        if (i == 1) {
-            // First time out we should build the message.
-            EXPECT_FALSE(prev_msg);
-            EXPECT_TRUE(curr_msg);
-        } else {
-            // Subsequent passes should reuse the request. We are only
-            // looking to check that we have not replaced the pointer value
-            // with a new pointer.  This tests the on_entry() logic which
-            // clears the request ONLY upon initial entry into the state.
-            EXPECT_TRUE(prev_msg == curr_msg);
-        }
-
         // Simulate a server corrupt response.
         name_add->setDnsUpdateStatus(DNSClient::INVALID_RESPONSE);
         name_add->postNextEvent(NameChangeTransaction::IO_COMPLETED_EVT);
index de74cc520cc2ad88e47b8ca4b2ea3a39e8d8ac07..1d53400fc9d138a80d74082460f1b2228f6a447c 100644 (file)
@@ -605,24 +605,9 @@ TEST_F(SimpleRemoveTransactionTest, removingFwdRRsHandler_Timeout) {
     // and then transition to selecting a new server.
     int max_tries = NameChangeTransaction::MAX_UPDATE_TRIES_PER_SERVER;
     for (int i = 1; i <= max_tries; ++i) {
-        const D2UpdateMessagePtr prev_msg = name_remove->getDnsUpdateRequest();
-
         // Run removingFwdRRsHandler to send the request.
         EXPECT_NO_THROW(name_remove->removingFwdRRsHandler());
 
-        const D2UpdateMessagePtr curr_msg = name_remove->getDnsUpdateRequest();
-        if (i == 1) {
-            // First time around we should build the message.
-            EXPECT_FALSE(prev_msg);
-            EXPECT_TRUE(curr_msg);
-        } else {
-            // Subsequent passes should reuse the request. We are only
-            // looking to check that we have not replaced the pointer value
-            // with a new pointer.  This tests the on_entry() logic which
-            // clears the request ONLY upon initial entry into the state.
-            EXPECT_TRUE(prev_msg == curr_msg);
-        }
-
         // Simulate a server IO timeout.
         name_remove->setDnsUpdateStatus(DNSClient::TIMEOUT);
         name_remove->postNextEvent(NameChangeTransaction::IO_COMPLETED_EVT);
@@ -669,24 +654,9 @@ TEST_F(SimpleRemoveTransactionTest, removingFwdRRsHandler_InvalidResponse) {
     // and then transition to selecting a new server.
     int max_tries = NameChangeTransaction::MAX_UPDATE_TRIES_PER_SERVER;
     for (int i = 1; i <= max_tries; ++i) {
-        const D2UpdateMessagePtr prev_msg = name_remove->getDnsUpdateRequest();
-
         // Run removingFwdRRsHandler to send the request.
         EXPECT_NO_THROW(name_remove->removingFwdRRsHandler());
 
-        const D2UpdateMessagePtr curr_msg = name_remove->getDnsUpdateRequest();
-        if (i == 1) {
-            // First time around we should build the message.
-            EXPECT_FALSE(prev_msg);
-            EXPECT_TRUE(curr_msg);
-        } else {
-            // Subsequent passes should reuse the request. We are only
-            // looking to check that we have not replaced the pointer value
-            // with a new pointer.  This tests the on_entry() logic which
-            // clears the request ONLY upon initial entry into the state.
-            EXPECT_TRUE(prev_msg == curr_msg);
-        }
-
         // Simulate a corrupt server response.
         name_remove->setDnsUpdateStatus(DNSClient::INVALID_RESPONSE);
         name_remove->postNextEvent(NameChangeTransaction::IO_COMPLETED_EVT);
@@ -945,24 +915,9 @@ TEST_F(SimpleRemoveTransactionTest, removingRevPtrsHandler_Timeout) {
     // and then transition to selecting a new server.
     int max_tries = NameChangeTransaction::MAX_UPDATE_TRIES_PER_SERVER;
     for (int i = 1; i <= max_tries; ++i) {
-        const D2UpdateMessagePtr prev_msg = name_remove->getDnsUpdateRequest();
-
         // Run removingRevPtrsHandler to send the request.
         EXPECT_NO_THROW(name_remove->removingRevPtrsHandler());
 
-        const D2UpdateMessagePtr curr_msg = name_remove->getDnsUpdateRequest();
-        if (i == 1) {
-            // First time around we should build the message.
-            EXPECT_FALSE(prev_msg);
-            EXPECT_TRUE(curr_msg);
-        } else {
-            // Subsequent passes should reuse the request. We are only
-            // looking to check that we have not replaced the pointer value
-            // with a new pointer.  This tests the on_entry() logic which
-            // clears the request ONLY upon initial entry into the state.
-            EXPECT_TRUE(prev_msg == curr_msg);
-        }
-
         // Simulate a server IO timeout.
         name_remove->setDnsUpdateStatus(DNSClient::TIMEOUT);
         name_remove->postNextEvent(NameChangeTransaction::IO_COMPLETED_EVT);
@@ -1009,24 +964,9 @@ TEST_F(SimpleRemoveTransactionTest, removingRevPtrsHandler_CorruptResponse) {
     // and then transition to selecting a new server.
     int max_tries = NameChangeTransaction::MAX_UPDATE_TRIES_PER_SERVER;
     for (int i = 1; i <= max_tries; ++i) {
-        const D2UpdateMessagePtr prev_msg = name_remove->getDnsUpdateRequest();
-
         // Run removingRevPtrsHandler to send the request.
         EXPECT_NO_THROW(name_remove->removingRevPtrsHandler());
 
-        const D2UpdateMessagePtr curr_msg = name_remove->getDnsUpdateRequest();
-        if (i == 1) {
-            // First time around we should build the message.
-            EXPECT_FALSE(prev_msg);
-            EXPECT_TRUE(curr_msg);
-        } else {
-            // Subsequent passes should reuse the request. We are only
-            // looking to check that we have not replaced the pointer value
-            // with a new pointer.  This tests the on_entry() logic which
-            // clears the request ONLY upon initial entry into the state.
-            EXPECT_TRUE(prev_msg == curr_msg);
-        }
-
         // Simulate a server corrupt response.
         name_remove->setDnsUpdateStatus(DNSClient::INVALID_RESPONSE);
         name_remove->postNextEvent(NameChangeTransaction::IO_COMPLETED_EVT);
index 32407e04372fec44222ebe23563d1cee7901e44d..e9534c256c85647bc063c8eb5795742439c0a63d 100644 (file)
@@ -301,10 +301,14 @@ NameChangeTransaction::setDnsUpdateRequest(D2UpdateMessagePtr& request) {
 
 void
 NameChangeTransaction::clearDnsUpdateRequest() {
-    update_attempts_ = 0;
     dns_update_request_.reset();
 }
 
+void
+NameChangeTransaction::clearUpdateAttempts() {
+    update_attempts_ = 0;
+}
+
 void
 NameChangeTransaction::setDnsUpdateStatus(const DNSClient::Status& status) {
     dns_update_status_ = status;
index cfbc9ec45cea8cbe99e5257e1262bd7c09cf7221..2aee7eccfbe391f639082a34e53030a466681fe1 100644 (file)
@@ -288,10 +288,12 @@ protected:
     /// @param request is the new request packet to assign.
     void setDnsUpdateRequest(D2UpdateMessagePtr& request);
 
-    /// @brief Destroys the current update request packet and resets
-    /// update attempts count.
+    /// @brief Destroys the current update request packet.
     void clearDnsUpdateRequest();
 
+    /// @brief Resets the update attempts count.
+    void clearUpdateAttempts();
+
     /// @brief Sets the update status to the given status value.
     ///
     /// @param status is the new value for the update status.
index e461a2aacf9f4cedf02b6efccbcf27a0eb98ba4a..89a23b78065c2f6d1bf0de8009953e212f1ef2c5 100644 (file)
@@ -237,6 +237,7 @@ public:
     using NameChangeTransaction::setNcrStatus;
     using NameChangeTransaction::setDnsUpdateRequest;
     using NameChangeTransaction::clearDnsUpdateRequest;
+    using NameChangeTransaction::clearUpdateAttempts;
     using NameChangeTransaction::setDnsUpdateStatus;
     using NameChangeTransaction::getDnsUpdateResponse;
     using NameChangeTransaction::setDnsUpdateResponse;
@@ -873,6 +874,12 @@ TEST_F(NameChangeTransactionTest, updateAttempts) {
 
     // Verify that the value is as expected.
     EXPECT_EQ(5, name_change->getUpdateAttempts());
+
+    // Clear it.
+    name_change->clearUpdateAttempts();
+
+    // Verify that it was cleared as expected.
+    EXPECT_EQ(0, name_change->getUpdateAttempts());
 }
 
 /// @brief Tests retryTransition method