0

content/android: Attempt to deflake CpuTimeMetricsTests

Looks like these tests were flaky because the visibility changed signal
now propagates asynchronously via the thread pool. Deflake this by
waiting for the thread pool tasks to execute before and after changing
the visibility state.

Bug: 1210898
Change-Id: Ic52f2300c6b84f3e51309372b05565f99395b34b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2910421
Commit-Queue: Eric Seckler <eseckler@chromium.org>
Commit-Queue: Bo <boliu@chromium.org>
Auto-Submit: Eric Seckler <eseckler@chromium.org>
Reviewed-by: Bo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#885025}
This commit is contained in:
Eric Seckler
2021-05-20 14:50:12 +00:00
committed by Chromium LUCI CQ
parent f5ec819509
commit 6e5dcfcdf1

@ -43,10 +43,12 @@ TEST(CpuTimeMetricsTest, RecordsMetricsForeground) {
ProcessCpuTimeMetrics::SetIgnoreHistogramAllocatorForTesting(true);
std::unique_ptr<ProcessCpuTimeMetrics> metrics =
ProcessCpuTimeMetrics::CreateForTesting();
metrics->WaitForCollectionForTesting();
// Start out in the foreground and spend one CPU second there.
// This will also set the current power mode to 'idle'.
ProcessVisibilityTracker::GetInstance()->OnProcessVisibilityChanged(true);
metrics->WaitForCollectionForTesting();
thread1.task_runner()->PostTask(
FROM_HERE, BindOnce(&WorkForOneCpuSec, base::Unretained(&event)));
@ -115,9 +117,11 @@ TEST(CpuTimeMetricsTest, RecordsMetricsBackground) {
ProcessCpuTimeMetrics::SetIgnoreHistogramAllocatorForTesting(true);
std::unique_ptr<ProcessCpuTimeMetrics> metrics =
ProcessCpuTimeMetrics::CreateForTesting();
metrics->WaitForCollectionForTesting();
// Start out in the background and spend one CPU second there.
ProcessVisibilityTracker::GetInstance()->OnProcessVisibilityChanged(false);
metrics->WaitForCollectionForTesting();
thread1.task_runner()->PostTask(
FROM_HERE, BindOnce(&WorkForOneCpuSec, base::Unretained(&event)));