From 7787ebcd3fef9f007dabbfc2228089a1060a3d73 Mon Sep 17 00:00:00 2001 From: Ilya Nikolaevskiy Date: Tue, 14 Jan 2020 10:25:30 +0100 Subject: [PATCH] Deflake CpuTimeTest.TwoThreads The test sometimes failed because thread creation on some platforms on internal tests may take too much work. Now checks are less strict. Bug: none Change-Id: Ibd3df02bda26b0c5e804360a909c61afa760b3bc Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/165960 Reviewed-by: Karl Wiberg Commit-Queue: Ilya Nikolaevskiy Cr-Commit-Position: refs/heads/master@{#30267} --- rtc_base/cpu_time_unittest.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/rtc_base/cpu_time_unittest.cc b/rtc_base/cpu_time_unittest.cc index 79f0a4036f..675e86307c 100644 --- a/rtc_base/cpu_time_unittest.cc +++ b/rtc_base/cpu_time_unittest.cc @@ -26,7 +26,7 @@ namespace { const int kAllowedErrorMillisecs = 30; -const int kProcessingTimeMillisecs = 300; +const int kProcessingTimeMillisecs = 500; const int kWorkingThreads = 2; // Consumes approximately kProcessingTimeMillisecs of CPU time in single thread. @@ -77,10 +77,11 @@ TEST(CpuTimeTest, MAYBE_TEST(TwoThreads)) { GetProcessCpuTimeNanos() - process_start_time_nanos; int64_t thread_duration_nanos = GetThreadCpuTimeNanos() - thread_start_time_nanos; - // This thread did almost nothing. + // This thread did almost nothing. Definetly less work than kProcessingTime. // Therefore GetThreadCpuTime is not a wall clock. EXPECT_LE(thread_duration_nanos, - kAllowedErrorMillisecs * kNumNanosecsPerMillisec); + (kProcessingTimeMillisecs - kAllowedErrorMillisecs) * + kNumNanosecsPerMillisec); // Total process time is at least twice working threads' CPU time. // Therefore process and thread times are correctly related. EXPECT_GE(process_duration_nanos, @@ -97,7 +98,8 @@ TEST(CpuTimeTest, MAYBE_TEST(Sleeping)) { // Sleeping should not introduce any additional CPU time. // Therefore GetProcessCpuTime is not a wall clock. EXPECT_LE(process_duration_nanos, - kWorkingThreads * kAllowedErrorMillisecs * kNumNanosecsPerMillisec); + (kProcessingTimeMillisecs - kAllowedErrorMillisecs) * + kNumNanosecsPerMillisec); } } // namespace rtc