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> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
15 #include "base/callback.h" | 15 #include "base/callback.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
19 #include "base/synchronization/condition_variable.h" | 19 #include "base/synchronization/condition_variable.h" |
20 #include "base/synchronization/lock.h" | 20 #include "base/synchronization/lock.h" |
21 #include "base/synchronization/waitable_event.h" | 21 #include "base/synchronization/waitable_event.h" |
22 #include "base/task_runner.h" | 22 #include "base/task_runner.h" |
23 #include "base/task_scheduler/delayed_task_manager.h" | 23 #include "base/task_scheduler/delayed_task_manager.h" |
24 #include "base/task_scheduler/sequence.h" | 24 #include "base/task_scheduler/sequence.h" |
25 #include "base/task_scheduler/sequence_sort_key.h" | 25 #include "base/task_scheduler/sequence_sort_key.h" |
26 #include "base/task_scheduler/task_tracker.h" | 26 #include "base/task_scheduler/task_tracker.h" |
27 #include "base/task_scheduler/test_task_factory.h" | 27 #include "base/task_scheduler/test_task_factory.h" |
28 #include "base/task_scheduler/test_utils.h" | 28 #include "base/task_scheduler/test_utils.h" |
| 29 #include "base/task_scheduler/worker_pool_params.h" |
29 #include "base/threading/platform_thread.h" | 30 #include "base/threading/platform_thread.h" |
30 #include "base/threading/simple_thread.h" | 31 #include "base/threading/simple_thread.h" |
31 #include "base/threading/thread_restrictions.h" | 32 #include "base/threading/thread_restrictions.h" |
32 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
33 | 34 |
34 namespace base { | 35 namespace base { |
35 namespace internal { | 36 namespace internal { |
36 namespace { | 37 namespace { |
37 | 38 |
38 const size_t kNumWorkersInWorkerPool = 4; | 39 const size_t kNumWorkersInWorkerPool = 4; |
(...skipping 17 matching lines...) Expand all Loading... |
56 DISALLOW_COPY_AND_ASSIGN(TestDelayedTaskManager); | 57 DISALLOW_COPY_AND_ASSIGN(TestDelayedTaskManager); |
57 }; | 58 }; |
58 | 59 |
59 class TaskSchedulerWorkerPoolImplTest | 60 class TaskSchedulerWorkerPoolImplTest |
60 : public testing::TestWithParam<ExecutionMode> { | 61 : public testing::TestWithParam<ExecutionMode> { |
61 protected: | 62 protected: |
62 TaskSchedulerWorkerPoolImplTest() = default; | 63 TaskSchedulerWorkerPoolImplTest() = default; |
63 | 64 |
64 void SetUp() override { | 65 void SetUp() override { |
65 worker_pool_ = SchedulerWorkerPoolImpl::Create( | 66 worker_pool_ = SchedulerWorkerPoolImpl::Create( |
66 "TestWorkerPoolWithFileIO", ThreadPriority::NORMAL, | 67 WorkerPoolParams("TestWorkerPoolWithFileIO", ThreadPriority::NORMAL, |
67 kNumWorkersInWorkerPool, IORestriction::ALLOWED, | 68 IORestriction::ALLOWED, kNumWorkersInWorkerPool), |
68 Bind(&TaskSchedulerWorkerPoolImplTest::ReEnqueueSequenceCallback, | 69 Bind(&TaskSchedulerWorkerPoolImplTest::ReEnqueueSequenceCallback, |
69 Unretained(this)), | 70 Unretained(this)), |
70 &task_tracker_, &delayed_task_manager_); | 71 &task_tracker_, &delayed_task_manager_); |
71 ASSERT_TRUE(worker_pool_); | 72 ASSERT_TRUE(worker_pool_); |
72 } | 73 } |
73 | 74 |
74 void TearDown() override { | 75 void TearDown() override { |
75 worker_pool_->WaitForAllWorkersIdleForTesting(); | 76 worker_pool_->WaitForAllWorkersIdleForTesting(); |
76 worker_pool_->JoinForTesting(); | 77 worker_pool_->JoinForTesting(); |
77 } | 78 } |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerWorkerPoolImplIORestrictionTest); | 357 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerWorkerPoolImplIORestrictionTest); |
357 }; | 358 }; |
358 | 359 |
359 } // namespace | 360 } // namespace |
360 | 361 |
361 TEST_P(TaskSchedulerWorkerPoolImplIORestrictionTest, IORestriction) { | 362 TEST_P(TaskSchedulerWorkerPoolImplIORestrictionTest, IORestriction) { |
362 TaskTracker task_tracker; | 363 TaskTracker task_tracker; |
363 DelayedTaskManager delayed_task_manager(Bind(&DoNothing)); | 364 DelayedTaskManager delayed_task_manager(Bind(&DoNothing)); |
364 | 365 |
365 auto worker_pool = SchedulerWorkerPoolImpl::Create( | 366 auto worker_pool = SchedulerWorkerPoolImpl::Create( |
366 "TestWorkerPoolWithParam", ThreadPriority::NORMAL, 1U, GetParam(), | 367 WorkerPoolParams("TestWorkerPoolWithParam", ThreadPriority::NORMAL, |
| 368 GetParam(), 1U), |
367 Bind(&NotReachedReEnqueueSequenceCallback), &task_tracker, | 369 Bind(&NotReachedReEnqueueSequenceCallback), &task_tracker, |
368 &delayed_task_manager); | 370 &delayed_task_manager); |
369 ASSERT_TRUE(worker_pool); | 371 ASSERT_TRUE(worker_pool); |
370 | 372 |
371 WaitableEvent task_ran(WaitableEvent::ResetPolicy::MANUAL, | 373 WaitableEvent task_ran(WaitableEvent::ResetPolicy::MANUAL, |
372 WaitableEvent::InitialState::NOT_SIGNALED); | 374 WaitableEvent::InitialState::NOT_SIGNALED); |
373 worker_pool->CreateTaskRunnerWithTraits(TaskTraits(), ExecutionMode::PARALLEL) | 375 worker_pool->CreateTaskRunnerWithTraits(TaskTraits(), ExecutionMode::PARALLEL) |
374 ->PostTask(FROM_HERE, Bind(&ExpectIORestriction, GetParam(), &task_ran)); | 376 ->PostTask(FROM_HERE, Bind(&ExpectIORestriction, GetParam(), &task_ran)); |
375 task_ran.Wait(); | 377 task_ran.Wait(); |
376 | 378 |
377 worker_pool->JoinForTesting(); | 379 worker_pool->JoinForTesting(); |
378 } | 380 } |
379 | 381 |
380 INSTANTIATE_TEST_CASE_P(IOAllowed, | 382 INSTANTIATE_TEST_CASE_P(IOAllowed, |
381 TaskSchedulerWorkerPoolImplIORestrictionTest, | 383 TaskSchedulerWorkerPoolImplIORestrictionTest, |
382 ::testing::Values(IORestriction::ALLOWED)); | 384 ::testing::Values(IORestriction::ALLOWED)); |
383 INSTANTIATE_TEST_CASE_P(IODisallowed, | 385 INSTANTIATE_TEST_CASE_P(IODisallowed, |
384 TaskSchedulerWorkerPoolImplIORestrictionTest, | 386 TaskSchedulerWorkerPoolImplIORestrictionTest, |
385 ::testing::Values(IORestriction::DISALLOWED)); | 387 ::testing::Values(IORestriction::DISALLOWED)); |
386 | 388 |
387 } // namespace internal | 389 } // namespace internal |
388 } // namespace base | 390 } // namespace base |
OLD | NEW |