Skip to content

Commit af91168

Browse files
committed
[#3163] relax time-senstitive tests in dhcp[46]
1 parent e82ee81 commit af91168

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

src/bin/dhcp4/tests/dhcp4_srv_unittest.cc

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848

4949
#include <iostream>
5050
#include <cstdlib>
51-
#include <sstream>
5251

5352
#include <arpa/inet.h>
5453
#include <dirent.h>
@@ -1892,8 +1891,7 @@ TEST_F(Dhcpv4SrvTest, DiscoverCache) {
18921891
OptionUint32Ptr opt = boost::dynamic_pointer_cast<
18931892
OptionUint32>(offer->getOption(DHO_DHCP_LEASE_TIME));
18941893
ASSERT_TRUE(opt);
1895-
EXPECT_GE(subnet_->getValid() - delta, opt->getValue());
1896-
EXPECT_LE(subnet_->getValid() - delta - 10, opt->getValue());
1894+
EXPECT_EQ_MARGIN(subnet_->getValid() - delta, opt->getValue(), 1);
18971895

18981896
// Check address
18991897
EXPECT_EQ(addr, offer->getYiaddr());
@@ -2074,7 +2072,7 @@ TEST_F(Dhcpv4SrvTest, RenewBasic) {
20742072
int32_t cltt = static_cast<int32_t>(l->cltt_);
20752073
int32_t expected = static_cast<int32_t>(time(NULL));
20762074
// Equality or difference by 1 between cltt and expected is ok.
2077-
EXPECT_GE(1, abs(cltt - expected));
2075+
EXPECT_EQ_MARGIN(cltt, expected, 1);
20782076

20792077
Lease4Ptr lease = LeaseMgrFactory::instance().getLease4(addr);
20802078
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(lease));
@@ -2197,7 +2195,7 @@ TEST_F(Dhcpv4SrvTest, RenewDefaultLifetime) {
21972195
int32_t cltt = static_cast<int32_t>(c.l->cltt_);
21982196
int32_t expected = static_cast<int32_t>(time(NULL));
21992197
// Equality or difference by 1 between cltt and expected is ok.
2200-
EXPECT_GE(1, abs(cltt - expected));
2198+
EXPECT_EQ_MARGIN(cltt, expected, 1);
22012199

22022200
Lease4Ptr lease = LeaseMgrFactory::instance().getLease4(c.addr);
22032201
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(lease));
@@ -2243,7 +2241,7 @@ TEST_F(Dhcpv4SrvTest, RenewHintLifetime) {
22432241
int32_t cltt = static_cast<int32_t>(c.l->cltt_);
22442242
int32_t expected = static_cast<int32_t>(time(NULL));
22452243
// Equality or difference by 1 between cltt and expected is ok.
2246-
EXPECT_GE(1, abs(cltt - expected));
2244+
EXPECT_EQ_MARGIN(cltt, expected, 1);
22472245

22482246
Lease4Ptr lease = LeaseMgrFactory::instance().getLease4(c.addr);
22492247
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(lease));
@@ -2289,7 +2287,7 @@ TEST_F(Dhcpv4SrvTest, RenewMinLifetime) {
22892287
int32_t cltt = static_cast<int32_t>(c.l->cltt_);
22902288
int32_t expected = static_cast<int32_t>(time(NULL));
22912289
// Equality or difference by 1 between cltt and expected is ok.
2292-
EXPECT_GE(1, abs(cltt - expected));
2290+
EXPECT_EQ_MARGIN(cltt, expected, 1);
22932291

22942292
Lease4Ptr lease = LeaseMgrFactory::instance().getLease4(c.addr);
22952293
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(lease));
@@ -2334,7 +2332,7 @@ TEST_F(Dhcpv4SrvTest, RenewMaxLifetime) {
23342332
int32_t cltt = static_cast<int32_t>(c.l->cltt_);
23352333
int32_t expected = static_cast<int32_t>(time(NULL));
23362334
// Equality or difference by 1 between cltt and expected is ok.
2337-
EXPECT_GE(1, abs(cltt - expected));
2335+
EXPECT_EQ_MARGIN(cltt, expected, 1);
23382336

23392337
Lease4Ptr lease = LeaseMgrFactory::instance().getLease4(c.addr);
23402338
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(lease));
@@ -2402,8 +2400,7 @@ TEST_F(Dhcpv4SrvTest, RenewCache) {
24022400
OptionUint32Ptr opt = boost::dynamic_pointer_cast<
24032401
OptionUint32>(ack->getOption(DHO_DHCP_LEASE_TIME));
24042402
ASSERT_TRUE(opt);
2405-
EXPECT_GE(subnet_->getValid() - delta, opt->getValue());
2406-
EXPECT_LE(subnet_->getValid() - delta - 10, opt->getValue());
2403+
EXPECT_EQ_MARGIN(subnet_->getValid() - delta, opt->getValue(), 1);
24072404

24082405
// Check address
24092406
EXPECT_EQ(addr, ack->getYiaddr());

src/bin/dhcp6/tests/dhcp6_srv_unittest.cc

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@
4848
#include <boost/pointer_cast.hpp>
4949
#include <boost/scoped_ptr.hpp>
5050

51-
#include <fstream>
5251
#include <iostream>
53-
#include <sstream>
5452

5553
#include <dirent.h>
5654
#include <unistd.h>
@@ -1706,8 +1704,11 @@ TEST_F(Dhcpv6SrvTest, RequestCache) {
17061704

17071705
// Check the address.
17081706
EXPECT_EQ(addr, iaaddr->getAddress());
1709-
EXPECT_EQ(pref - delta, iaaddr->getPreferred());
1710-
EXPECT_EQ(valid - delta, iaaddr->getValid());
1707+
1708+
// Since the initial time values were set, one second could have ticked,
1709+
// so allow one second of margin error.
1710+
EXPECT_EQ_MARGIN(pref - delta, iaaddr->getPreferred(), 1);
1711+
EXPECT_EQ_MARGIN(valid - delta, iaaddr->getValid(), 1);
17111712

17121713
// check DUIDs
17131714
checkServerId(reply, srv.getServerID());
@@ -1781,8 +1782,8 @@ TEST_F(Dhcpv6SrvTest, pdRequestCache) {
17811782
// Check the prefix.
17821783
EXPECT_EQ(prefix, iapref->getAddress());
17831784
EXPECT_EQ(prefixlen, iapref->getLength());
1784-
EXPECT_EQ(pref - delta, iapref->getPreferred());
1785-
EXPECT_EQ(valid - delta, iapref->getValid());
1785+
EXPECT_EQ_MARGIN(pref - delta, iapref->getPreferred(), 1);
1786+
EXPECT_EQ_MARGIN(valid - delta, iapref->getValid(), 1);
17861787

17871788
// check DUIDs
17881789
checkServerId(reply, srv.getServerID());
@@ -1996,8 +1997,8 @@ TEST_F(Dhcpv6SrvTest, RenewCache) {
19961997

19971998
// Check the address.
19981999
EXPECT_EQ(addr, iaaddr->getAddress());
1999-
EXPECT_EQ(pref - delta, iaaddr->getPreferred());
2000-
EXPECT_EQ(valid - delta, iaaddr->getValid());
2000+
EXPECT_EQ_MARGIN(pref - delta, iaaddr->getPreferred(), 1);
2001+
EXPECT_EQ_MARGIN(valid - delta, iaaddr->getValid(), 1);
20012002

20022003
// check DUIDs
20032004
checkServerId(reply, srv.getServerID());
@@ -2071,8 +2072,8 @@ TEST_F(Dhcpv6SrvTest, pdRenewCache) {
20712072
// Check the prefix.
20722073
EXPECT_EQ(prefix, iapref->getAddress());
20732074
EXPECT_EQ(prefixlen, iapref->getLength());
2074-
EXPECT_EQ(pref - delta, iapref->getPreferred());
2075-
EXPECT_EQ(valid - delta, iapref->getValid());
2075+
EXPECT_EQ_MARGIN(pref - delta, iapref->getPreferred(), 1);
2076+
EXPECT_EQ_MARGIN(valid - delta, iapref->getValid(), 1);
20762077

20772078
// check DUIDs
20782079
checkServerId(reply, srv.getServerID());

0 commit comments

Comments
 (0)