From: Marcin Siodelski Date: Mon, 17 Sep 2012 17:38:35 +0000 (+0200) Subject: [master] Adding timeout tolerance to receiveX() timeout checks. X-Git-Tag: trac2351_base~70^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8a6f971934a55f86df87c8dc7996d50b2ace0111;p=thirdparty%2Fkea.git [master] Adding timeout tolerance to receiveX() timeout checks. --- diff --git a/src/lib/dhcp/tests/iface_mgr_unittest.cc b/src/lib/dhcp/tests/iface_mgr_unittest.cc index 8db8706bec..3bf5ca4450 100644 --- a/src/lib/dhcp/tests/iface_mgr_unittest.cc +++ b/src/lib/dhcp/tests/iface_mgr_unittest.cc @@ -42,6 +42,13 @@ char LOOPBACK[BUF_SIZE] = "lo"; const uint16_t PORT1 = 10547; // V6 socket const uint16_t PORT2 = 10548; // V4 socket +// On some systems measured duration of receive6() and +// receive4() appears to be shorter than select() timeout. +// called by these functions. This may be the case +// if different ime resolutions are used by these functions. +// For such cases we set the tolerance of 0.01s. +const uint32_t TIMEOUT_TOLERANCE = 10000; + class NakedIfaceMgr: public IfaceMgr { // "naked" Interface Manager, exposes internal fields @@ -250,7 +257,8 @@ TEST_F(IfaceMgrTest, receiveTimeout6) { // precisely reflect the receive timeout. However the // uncertainity should be low enough to expect that measured // value is in the range <1.4s; 1.7s>. - EXPECT_GE(duration.total_microseconds(), 1400000); + EXPECT_GE(duration.total_microseconds(), + 1400000 - TIMEOUT_TOLERANCE); EXPECT_LE(duration.total_microseconds(), 1700000); // Test timeout shorter than 1s. @@ -260,7 +268,8 @@ TEST_F(IfaceMgrTest, receiveTimeout6) { ASSERT_FALSE(pkt); duration = stop_time - start_time; // Check if measured duration is within <0.5s; 0.8s>. - EXPECT_GE(duration.total_microseconds(), 500000); + EXPECT_GE(duration.total_microseconds(), + 500000 - TIMEOUT_TOLERANCE); EXPECT_LE(duration.total_microseconds(), 800000); // Test with invalid fractional timeout values. @@ -300,7 +309,8 @@ TEST_F(IfaceMgrTest, receiveTimeout4) { // precisely reflect the receive timeout. However the // uncertainity should be low enough to expect that measured // value is in the range <2.3s; 2.6s>. - EXPECT_GE(duration.total_microseconds(), 2300000); + EXPECT_GE(duration.total_microseconds(), + 2300000 - TIMEOUT_TOLERANCE); EXPECT_LE(duration.total_microseconds(), 2600000); // Test timeout shorter than 1s. @@ -310,7 +320,8 @@ TEST_F(IfaceMgrTest, receiveTimeout4) { ASSERT_FALSE(pkt); duration = stop_time - start_time; // Check if measured duration is within <0.4s; 0.7s>. - EXPECT_GE(duration.total_microseconds(), 400000); + EXPECT_GE(duration.total_microseconds(), + 400000 - TIMEOUT_TOLERANCE); EXPECT_LE(duration.total_microseconds(), 700000); // Test with invalid fractional timeout values.