Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Unified Diff: webrtc/system_wrappers/source/clock_unittest.cc

Issue 2393063002: Fixed flaky clock_unittest by using relative comparison. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/system_wrappers/source/clock_unittest.cc
diff --git a/webrtc/system_wrappers/source/clock_unittest.cc b/webrtc/system_wrappers/source/clock_unittest.cc
index 76507ce3f340c9ca4396073f46d40666de4be218..5010d37c18a8e75a8765f0a46d020644bfdbce36 100644
--- a/webrtc/system_wrappers/source/clock_unittest.cc
+++ b/webrtc/system_wrappers/source/clock_unittest.cc
@@ -18,11 +18,19 @@ TEST(ClockTest, NtpTime) {
Clock* clock = Clock::GetRealTimeClock();
uint32_t seconds;
uint32_t fractions;
+
+ // To ensure the test runs correctly even on a heavily loaded system, do not
+ // compare the seconds/fractions and millisecond values directly. Instead,
+ // we check that the NTP time is between the "milliseconds" values returned
+ // right before and right after the call.
+ // The comparison includes 1 ms of margin to account for the rounding error in
+ // the conversion.
+ int64_t milliseconds_lower_bound = clock->CurrentNtpInMilliseconds();
clock->CurrentNtp(seconds, fractions);
- int64_t milliseconds = clock->CurrentNtpInMilliseconds();
- EXPECT_GT(milliseconds / 1000, kNtpJan1970);
- EXPECT_GE(milliseconds, Clock::NtpToMs(seconds, fractions));
- EXPECT_NEAR(milliseconds, Clock::NtpToMs(seconds, fractions), 100);
+ int64_t milliseconds_upper_bound = clock->CurrentNtpInMilliseconds();
+ EXPECT_GT(milliseconds_lower_bound / 1000, kNtpJan1970);
+ EXPECT_LE(milliseconds_lower_bound - 1, Clock::NtpToMs(seconds, fractions));
+ EXPECT_GE(milliseconds_upper_bound + 1, Clock::NtpToMs(seconds, fractions));
}
} // namespace webrtc
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698