]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3163] relax time-senstitive tests in dhcp[46]
authorAndrei Pavel <andrei@isc.org>
Mon, 29 Apr 2024 12:19:13 +0000 (15:19 +0300)
committerAndrei Pavel <andrei@isc.org>
Wed, 1 May 2024 10:23:17 +0000 (13:23 +0300)
src/bin/dhcp4/tests/dhcp4_srv_unittest.cc
src/bin/dhcp6/tests/dhcp6_srv_unittest.cc

index 389f393eb4dcfb29dd106fe7ad55a983869bd9fb..96ee7249b74d87c491f6517bf6b2f78a62157e63 100644 (file)
@@ -48,7 +48,6 @@
 
 #include <iostream>
 #include <cstdlib>
-#include <sstream>
 
 #include <arpa/inet.h>
 #include <dirent.h>
@@ -1892,8 +1891,7 @@ TEST_F(Dhcpv4SrvTest, DiscoverCache) {
     OptionUint32Ptr opt = boost::dynamic_pointer_cast<
         OptionUint32>(offer->getOption(DHO_DHCP_LEASE_TIME));
     ASSERT_TRUE(opt);
-    EXPECT_GE(subnet_->getValid() - delta, opt->getValue());
-    EXPECT_LE(subnet_->getValid() - delta - 10, opt->getValue());
+    EXPECT_EQ_MARGIN(subnet_->getValid() - delta, opt->getValue(), 1);
 
     // Check address
     EXPECT_EQ(addr, offer->getYiaddr());
@@ -2074,7 +2072,7 @@ TEST_F(Dhcpv4SrvTest, RenewBasic) {
     int32_t cltt = static_cast<int32_t>(l->cltt_);
     int32_t expected = static_cast<int32_t>(time(NULL));
     // Equality or difference by 1 between cltt and expected is ok.
-    EXPECT_GE(1, abs(cltt - expected));
+    EXPECT_EQ_MARGIN(cltt, expected, 1);
 
     Lease4Ptr lease = LeaseMgrFactory::instance().getLease4(addr);
     EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(lease));
@@ -2197,7 +2195,7 @@ TEST_F(Dhcpv4SrvTest, RenewDefaultLifetime) {
     int32_t cltt = static_cast<int32_t>(c.l->cltt_);
     int32_t expected = static_cast<int32_t>(time(NULL));
     // Equality or difference by 1 between cltt and expected is ok.
-    EXPECT_GE(1, abs(cltt - expected));
+    EXPECT_EQ_MARGIN(cltt, expected, 1);
 
     Lease4Ptr lease = LeaseMgrFactory::instance().getLease4(c.addr);
     EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(lease));
@@ -2243,7 +2241,7 @@ TEST_F(Dhcpv4SrvTest, RenewHintLifetime) {
     int32_t cltt = static_cast<int32_t>(c.l->cltt_);
     int32_t expected = static_cast<int32_t>(time(NULL));
     // Equality or difference by 1 between cltt and expected is ok.
-    EXPECT_GE(1, abs(cltt - expected));
+    EXPECT_EQ_MARGIN(cltt, expected, 1);
 
     Lease4Ptr lease = LeaseMgrFactory::instance().getLease4(c.addr);
     EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(lease));
@@ -2289,7 +2287,7 @@ TEST_F(Dhcpv4SrvTest, RenewMinLifetime) {
     int32_t cltt = static_cast<int32_t>(c.l->cltt_);
     int32_t expected = static_cast<int32_t>(time(NULL));
     // Equality or difference by 1 between cltt and expected is ok.
-    EXPECT_GE(1, abs(cltt - expected));
+    EXPECT_EQ_MARGIN(cltt, expected, 1);
 
     Lease4Ptr lease = LeaseMgrFactory::instance().getLease4(c.addr);
     EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(lease));
@@ -2334,7 +2332,7 @@ TEST_F(Dhcpv4SrvTest, RenewMaxLifetime) {
     int32_t cltt = static_cast<int32_t>(c.l->cltt_);
     int32_t expected = static_cast<int32_t>(time(NULL));
     // Equality or difference by 1 between cltt and expected is ok.
-    EXPECT_GE(1, abs(cltt - expected));
+    EXPECT_EQ_MARGIN(cltt, expected, 1);
 
     Lease4Ptr lease = LeaseMgrFactory::instance().getLease4(c.addr);
     EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(lease));
@@ -2402,8 +2400,7 @@ TEST_F(Dhcpv4SrvTest, RenewCache) {
     OptionUint32Ptr opt = boost::dynamic_pointer_cast<
         OptionUint32>(ack->getOption(DHO_DHCP_LEASE_TIME));
     ASSERT_TRUE(opt);
-    EXPECT_GE(subnet_->getValid() - delta, opt->getValue());
-    EXPECT_LE(subnet_->getValid() - delta - 10, opt->getValue());
+    EXPECT_EQ_MARGIN(subnet_->getValid() - delta, opt->getValue(), 1);
 
     // Check address
     EXPECT_EQ(addr, ack->getYiaddr());
index b52149342e84fef1b9a85ff1d778bd11501017b2..5577e44259c28b9bf6e7b338db23a28569157c1b 100644 (file)
@@ -48,9 +48,7 @@
 #include <boost/pointer_cast.hpp>
 #include <boost/scoped_ptr.hpp>
 
-#include <fstream>
 #include <iostream>
-#include <sstream>
 
 #include <dirent.h>
 #include <unistd.h>
@@ -1706,8 +1704,11 @@ TEST_F(Dhcpv6SrvTest, RequestCache) {
 
     // Check the address.
     EXPECT_EQ(addr, iaaddr->getAddress());
-    EXPECT_EQ(pref - delta, iaaddr->getPreferred());
-    EXPECT_EQ(valid - delta, iaaddr->getValid());
+
+    // Since the initial time values were set, one second could have ticked,
+    // so allow one second of margin error.
+    EXPECT_EQ_MARGIN(pref - delta, iaaddr->getPreferred(), 1);
+    EXPECT_EQ_MARGIN(valid - delta, iaaddr->getValid(), 1);
 
     // check DUIDs
     checkServerId(reply, srv.getServerID());
@@ -1781,8 +1782,8 @@ TEST_F(Dhcpv6SrvTest, pdRequestCache) {
     // Check the prefix.
     EXPECT_EQ(prefix, iapref->getAddress());
     EXPECT_EQ(prefixlen, iapref->getLength());
-    EXPECT_EQ(pref - delta, iapref->getPreferred());
-    EXPECT_EQ(valid - delta, iapref->getValid());
+    EXPECT_EQ_MARGIN(pref - delta, iapref->getPreferred(), 1);
+    EXPECT_EQ_MARGIN(valid - delta, iapref->getValid(), 1);
 
     // check DUIDs
     checkServerId(reply, srv.getServerID());
@@ -1996,8 +1997,8 @@ TEST_F(Dhcpv6SrvTest, RenewCache) {
 
     // Check the address.
     EXPECT_EQ(addr, iaaddr->getAddress());
-    EXPECT_EQ(pref - delta, iaaddr->getPreferred());
-    EXPECT_EQ(valid - delta, iaaddr->getValid());
+    EXPECT_EQ_MARGIN(pref - delta, iaaddr->getPreferred(), 1);
+    EXPECT_EQ_MARGIN(valid - delta, iaaddr->getValid(), 1);
 
     // check DUIDs
     checkServerId(reply, srv.getServerID());
@@ -2071,8 +2072,8 @@ TEST_F(Dhcpv6SrvTest, pdRenewCache) {
     // Check the prefix.
     EXPECT_EQ(prefix, iapref->getAddress());
     EXPECT_EQ(prefixlen, iapref->getLength());
-    EXPECT_EQ(pref - delta, iapref->getPreferred());
-    EXPECT_EQ(valid - delta, iapref->getValid());
+    EXPECT_EQ_MARGIN(pref - delta, iapref->getPreferred(), 1);
+    EXPECT_EQ_MARGIN(valid - delta, iapref->getValid(), 1);
 
     // check DUIDs
     checkServerId(reply, srv.getServerID());