Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/task_scheduler/scheduler_worker_pool_impl.h" | 5 #include "base/task_scheduler/scheduler_worker_pool_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <unordered_set> | 10 #include <unordered_set> |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 | 60 |
| 61 using StandbyThreadPolicy = SchedulerWorkerPoolParams::StandbyThreadPolicy; | 61 using StandbyThreadPolicy = SchedulerWorkerPoolParams::StandbyThreadPolicy; |
| 62 | 62 |
| 63 class TaskSchedulerWorkerPoolImplTest | 63 class TaskSchedulerWorkerPoolImplTest |
| 64 : public testing::TestWithParam<test::ExecutionMode> { | 64 : public testing::TestWithParam<test::ExecutionMode> { |
| 65 protected: | 65 protected: |
| 66 TaskSchedulerWorkerPoolImplTest() | 66 TaskSchedulerWorkerPoolImplTest() |
| 67 : service_thread_("TaskSchedulerServiceThread") {} | 67 : service_thread_("TaskSchedulerServiceThread") {} |
| 68 | 68 |
| 69 void SetUp() override { | 69 void SetUp() override { |
| 70 InitializeWorkerPool(TimeDelta::Max(), kNumWorkersInWorkerPool); | 70 if (GetParam() == test::ExecutionMode::SINGLE_THREADED) |
| 71 InitializeSingleThreadWorkerPool(TimeDelta::Max()); | |
| 72 else | |
| 73 InitializeWorkerPool(TimeDelta::Max(), kNumWorkersInWorkerPool); | |
| 71 } | 74 } |
| 72 | 75 |
| 73 void TearDown() override { | 76 void TearDown() override { |
| 74 service_thread_.Stop(); | 77 service_thread_.Stop(); |
| 75 worker_pool_->WaitForAllWorkersIdleForTesting(); | 78 worker_pool_->WaitForAllWorkersIdleForTesting(); |
| 76 worker_pool_->JoinForTesting(); | 79 worker_pool_->JoinForTesting(); |
| 77 } | 80 } |
| 78 | 81 |
| 79 void InitializeWorkerPool(TimeDelta suggested_reclaim_time, | 82 void InitializeWorkerPool(TimeDelta suggested_reclaim_time, |
| 80 size_t num_workers) { | 83 size_t num_workers) { |
| 81 ASSERT_FALSE(worker_pool_); | 84 ASSERT_FALSE(worker_pool_); |
| 82 ASSERT_FALSE(delayed_task_manager_); | 85 ASSERT_FALSE(delayed_task_manager_); |
| 83 service_thread_.Start(); | 86 service_thread_.Start(); |
| 84 delayed_task_manager_ = | 87 delayed_task_manager_ = |
| 85 base::MakeUnique<DelayedTaskManager>(service_thread_.task_runner()); | 88 base::MakeUnique<DelayedTaskManager>(service_thread_.task_runner()); |
| 86 worker_pool_ = SchedulerWorkerPoolImpl::Create( | 89 worker_pool_ = SchedulerWorkerPoolImpl::Create( |
| 87 SchedulerWorkerPoolParams("TestWorkerPool", ThreadPriority::NORMAL, | 90 SchedulerWorkerPoolParams("TestWorkerPool", ThreadPriority::NORMAL, |
| 88 StandbyThreadPolicy::LAZY, num_workers, | 91 StandbyThreadPolicy::LAZY, num_workers, |
| 89 suggested_reclaim_time), | 92 suggested_reclaim_time), |
| 90 Bind(&TaskSchedulerWorkerPoolImplTest::ReEnqueueSequenceCallback, | 93 Bind(&TaskSchedulerWorkerPoolImplTest::ReEnqueueSequenceCallback, |
| 91 Unretained(this)), | 94 Unretained(this)), |
| 92 &task_tracker_, delayed_task_manager_.get()); | 95 &task_tracker_, delayed_task_manager_.get()); |
| 93 ASSERT_TRUE(worker_pool_); | 96 ASSERT_TRUE(worker_pool_); |
| 94 } | 97 } |
| 95 | 98 |
| 99 void InitializeSingleThreadWorkerPool(TimeDelta suggested_reclaim_time) { | |
| 100 ASSERT_FALSE(worker_pool_); | |
| 101 ASSERT_FALSE(delayed_task_manager_); | |
| 102 service_thread_.Start(); | |
| 103 delayed_task_manager_ = | |
| 104 base::MakeUnique<DelayedTaskManager>(service_thread_.task_runner()); | |
| 105 worker_pool_ = CreateSingleThreadWorkerPool( | |
| 106 suggested_reclaim_time, | |
| 107 Bind(&TaskSchedulerWorkerPoolImplTest:: | |
| 108 UnregisterSingleThreadWorkerPoolCallback, | |
| 109 Unretained(this))); | |
| 110 ASSERT_TRUE(worker_pool_); | |
| 111 } | |
| 112 | |
| 113 std::unique_ptr<SchedulerWorkerPoolImpl> CreateSingleThreadWorkerPool( | |
| 114 TimeDelta suggested_reclaim_time, | |
| 115 SchedulerWorkerPoolImpl::UnregisterSingleThreadWorkerPoolCallback | |
| 116 unregister_single_thread_worker_pool_callback) { | |
| 117 return SchedulerWorkerPoolImpl::CreateSingleThreadWorkerPool( | |
| 118 SchedulerWorkerPoolParams("TestWorkerPool", ThreadPriority::NORMAL, | |
| 119 StandbyThreadPolicy::LAZY, 1, | |
| 120 suggested_reclaim_time), | |
| 121 unregister_single_thread_worker_pool_callback, &task_tracker_, | |
| 122 delayed_task_manager_.get()); | |
| 123 } | |
| 124 | |
| 96 std::unique_ptr<SchedulerWorkerPoolImpl> worker_pool_; | 125 std::unique_ptr<SchedulerWorkerPoolImpl> worker_pool_; |
| 97 | 126 |
| 98 TaskTracker task_tracker_; | 127 TaskTracker task_tracker_; |
| 99 Thread service_thread_; | 128 Thread service_thread_; |
| 100 std::unique_ptr<DelayedTaskManager> delayed_task_manager_; | 129 std::unique_ptr<DelayedTaskManager> delayed_task_manager_; |
| 101 | 130 |
| 102 private: | 131 private: |
| 103 void ReEnqueueSequenceCallback(scoped_refptr<Sequence> sequence) { | 132 void ReEnqueueSequenceCallback(scoped_refptr<Sequence> sequence) { |
| 104 // In production code, this callback would be implemented by the | 133 // In production code, this callback would be implemented by the |
| 105 // TaskScheduler which would first determine which PriorityQueue the | 134 // TaskScheduler which would first determine which PriorityQueue the |
| 106 // sequence must be re-enqueued. | 135 // sequence must be re-enqueued. |
| 107 const SequenceSortKey sort_key(sequence->GetSortKey()); | 136 const SequenceSortKey sort_key(sequence->GetSortKey()); |
| 108 worker_pool_->ReEnqueueSequence(std::move(sequence), sort_key); | 137 worker_pool_->ReEnqueueSequence(std::move(sequence), sort_key); |
| 109 } | 138 } |
| 110 | 139 |
| 140 void UnregisterSingleThreadWorkerPoolCallback( | |
| 141 const SchedulerWorkerPoolImpl* scheduler_worker_pool) { | |
| 142 EXPECT_EQ(worker_pool_.get(), scheduler_worker_pool); | |
| 143 } | |
| 144 | |
| 111 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerWorkerPoolImplTest); | 145 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerWorkerPoolImplTest); |
| 112 }; | 146 }; |
| 113 | 147 |
| 114 scoped_refptr<TaskRunner> CreateTaskRunnerWithExecutionMode( | 148 scoped_refptr<TaskRunner> CreateTaskRunnerWithExecutionMode( |
| 115 SchedulerWorkerPoolImpl* worker_pool, | 149 SchedulerWorkerPoolImpl* worker_pool, |
| 116 test::ExecutionMode execution_mode) { | 150 test::ExecutionMode execution_mode) { |
| 117 // Allow tasks posted to the returned TaskRunner to wait on a WaitableEvent. | 151 // Allow tasks posted to the returned TaskRunner to wait on a WaitableEvent. |
| 118 const TaskTraits traits = TaskTraits().WithBaseSyncPrimitives(); | 152 const TaskTraits traits = TaskTraits().WithBaseSyncPrimitives(); |
| 119 switch (execution_mode) { | 153 switch (execution_mode) { |
| 120 case test::ExecutionMode::PARALLEL: | 154 case test::ExecutionMode::PARALLEL: |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 | 284 |
| 251 // Wait until all workers are idle to be sure that no task accesses its | 285 // Wait until all workers are idle to be sure that no task accesses its |
| 252 // TestTaskFactory after |thread_posting_tasks| is destroyed. | 286 // TestTaskFactory after |thread_posting_tasks| is destroyed. |
| 253 worker_pool_->WaitForAllWorkersIdleForTesting(); | 287 worker_pool_->WaitForAllWorkersIdleForTesting(); |
| 254 } | 288 } |
| 255 | 289 |
| 256 TEST_P(TaskSchedulerWorkerPoolImplTest, PostTasksWithOneAvailableWorker) { | 290 TEST_P(TaskSchedulerWorkerPoolImplTest, PostTasksWithOneAvailableWorker) { |
| 257 // Post blocking tasks to keep all workers busy except one until |event| is | 291 // Post blocking tasks to keep all workers busy except one until |event| is |
| 258 // signaled. Use different factories so that tasks are added to different | 292 // signaled. Use different factories so that tasks are added to different |
| 259 // sequences and can run simultaneously when the execution mode is SEQUENCED. | 293 // sequences and can run simultaneously when the execution mode is SEQUENCED. |
| 294 const size_t num_workers_in_pool = | |
| 295 (GetParam() == test::ExecutionMode::SINGLE_THREADED) | |
| 296 ? 1 | |
| 297 : kNumWorkersInWorkerPool; | |
| 260 WaitableEvent event(WaitableEvent::ResetPolicy::MANUAL, | 298 WaitableEvent event(WaitableEvent::ResetPolicy::MANUAL, |
| 261 WaitableEvent::InitialState::NOT_SIGNALED); | 299 WaitableEvent::InitialState::NOT_SIGNALED); |
| 262 std::vector<std::unique_ptr<test::TestTaskFactory>> blocked_task_factories; | 300 std::vector<std::unique_ptr<test::TestTaskFactory>> blocked_task_factories; |
| 263 for (size_t i = 0; i < (kNumWorkersInWorkerPool - 1); ++i) { | 301 for (size_t i = 0; i < (num_workers_in_pool - 1); ++i) { |
| 264 blocked_task_factories.push_back(MakeUnique<test::TestTaskFactory>( | 302 blocked_task_factories.push_back(MakeUnique<test::TestTaskFactory>( |
| 265 CreateTaskRunnerWithExecutionMode(worker_pool_.get(), GetParam()), | 303 CreateTaskRunnerWithExecutionMode(worker_pool_.get(), GetParam()), |
| 266 GetParam())); | 304 GetParam())); |
| 267 EXPECT_TRUE(blocked_task_factories.back()->PostTask( | 305 EXPECT_TRUE(blocked_task_factories.back()->PostTask( |
| 268 PostNestedTask::NO, Bind(&WaitableEvent::Wait, Unretained(&event)))); | 306 PostNestedTask::NO, Bind(&WaitableEvent::Wait, Unretained(&event)))); |
| 269 blocked_task_factories.back()->WaitForAllTasksToRun(); | 307 blocked_task_factories.back()->WaitForAllTasksToRun(); |
| 270 } | 308 } |
| 271 | 309 |
| 272 // Post |kNumTasksPostedPerThread| tasks that should all run despite the fact | 310 // Post |kNumTasksPostedPerThread| tasks that should all run despite the fact |
| 273 // that only one worker in |worker_pool_| isn't busy. | 311 // that only one worker in |worker_pool_| isn't busy. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 284 // Wait until all workers are idle to be sure that no task accesses | 322 // Wait until all workers are idle to be sure that no task accesses |
| 285 // its TestTaskFactory after it is destroyed. | 323 // its TestTaskFactory after it is destroyed. |
| 286 worker_pool_->WaitForAllWorkersIdleForTesting(); | 324 worker_pool_->WaitForAllWorkersIdleForTesting(); |
| 287 } | 325 } |
| 288 | 326 |
| 289 TEST_P(TaskSchedulerWorkerPoolImplTest, Saturate) { | 327 TEST_P(TaskSchedulerWorkerPoolImplTest, Saturate) { |
| 290 // Verify that it is possible to have |kNumWorkersInWorkerPool| | 328 // Verify that it is possible to have |kNumWorkersInWorkerPool| |
| 291 // tasks/sequences running simultaneously. Use different factories so that the | 329 // tasks/sequences running simultaneously. Use different factories so that the |
| 292 // blocking tasks are added to different sequences and can run simultaneously | 330 // blocking tasks are added to different sequences and can run simultaneously |
| 293 // when the execution mode is SEQUENCED. | 331 // when the execution mode is SEQUENCED. |
| 332 const size_t num_workers_in_pool = | |
| 333 (GetParam() == test::ExecutionMode::SINGLE_THREADED) | |
| 334 ? 1 | |
| 335 : kNumWorkersInWorkerPool; | |
| 294 WaitableEvent event(WaitableEvent::ResetPolicy::MANUAL, | 336 WaitableEvent event(WaitableEvent::ResetPolicy::MANUAL, |
| 295 WaitableEvent::InitialState::NOT_SIGNALED); | 337 WaitableEvent::InitialState::NOT_SIGNALED); |
| 296 std::vector<std::unique_ptr<test::TestTaskFactory>> factories; | 338 std::vector<std::unique_ptr<test::TestTaskFactory>> factories; |
| 297 for (size_t i = 0; i < kNumWorkersInWorkerPool; ++i) { | 339 for (size_t i = 0; i < num_workers_in_pool; ++i) { |
| 298 factories.push_back(MakeUnique<test::TestTaskFactory>( | 340 factories.push_back(MakeUnique<test::TestTaskFactory>( |
| 299 CreateTaskRunnerWithExecutionMode(worker_pool_.get(), GetParam()), | 341 CreateTaskRunnerWithExecutionMode(worker_pool_.get(), GetParam()), |
| 300 GetParam())); | 342 GetParam())); |
| 301 EXPECT_TRUE(factories.back()->PostTask( | 343 EXPECT_TRUE(factories.back()->PostTask( |
| 302 PostNestedTask::NO, Bind(&WaitableEvent::Wait, Unretained(&event)))); | 344 PostNestedTask::NO, Bind(&WaitableEvent::Wait, Unretained(&event)))); |
| 303 factories.back()->WaitForAllTasksToRun(); | 345 factories.back()->WaitForAllTasksToRun(); |
| 304 } | 346 } |
| 305 | 347 |
| 306 // Release tasks waiting on |event|. | 348 // Release tasks waiting on |event|. |
| 307 event.Signal(); | 349 event.Signal(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 381 namespace { | 423 namespace { |
| 382 | 424 |
| 383 // Same as TaskSchedulerWorkerPoolImplTest but its SchedulerWorkerPoolImpl | 425 // Same as TaskSchedulerWorkerPoolImplTest but its SchedulerWorkerPoolImpl |
| 384 // instance uses |max_threads == 1|. | 426 // instance uses |max_threads == 1|. |
| 385 class TaskSchedulerWorkerPoolImplSingleWorkerTest | 427 class TaskSchedulerWorkerPoolImplSingleWorkerTest |
| 386 : public TaskSchedulerWorkerPoolImplTest { | 428 : public TaskSchedulerWorkerPoolImplTest { |
| 387 public: | 429 public: |
| 388 TaskSchedulerWorkerPoolImplSingleWorkerTest() = default; | 430 TaskSchedulerWorkerPoolImplSingleWorkerTest() = default; |
| 389 | 431 |
| 390 protected: | 432 protected: |
| 391 void SetUp() override { | 433 void SetUp() override { InitializeSingleThreadWorkerPool(TimeDelta::Max()); } |
| 392 InitializeWorkerPool(TimeDelta::Max(), 1); | |
| 393 } | |
| 394 | 434 |
| 395 private: | 435 private: |
| 396 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerWorkerPoolImplSingleWorkerTest); | 436 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerWorkerPoolImplSingleWorkerTest); |
| 397 }; | 437 }; |
| 398 | 438 |
| 399 } // namespace | 439 } // namespace |
| 400 | 440 |
| 401 // Verify that the RunsTasksOnCurrentThread() method of a | 441 // Verify that the RunsTasksOnCurrentThread() method of a |
| 402 // SchedulerSingleThreadTaskRunner returns false when called from a task that | 442 // SchedulerSingleThreadTaskRunner returns false when called from a task that |
| 403 // isn't part of its sequence even though it's running on that | 443 // isn't part of its sequence even though it's running on that |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 445 void InitializeThreadChecker() { | 485 void InitializeThreadChecker() { |
| 446 thread_checker_.reset(new ThreadCheckerImpl()); | 486 thread_checker_.reset(new ThreadCheckerImpl()); |
| 447 } | 487 } |
| 448 | 488 |
| 449 void CheckValidThread() { | 489 void CheckValidThread() { |
| 450 EXPECT_TRUE(thread_checker_->CalledOnValidThread()); | 490 EXPECT_TRUE(thread_checker_->CalledOnValidThread()); |
| 451 } | 491 } |
| 452 | 492 |
| 453 protected: | 493 protected: |
| 454 void SetUp() override { | 494 void SetUp() override { |
| 455 InitializeWorkerPool(kReclaimTimeForDetachTests, kNumWorkersInWorkerPool); | 495 InitializeSingleThreadWorkerPool(kReclaimTimeForDetachTests); |
| 456 } | 496 } |
| 457 | 497 |
| 458 TaskSchedulerWorkerPoolSingleThreadedTest() = default; | 498 TaskSchedulerWorkerPoolSingleThreadedTest() = default; |
| 459 | 499 |
| 460 private: | 500 private: |
| 461 std::unique_ptr<ThreadCheckerImpl> thread_checker_; | 501 std::unique_ptr<ThreadCheckerImpl> thread_checker_; |
| 462 | 502 |
| 463 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerWorkerPoolSingleThreadedTest); | 503 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerWorkerPoolSingleThreadedTest); |
| 464 }; | 504 }; |
| 465 | 505 |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 731 *thread_id = PlatformThread::CurrentId(); | 771 *thread_id = PlatformThread::CurrentId(); |
| 732 } | 772 } |
| 733 | 773 |
| 734 void VerifyThreadIdIsNot(PlatformThreadId thread_id) { | 774 void VerifyThreadIdIsNot(PlatformThreadId thread_id) { |
| 735 EXPECT_NE(thread_id, PlatformThread::CurrentId()); | 775 EXPECT_NE(thread_id, PlatformThread::CurrentId()); |
| 736 } | 776 } |
| 737 | 777 |
| 738 } // namespace | 778 } // namespace |
| 739 | 779 |
| 740 TEST_F(TaskSchedulerWorkerPoolHistogramTest, NumTasksBeforeDetach) { | 780 TEST_F(TaskSchedulerWorkerPoolHistogramTest, NumTasksBeforeDetach) { |
| 741 InitializeWorkerPool(kReclaimTimeForDetachTests, kNumWorkersInWorkerPool); | 781 InitializeSingleThreadWorkerPool(kReclaimTimeForDetachTests); |
| 782 std::unique_ptr<SchedulerWorkerPoolImpl> other_worker_pool = | |
| 783 CreateSingleThreadWorkerPool( | |
| 784 kReclaimTimeForDetachTests, | |
| 785 base::Bind( | |
| 786 [](const SchedulerWorkerPoolImpl* scheduler_worker_pool) {})); | |
| 742 | 787 |
| 743 // This test assumes that the TaskRunners aren't assigned to the same worker. | 788 // This test assumes that the TaskRunners aren't assigned to the same worker. |
| 744 auto task_runner = | 789 auto task_runner = |
| 745 worker_pool_->CreateSingleThreadTaskRunnerWithTraits(TaskTraits()); | 790 worker_pool_->CreateSingleThreadTaskRunnerWithTraits(TaskTraits()); |
| 746 auto other_task_runner = | 791 auto other_task_runner = |
|
fdoray
2017/01/27 16:47:35
|other_task_runner| was used to change the order o
robliao
2017/01/27 21:25:41
Removed!
| |
| 747 worker_pool_->CreateSingleThreadTaskRunnerWithTraits(TaskTraits()); | 792 other_worker_pool->CreateSingleThreadTaskRunnerWithTraits(TaskTraits()); |
| 793 other_worker_pool->DisallowWorkerDetachmentForTesting(); | |
| 748 | 794 |
| 749 // Post 3 tasks and wait until they run. | 795 // Post 3 tasks and wait until they run. |
| 750 PlatformThreadId thread_id; | 796 PlatformThreadId thread_id; |
| 751 task_runner->PostTask(FROM_HERE, | 797 task_runner->PostTask(FROM_HERE, |
| 752 Bind(&CaptureThreadId, Unretained(&thread_id))); | 798 Bind(&CaptureThreadId, Unretained(&thread_id))); |
| 753 task_runner->PostTask(FROM_HERE, Bind(&DoNothing)); | 799 task_runner->PostTask(FROM_HERE, Bind(&DoNothing)); |
| 754 task_runner->PostTask(FROM_HERE, Bind(&DoNothing)); | 800 task_runner->PostTask(FROM_HERE, Bind(&DoNothing)); |
| 755 worker_pool_->WaitForAllWorkersIdleForTesting(); | 801 worker_pool_->WaitForAllWorkersIdleForTesting(); |
| 756 | 802 |
| 757 // To allow the SchedulerWorker associated with |task_runner| to detach: | 803 // To allow the SchedulerWorker associated with |task_runner| to detach: |
| 758 // - Make sure it isn't on top of the idle stack by waking up another | 804 // - Make sure it isn't on top of the idle stack by waking up another |
| 759 // SchedulerWorker and waiting until it goes back to sleep. | 805 // SchedulerWorker and waiting until it goes back to sleep. |
| 760 // - Release |task_runner|. | 806 // - Release |task_runner|. |
| 761 other_task_runner->PostTask(FROM_HERE, Bind(&VerifyThreadIdIsNot, thread_id)); | 807 other_task_runner->PostTask(FROM_HERE, Bind(&VerifyThreadIdIsNot, thread_id)); |
| 762 worker_pool_->WaitForAllWorkersIdleForTesting(); | 808 worker_pool_->WaitForAllWorkersIdleForTesting(); |
| 809 other_worker_pool->WaitForAllWorkersIdleForTesting(); | |
| 763 task_runner = nullptr; | 810 task_runner = nullptr; |
| 764 | 811 |
| 765 // Allow the SchedulerWorker that was associated with |task_runner| to detach. | 812 // Allow the SchedulerWorker that was associated with |task_runner| to detach. |
| 766 PlatformThread::Sleep(kReclaimTimeForDetachTests + kExtraTimeToWaitForDetach); | 813 PlatformThread::Sleep(kReclaimTimeForDetachTests + kExtraTimeToWaitForDetach); |
| 767 worker_pool_->DisallowWorkerDetachmentForTesting(); | 814 worker_pool_->DisallowWorkerDetachmentForTesting(); |
| 768 | 815 |
| 769 // Verify that counts were recorded to the histogram as expected. | 816 // Verify that counts were recorded to the histogram as expected. |
| 770 const auto* histogram = worker_pool_->num_tasks_before_detach_histogram(); | 817 const auto* histogram = worker_pool_->num_tasks_before_detach_histogram(); |
| 771 EXPECT_EQ(0, histogram->SnapshotSamples()->GetCount(0)); | 818 EXPECT_EQ(0, histogram->SnapshotSamples()->GetCount(0)); |
| 772 EXPECT_EQ(1, histogram->SnapshotSamples()->GetCount(3)); | 819 EXPECT_EQ(1, histogram->SnapshotSamples()->GetCount(3)); |
| 773 EXPECT_EQ(0, histogram->SnapshotSamples()->GetCount(10)); | 820 EXPECT_EQ(0, histogram->SnapshotSamples()->GetCount(10)); |
| 821 other_worker_pool->JoinForTesting(); | |
| 774 } | 822 } |
| 775 | 823 |
| 776 TEST(TaskSchedulerWorkerPoolStandbyPolicyTest, InitLazy) { | 824 TEST(TaskSchedulerWorkerPoolStandbyPolicyTest, InitLazy) { |
| 777 TaskTracker task_tracker; | 825 TaskTracker task_tracker; |
| 778 DelayedTaskManager delayed_task_manager( | 826 DelayedTaskManager delayed_task_manager( |
| 779 make_scoped_refptr(new TestSimpleTaskRunner)); | 827 make_scoped_refptr(new TestSimpleTaskRunner)); |
| 780 auto worker_pool = SchedulerWorkerPoolImpl::Create( | 828 auto worker_pool = SchedulerWorkerPoolImpl::Create( |
| 781 SchedulerWorkerPoolParams("LazyPolicyWorkerPool", ThreadPriority::NORMAL, | 829 SchedulerWorkerPoolParams("LazyPolicyWorkerPool", ThreadPriority::NORMAL, |
| 782 StandbyThreadPolicy::LAZY, 8U, | 830 StandbyThreadPolicy::LAZY, 8U, |
| 783 TimeDelta::Max()), | 831 TimeDelta::Max()), |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 797 StandbyThreadPolicy::ONE, 8U, TimeDelta::Max()), | 845 StandbyThreadPolicy::ONE, 8U, TimeDelta::Max()), |
| 798 Bind(&NotReachedReEnqueueSequenceCallback), &task_tracker, | 846 Bind(&NotReachedReEnqueueSequenceCallback), &task_tracker, |
| 799 &delayed_task_manager); | 847 &delayed_task_manager); |
| 800 ASSERT_TRUE(worker_pool); | 848 ASSERT_TRUE(worker_pool); |
| 801 EXPECT_EQ(1U, worker_pool->NumberOfAliveWorkersForTesting()); | 849 EXPECT_EQ(1U, worker_pool->NumberOfAliveWorkersForTesting()); |
| 802 worker_pool->JoinForTesting(); | 850 worker_pool->JoinForTesting(); |
| 803 } | 851 } |
| 804 | 852 |
| 805 } // namespace internal | 853 } // namespace internal |
| 806 } // namespace base | 854 } // namespace base |
| OLD | NEW |