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

Side by Side Diff: base/task_scheduler/scheduler_worker_pool_impl_unittest.cc

Issue 2146223002: Refactor WorkerPoolCreationArgs to a Read-Only WorkerPoolParams (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR Feedback Created 4 years, 5 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 unified diff | Download patch
OLDNEW
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/scheduler_worker_pool_params.h"
24 #include "base/task_scheduler/sequence.h" 25 #include "base/task_scheduler/sequence.h"
25 #include "base/task_scheduler/sequence_sort_key.h" 26 #include "base/task_scheduler/sequence_sort_key.h"
26 #include "base/task_scheduler/task_tracker.h" 27 #include "base/task_scheduler/task_tracker.h"
27 #include "base/task_scheduler/test_task_factory.h" 28 #include "base/task_scheduler/test_task_factory.h"
28 #include "base/task_scheduler/test_utils.h" 29 #include "base/task_scheduler/test_utils.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;
39 const size_t kNumThreadsPostingTasks = 4; 40 const size_t kNumThreadsPostingTasks = 4;
40 const size_t kNumTasksPostedPerThread = 150; 41 const size_t kNumTasksPostedPerThread = 150;
41 42
42 using IORestriction = SchedulerWorkerPoolImpl::IORestriction; 43 using IORestriction = SchedulerWorkerPoolParams::IORestriction;
43 44
44 class TestDelayedTaskManager : public DelayedTaskManager { 45 class TestDelayedTaskManager : public DelayedTaskManager {
45 public: 46 public:
46 TestDelayedTaskManager() : DelayedTaskManager(Bind(&DoNothing)) {} 47 TestDelayedTaskManager() : DelayedTaskManager(Bind(&DoNothing)) {}
47 48
48 void SetCurrentTime(TimeTicks now) { now_ = now; } 49 void SetCurrentTime(TimeTicks now) { now_ = now; }
49 50
50 // DelayedTaskManager: 51 // DelayedTaskManager:
51 TimeTicks Now() const override { return now_; } 52 TimeTicks Now() const override { return now_; }
52 53
53 private: 54 private:
54 TimeTicks now_ = TimeTicks::Now(); 55 TimeTicks now_ = TimeTicks::Now();
55 56
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 SchedulerWorkerPoolParams("TestWorkerPoolWithFileIO",
67 kNumWorkersInWorkerPool, IORestriction::ALLOWED, 68 ThreadPriority::NORMAL,
69 IORestriction::ALLOWED,
70 kNumWorkersInWorkerPool),
68 Bind(&TaskSchedulerWorkerPoolImplTest::ReEnqueueSequenceCallback, 71 Bind(&TaskSchedulerWorkerPoolImplTest::ReEnqueueSequenceCallback,
69 Unretained(this)), 72 Unretained(this)),
70 &task_tracker_, &delayed_task_manager_); 73 &task_tracker_, &delayed_task_manager_);
71 ASSERT_TRUE(worker_pool_); 74 ASSERT_TRUE(worker_pool_);
72 } 75 }
73 76
74 void TearDown() override { 77 void TearDown() override {
75 worker_pool_->WaitForAllWorkersIdleForTesting(); 78 worker_pool_->WaitForAllWorkersIdleForTesting();
76 worker_pool_->JoinForTesting(); 79 worker_pool_->JoinForTesting();
77 } 80 }
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerWorkerPoolImplIORestrictionTest); 359 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerWorkerPoolImplIORestrictionTest);
357 }; 360 };
358 361
359 } // namespace 362 } // namespace
360 363
361 TEST_P(TaskSchedulerWorkerPoolImplIORestrictionTest, IORestriction) { 364 TEST_P(TaskSchedulerWorkerPoolImplIORestrictionTest, IORestriction) {
362 TaskTracker task_tracker; 365 TaskTracker task_tracker;
363 DelayedTaskManager delayed_task_manager(Bind(&DoNothing)); 366 DelayedTaskManager delayed_task_manager(Bind(&DoNothing));
364 367
365 auto worker_pool = SchedulerWorkerPoolImpl::Create( 368 auto worker_pool = SchedulerWorkerPoolImpl::Create(
366 "TestWorkerPoolWithParam", ThreadPriority::NORMAL, 1U, GetParam(), 369 SchedulerWorkerPoolParams("TestWorkerPoolWithParam",
370 ThreadPriority::NORMAL, GetParam(), 1U),
367 Bind(&NotReachedReEnqueueSequenceCallback), &task_tracker, 371 Bind(&NotReachedReEnqueueSequenceCallback), &task_tracker,
368 &delayed_task_manager); 372 &delayed_task_manager);
369 ASSERT_TRUE(worker_pool); 373 ASSERT_TRUE(worker_pool);
370 374
371 WaitableEvent task_ran(WaitableEvent::ResetPolicy::MANUAL, 375 WaitableEvent task_ran(WaitableEvent::ResetPolicy::MANUAL,
372 WaitableEvent::InitialState::NOT_SIGNALED); 376 WaitableEvent::InitialState::NOT_SIGNALED);
373 worker_pool->CreateTaskRunnerWithTraits(TaskTraits(), ExecutionMode::PARALLEL) 377 worker_pool->CreateTaskRunnerWithTraits(TaskTraits(), ExecutionMode::PARALLEL)
374 ->PostTask(FROM_HERE, Bind(&ExpectIORestriction, GetParam(), &task_ran)); 378 ->PostTask(FROM_HERE, Bind(&ExpectIORestriction, GetParam(), &task_ran));
375 task_ran.Wait(); 379 task_ran.Wait();
376 380
377 worker_pool->JoinForTesting(); 381 worker_pool->JoinForTesting();
378 } 382 }
379 383
380 INSTANTIATE_TEST_CASE_P(IOAllowed, 384 INSTANTIATE_TEST_CASE_P(IOAllowed,
381 TaskSchedulerWorkerPoolImplIORestrictionTest, 385 TaskSchedulerWorkerPoolImplIORestrictionTest,
382 ::testing::Values(IORestriction::ALLOWED)); 386 ::testing::Values(IORestriction::ALLOWED));
383 INSTANTIATE_TEST_CASE_P(IODisallowed, 387 INSTANTIATE_TEST_CASE_P(IODisallowed,
384 TaskSchedulerWorkerPoolImplIORestrictionTest, 388 TaskSchedulerWorkerPoolImplIORestrictionTest,
385 ::testing::Values(IORestriction::DISALLOWED)); 389 ::testing::Values(IORestriction::DISALLOWED));
386 390
387 } // namespace internal 391 } // namespace internal
388 } // namespace base 392 } // namespace base
OLDNEW
« no previous file with comments | « base/task_scheduler/scheduler_worker_pool_impl.cc ('k') | base/task_scheduler/scheduler_worker_pool_params.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698