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 <kwiberg@webrtc.org>
Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30267}
diff --git a/rtc_base/cpu_time_unittest.cc b/rtc_base/cpu_time_unittest.cc
index 79f0a40..675e863 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 @@
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 @@
// 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