aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAliaksey Kandratsenka <alkondratenko@gmail.com>2024-08-18 15:52:59 -0400
committerAliaksey Kandratsenka <alkondratenko@gmail.com>2024-08-18 15:56:17 -0400
commitae15d7a490eff0cd93fbbcfa89469f672e0ec7cd (patch)
treeef82ff78a83dee19bd5b53e5936846f3c2db2995
parent2e0b81852ed36ad872548e4664a8c3df5e0ce27b (diff)
downloadgoogle-perftools-ae15d7a490eff0cd93fbbcfa89469f672e0ec7cd.tar.gz
google-perftools-ae15d7a490eff0cd93fbbcfa89469f672e0ec7cd.zip
fix spurious rare failures in profile handler unittest
It's method of verifying that cpu profiling ticks happens is inherently brittle. It sleeps certain time and then checks if ticks happened during that time. And sleeping is by wall clock time. But due to cpu scheduling being unpredictable, it is not impossible to see no ticks even waiting 200 ms. We improve the issue by having the code loop a bit until it seeks ticks happen.
-rw-r--r--src/tests/profile-handler_unittest.cc15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/tests/profile-handler_unittest.cc b/src/tests/profile-handler_unittest.cc
index 0bc2594..148ec4a 100644
--- a/src/tests/profile-handler_unittest.cc
+++ b/src/tests/profile-handler_unittest.cc
@@ -272,10 +272,21 @@ class ProfileHandlerTest : public ::testing::Test {
uint64_t interrupts_before = GetInterruptCount();
// Sleep for a bit and check that tick counter is making progress.
int old_tick_count = tick_counter;
+ int new_tick_count;
+ uint64_t interrupts_after;
Delay(kSleepInterval);
- int new_tick_count = tick_counter;
- uint64_t interrupts_after = GetInterruptCount();
if (FLAGS_test_profiler_enabled) {
+ // The "sleep" check we do here is somewhat inherently
+ // brittle. But we can repeat waiting a bit more to ensure that
+ // ticks do occur.
+ for (int i = 10; i > 0; i--) {
+ new_tick_count = tick_counter;
+ interrupts_after = GetInterruptCount();
+ if (new_tick_count > old_tick_count && interrupts_after > interrupts_before) {
+ break;
+ }
+ Delay(kSleepInterval);
+ }
EXPECT_GT(new_tick_count, old_tick_count);
EXPECT_GT(interrupts_after, interrupts_before);
} else {