Chromium Code Reviews| Index: base/task_scheduler/scheduler_worker_pool_impl_unittest.cc |
| diff --git a/base/task_scheduler/scheduler_worker_pool_impl_unittest.cc b/base/task_scheduler/scheduler_worker_pool_impl_unittest.cc |
| index 0f8475a69051fc7f56a1d5d3f3feb1d4a6a75f39..5ec2942eb84751507c2f0147068dc0dd65c4234c 100644 |
| --- a/base/task_scheduler/scheduler_worker_pool_impl_unittest.cc |
| +++ b/base/task_scheduler/scheduler_worker_pool_impl_unittest.cc |
| @@ -593,7 +593,10 @@ class TaskSchedulerWorkerPoolHistogramTest |
| protected: |
| void SetUp() override {} |
| - void TearDown() override { worker_pool_->JoinForTesting(); } |
| + void TearDown() override { |
| + if (worker_pool_) |
|
robliao
2016/10/13 18:04:04
Mention that worker pool initialization is handled
fdoray
2016/10/13 20:38:53
Done
|
| + worker_pool_->JoinForTesting(); |
| + } |
| private: |
| std::unique_ptr<StatisticsRecorder> statistics_recorder_ = |
| @@ -723,5 +726,44 @@ TEST_F(TaskSchedulerWorkerPoolHistogramTest, NumTasksBetweenWaitsWithDetach) { |
| worker_pool_->DisallowWorkerDetachmentForTesting(); |
| } |
| +TEST_F(TaskSchedulerWorkerPoolHistogramTest, NumTasksBeforeDetach) { |
| + InitializeWorkerPool(kReclaimTimeForDetachTests, kNumWorkersInWorkerPool); |
| + auto task_runner = worker_pool_->CreateTaskRunnerWithTraits( |
| + TaskTraits(), ExecutionMode::SINGLE_THREADED); |
| + auto other_task_runner = worker_pool_->CreateTaskRunnerWithTraits( |
| + TaskTraits(), ExecutionMode::SINGLE_THREADED); |
| + |
| + // Post 3 tasks and wait until they run. |
| + task_runner->PostTask(FROM_HERE, Bind(&DoNothing)); |
| + task_runner->PostTask(FROM_HERE, Bind(&DoNothing)); |
| + task_runner->PostTask(FROM_HERE, Bind(&DoNothing)); |
| + worker_pool_->WaitForAllWorkersIdleForTesting(); |
| + |
| + // To allow the SchedulerWorker associated with |task_runner| to detach: |
| + // - Make sure it isn't on top of the idle stack by waking up another |
| + // SchedulerWorker. |
| + // - Release |task_runner|. |
| + other_task_runner->PostTask(FROM_HERE, Bind(&DoNothing)); |
| + task_runner = nullptr; |
| + |
| + // Allow the SchedulerWorker to detach. |
| + PlatformThread::Sleep(kReclaimTimeForDetachTests + kExtraTimeToWaitForDetach); |
| + |
| + // Join the SchedulerWorkerPool. This forces SchedulerWorkers that detached |
| + // during the test to record to the histogram. |
| + worker_pool_->WaitForAllWorkersIdleForTesting(); |
| + worker_pool_->DisallowWorkerDetachmentForTesting(); |
| + worker_pool_->JoinForTesting(); |
| + const auto* histogram = |
| + worker_pool_->num_tasks_before_detach_histogram_for_testing(); |
| + other_task_runner = nullptr; |
| + worker_pool_.reset(); |
| + |
| + // Verify that counts were recorded to the histogram as expected. |
| + EXPECT_EQ(0, histogram->SnapshotSamples()->GetCount(0)); |
| + EXPECT_EQ(1, histogram->SnapshotSamples()->GetCount(3)); |
| + EXPECT_EQ(0, histogram->SnapshotSamples()->GetCount(10)); |
| +} |
| + |
| } // namespace internal |
| } // namespace base |