Commit c41d9d21 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Fix test flakiness due to race condition.

StartMonitoring() starts the thread asynchronously, which it must do
since it happens on the UI thread and cannot block.  However, the test
checks that the tid() is set immediately, which is only valid once the
thread starts up.  This race leads to test flakiness.

We could busy-loop waiting for the thread to start, or use a condition
variable, or do various other fixes to ensure that we don't access the
tid() until it's really there; but since the test is basically trying
to ensure that a second call to StartMonitoring() is a no-op, this just
checks that the thread* is non-null and unchanged between the two calls.
This is sufficient and should work consistently.

Bug: none
Change-Id: I672e229ce07d84d04a7cd0aa2eb498a9d903d5cb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2117053
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Cheng-Yu Lee <cylee@chromium.org>
Reviewed-by: default avatarCheng-Yu Lee <cylee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#753129}
parent bef5f5ce
......@@ -158,12 +158,13 @@ TEST_F(MemoryKillsMonitorTest, TestHistograms) {
}
// Call StartMonitoring multiple times.
base::PlatformThreadId tid1 = g_memory_kills_monitor_unittest_instance
->non_joinable_worker_thread_->tid();
base::DelegateSimpleThread* thread1 = g_memory_kills_monitor_unittest_instance
->non_joinable_worker_thread_.get();
EXPECT_NE(nullptr, thread1);
g_memory_kills_monitor_unittest_instance->StartMonitoring();
base::PlatformThreadId tid2 = g_memory_kills_monitor_unittest_instance
->non_joinable_worker_thread_->tid();
EXPECT_EQ(tid1, tid2);
base::DelegateSimpleThread* thread2 = g_memory_kills_monitor_unittest_instance
->non_joinable_worker_thread_.get();
EXPECT_EQ(thread1, thread2);
lmk_count_histogram = GetLowMemoryKillsCountHistogram();
ASSERT_TRUE(lmk_count_histogram);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment