From: Francis Dupont Date: Thu, 4 Nov 2021 15:57:22 +0000 (+0100) Subject: [#2131] Clear attempts on entry and always request X-Git-Tag: eng-drop-2021-11-10~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4135f1cf7403ce4cf6894db379f60da44d698b65;p=thirdparty%2Fkea.git [#2131] Clear attempts on entry and always request --- diff --git a/src/bin/d2/nc_add.cc b/src/bin/d2/nc_add.cc index 4a1661ac77..2d47d57b8b 100644 --- a/src/bin/d2/nc_add.cc +++ b/src/bin/d2/nc_add.cc @@ -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 diff --git a/src/bin/d2/nc_remove.cc b/src/bin/d2/nc_remove.cc index 8c158598d3..6cc468fe69 100644 --- a/src/bin/d2/nc_remove.cc +++ b/src/bin/d2/nc_remove.cc @@ -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 diff --git a/src/bin/d2/simple_add.cc b/src/bin/d2/simple_add.cc index 7c7b0cf2c4..dcf0415c4b 100644 --- a/src/bin/d2/simple_add.cc +++ b/src/bin/d2/simple_add.cc @@ -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 diff --git a/src/bin/d2/simple_remove.cc b/src/bin/d2/simple_remove.cc index e780080d71..823628e478 100644 --- a/src/bin/d2/simple_remove.cc +++ b/src/bin/d2/simple_remove.cc @@ -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 diff --git a/src/bin/d2/tests/d2_update_mgr_unittests.cc b/src/bin/d2/tests/d2_update_mgr_unittests.cc index ce2bb3e902..d79b4538f0 100644 --- a/src/bin/d2/tests/d2_update_mgr_unittests.cc +++ b/src/bin/d2/tests/d2_update_mgr_unittests.cc @@ -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; } } } diff --git a/src/bin/d2/tests/nc_add_unittests.cc b/src/bin/d2/tests/nc_add_unittests.cc index ec8351aed2..3f36b46737 100644 --- a/src/bin/d2/tests/nc_add_unittests.cc +++ b/src/bin/d2/tests/nc_add_unittests.cc @@ -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); diff --git a/src/bin/d2/tests/nc_remove_unittests.cc b/src/bin/d2/tests/nc_remove_unittests.cc index 3889c7cbab..4373811f17 100644 --- a/src/bin/d2/tests/nc_remove_unittests.cc +++ b/src/bin/d2/tests/nc_remove_unittests.cc @@ -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); diff --git a/src/bin/d2/tests/simple_add_unittests.cc b/src/bin/d2/tests/simple_add_unittests.cc index 54bc7fabe5..c47a2b6f4b 100644 --- a/src/bin/d2/tests/simple_add_unittests.cc +++ b/src/bin/d2/tests/simple_add_unittests.cc @@ -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); diff --git a/src/bin/d2/tests/simple_remove_unittests.cc b/src/bin/d2/tests/simple_remove_unittests.cc index de74cc520c..1d53400fc9 100644 --- a/src/bin/d2/tests/simple_remove_unittests.cc +++ b/src/bin/d2/tests/simple_remove_unittests.cc @@ -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); diff --git a/src/lib/d2srv/nc_trans.cc b/src/lib/d2srv/nc_trans.cc index 32407e0437..e9534c256c 100644 --- a/src/lib/d2srv/nc_trans.cc +++ b/src/lib/d2srv/nc_trans.cc @@ -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; diff --git a/src/lib/d2srv/nc_trans.h b/src/lib/d2srv/nc_trans.h index cfbc9ec45c..2aee7eccfb 100644 --- a/src/lib/d2srv/nc_trans.h +++ b/src/lib/d2srv/nc_trans.h @@ -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. diff --git a/src/lib/d2srv/tests/nc_trans_unittests.cc b/src/lib/d2srv/tests/nc_trans_unittests.cc index e461a2aacf..89a23b7806 100644 --- a/src/lib/d2srv/tests/nc_trans_unittests.cc +++ b/src/lib/d2srv/tests/nc_trans_unittests.cc @@ -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