Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Unified Diff: components/metrics/single_sample_metrics_factory_impl_unittest.cc

Issue 2894553004: Fix flakiness in MultithreadedMetrics test for single sample metrics. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/metrics/single_sample_metrics_factory_impl_unittest.cc
diff --git a/components/metrics/single_sample_metrics_factory_impl_unittest.cc b/components/metrics/single_sample_metrics_factory_impl_unittest.cc
index d87d3fd1ee6442b6253eab0544a517b567f57102..a649b5df789ea41639c72a3caf26ed369af2a850 100644
--- a/components/metrics/single_sample_metrics_factory_impl_unittest.cc
+++ b/components/metrics/single_sample_metrics_factory_impl_unittest.cc
@@ -34,19 +34,22 @@ class SingleSampleMetricsFactoryImplTest : public testing::Test {
~SingleSampleMetricsFactoryImplTest() override {
factory_->DestroyProviderForTesting();
- if (thread_.IsRunning()) {
- thread_.task_runner()->PostTask(
- FROM_HERE,
- base::Bind(&SingleSampleMetricsFactoryImpl::DestroyProviderForTesting,
- base::Unretained(factory_)));
- thread_.Stop();
- }
+ if (thread_.IsRunning())
+ ShutdownThread();
base::SingleSampleMetricsFactory::DeleteFactoryForTesting();
}
protected:
void StartThread() { ASSERT_TRUE(thread_.Start()); }
+ void ShutdownThread() {
+ thread_.task_runner()->PostTask(
+ FROM_HERE,
+ base::Bind(&SingleSampleMetricsFactoryImpl::DestroyProviderForTesting,
+ base::Unretained(factory_)));
+ thread_.Stop();
Ilya Sherman 2017/05/19 00:12:41 I'm honestly a bit confused: I'd expect PostTask()
DaleCurtis 2017/05/19 00:13:29 Thread::Stop() joins, so all posted tasks are wait
Ilya Sherman 2017/05/19 00:18:55 Ah, great! =) LGTM in that case -- thanks!
+ }
+
void CreateProvider(mojom::SingleSampleMetricsProviderRequest request) {
CreateSingleSampleMetricsProvider(service_manager::BindSourceInfo(),
std::move(request));
@@ -131,13 +134,7 @@ TEST_F(SingleSampleMetricsFactoryImplTest, DefaultSingleSampleMetricWithValue) {
base::HistogramBase::kUmaTargetedHistogramFlag));
}
-// Flaky on Android N5X builders. https://crbug.com/719497
-#if defined(OS_ANDROID)
-#define MAYBE_MultithreadedMetrics DISABLED_MultithreadedMetrics
-#else
-#define MAYBE_MultithreadedMetrics MultithreadedMetrics
-#endif
-TEST_F(SingleSampleMetricsFactoryImplTest, MAYBE_MultithreadedMetrics) {
+TEST_F(SingleSampleMetricsFactoryImplTest, MultithreadedMetrics) {
base::HistogramTester tester;
std::unique_ptr<base::SingleSampleMetric> metric =
factory_->CreateCustomCountsMetric(kMetricName, kMin, kMax, kBucketCount);
@@ -171,18 +168,13 @@ TEST_F(SingleSampleMetricsFactoryImplTest, MAYBE_MultithreadedMetrics) {
run_loop.Run();
}
- // Release metrics and cycle threads to ensure destruction completes.
- {
- thread_.task_runner()->DeleteSoon(FROM_HERE, threaded_metric.release());
-
- base::RunLoop run_loop;
- thread_.task_runner()->PostTaskAndReply(
- FROM_HERE, base::Bind(&base::DoNothing), run_loop.QuitClosure());
- run_loop.Run();
- }
+ // Release metrics and shutdown thread to ensure destruction completes.
+ thread_.task_runner()->DeleteSoon(FROM_HERE, threaded_metric.release());
+ ShutdownThread();
metric.reset();
base::RunLoop().RunUntilIdle();
+
tester.ExpectUniqueSample(kMetricName, kSample, 2);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698