]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1434] fixed unittests
authorRazvan Becheriu <razvan@isc.org>
Fri, 16 Oct 2020 14:19:18 +0000 (17:19 +0300)
committerRazvan Becheriu <razvan@isc.org>
Thu, 22 Oct 2020 14:45:55 +0000 (17:45 +0300)
src/hooks/dhcp/lease_cmds/tests/lease_cmds_unittest.cc
src/lib/dhcpsrv/memfile_lease_mgr.cc

index 2cd36c87cc99b0aa4dcdc1cee7b774feb14a0255..e8053d364f05844cbd800fb26689b5292f9b9b00 100644 (file)
@@ -416,7 +416,9 @@ public:
         // Purposely using high cltt and valid lifetime to test that
         // expiration time is cast properly.
         lease->valid_lft_ = HIGH_VALID_LIFETIME; // Very high valid lifetime
+        lease->old_valid_lft_ = HIGH_VALID_LIFETIME; // Very high valid lifetime
         lease->cltt_ = DEC_2030_TIME; // December 11th 2030
+        lease->old_cltt_ = DEC_2030_TIME; // December 11th 2030
         if (declined) {
             lease->state_ = Lease::STATE_DECLINED;
         }
@@ -456,7 +458,9 @@ public:
         // Purposely using high cltt and valid lifetime to test that
         // expiration time is cast properly.
         lease->valid_lft_ = HIGH_VALID_LIFETIME; // Very high valid lifetime
+        lease->old_valid_lft_ = HIGH_VALID_LIFETIME; // Very high valid lifetime
         lease->cltt_ = DEC_2030_TIME; // December 11th 2030
+        lease->old_cltt_ = DEC_2030_TIME; // December 11th 2030
         if (declined) {
             lease->state_ = Lease::STATE_DECLINED;
         }
@@ -3646,7 +3650,9 @@ TEST_F(LeaseCmdsTest, Lease4UpdateNoLease) {
         "        \"hostname\": \"newhostname.example.org\""
         "    }\n"
         "}";
-    string exp_rsp = "failed to update the lease with address 192.0.2.1 - no such lease";
+    string exp_rsp = "failed to update the lease with address 192.0.2.1 "
+        "either because the lease has been deleted or it has changed in the "
+        "database, in both cases a retry might succeed";
     testCommand(txt, CONTROL_RESULT_ERROR, exp_rsp);
 }
 
@@ -3918,7 +3924,9 @@ TEST_F(LeaseCmdsTest, Lease4UpdateDoNotForceCreate) {
         "        \"force-create\": false"
         "    }\n"
         "}";
-    string exp_rsp = "failed to update the lease with address 192.0.2.1 - no such lease";
+    string exp_rsp = "failed to update the lease with address 192.0.2.1 "
+        "either because the lease has been deleted or it has changed in the "
+        "database, in both cases a retry might succeed";
     testCommand(txt, CONTROL_RESULT_ERROR, exp_rsp);
 
     checkLease4Stats(44, 0, 0);
@@ -4367,7 +4375,9 @@ TEST_F(LeaseCmdsTest, Lease6UpdateNoLease) {
         "        \"hostname\": \"newhostname.example.org\""
         "    }\n"
         "}";
-    string exp_rsp = "failed to update the lease with address 2001:db8:1::1 - no such lease";
+    string exp_rsp = "failed to update the lease with address 2001:db8:1::1 "
+        "either because the lease has been deleted or it has changed in the "
+        "database, in both cases a retry might succeed";
     testCommand(txt, CONTROL_RESULT_ERROR, exp_rsp);
 
     checkLease6Stats(66, 0, 0, 0);
@@ -4490,7 +4500,9 @@ TEST_F(LeaseCmdsTest, Lease6UpdateDoNotForceCreate) {
         "        \"force-create\": false"
         "    }\n"
         "}";
-    string exp_rsp = "failed to update the lease with address 2001:db8:1::1 - no such lease";
+    string exp_rsp = "failed to update the lease with address 2001:db8:1::1 "
+        "either because the lease has been deleted or it has changed in the "
+        "database, in both cases a retry might succeed";
     testCommand(txt, CONTROL_RESULT_ERROR, exp_rsp);
 
     checkLease6Stats(66, 0, 0, 0);
index ddbc9b4b412f645c1a1693377fc9e2b10c25ff6f..5227fcebed7e481a6cb6bafdc1188ba29276ec4a 100644 (file)
@@ -1416,8 +1416,8 @@ Memfile_LeaseMgr::updateLease4Internal(const Lease4Ptr& lease) {
     Lease4StorageAddressIndex::const_iterator lease_it = index.find(lease->addr_);
     if (lease_it == index.end()) {
         valid = false;
-    } else if ((!persist) && (((*lease_it)->old_cltt_ != lease->old_cltt_) ||
-        ((*lease_it)->old_valid_lft_ != lease->old_valid_lft_))) {
+    } else if ((!persist) && (((*lease_it)->cltt_ != lease->old_cltt_) ||
+        ((*lease_it)->valid_lft_ != lease->old_valid_lft_))) {
         valid = false;
     }
 
@@ -1462,8 +1462,8 @@ Memfile_LeaseMgr::updateLease6Internal(const Lease6Ptr& lease) {
     Lease6StorageAddressIndex::const_iterator lease_it = index.find(lease->addr_);
     if (lease_it == index.end()) {
         valid = false;
-    } else if ((!persist) && (((*lease_it)->old_cltt_ != lease->old_cltt_) ||
-        ((*lease_it)->old_valid_lft_ != lease->old_valid_lft_))) {
+    } else if ((!persist) && (((*lease_it)->cltt_ != lease->old_cltt_) ||
+        ((*lease_it)->valid_lft_ != lease->old_valid_lft_))) {
         valid = false;
     }
 
@@ -1513,10 +1513,10 @@ Memfile_LeaseMgr::deleteLeaseInternal(const Lease4Ptr& lease) {
             lease_copy.valid_lft_ = 0;
             lease_file4_->append(lease_copy);
         } else {
-            // for test purpose only to check that an actual database
+            // For test purpose only: check that an actual database
             // implementation action is atomic
-            if ((*l)->old_cltt_ != lease->old_cltt_ ||
-                (*l)->old_valid_lft_ != lease->old_valid_lft_) {
+            if ((*l)->cltt_ != lease->old_cltt_ ||
+                (*l)->valid_lft_ != lease->old_valid_lft_) {
                 return false;
             }
         }
@@ -1555,10 +1555,10 @@ Memfile_LeaseMgr::deleteLeaseInternal(const Lease6Ptr& lease) {
             lease_copy.preferred_lft_ = 0;
             lease_file6_->append(lease_copy);
         } else {
-            // for test purpose only to check that an actual database
+            // For test purpose only: check that an actual database
             // implementation action is atomic
-            if ((*l)->old_cltt_ != lease->old_cltt_ ||
-                (*l)->old_valid_lft_ != lease->old_valid_lft_) {
+            if ((*l)->cltt_ != lease->old_cltt_ ||
+                (*l)->valid_lft_ != lease->old_valid_lft_) {
                 return false;
             }
         }