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

Unified Diff: base/task_scheduler/task_scheduler_impl_unittest.cc

Issue 2064073003: TaskScheduler: Make the worker pools of TaskSchedulerImpl configurable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: self-review Created 4 years, 6 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 | « base/task_scheduler/task_scheduler_impl.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/task_scheduler/task_scheduler_impl_unittest.cc
diff --git a/base/task_scheduler/task_scheduler_impl_unittest.cc b/base/task_scheduler/task_scheduler_impl_unittest.cc
index e79a381c350ac0d2ec5d000adabc365b90fc429b..ba6588581f0d96fa29dfde33c9a0e3c9c8ae22ce 100644
--- a/base/task_scheduler/task_scheduler_impl_unittest.cc
+++ b/base/task_scheduler/task_scheduler_impl_unittest.cc
@@ -38,23 +38,6 @@ struct TraitsExecutionModePair {
ExecutionMode execution_mode;
};
-class TaskSchedulerImplTest
- : public testing::TestWithParam<TraitsExecutionModePair> {
- protected:
- TaskSchedulerImplTest() = default;
-
- void SetUp() override {
- scheduler_ = TaskSchedulerImpl::Create();
- EXPECT_TRUE(scheduler_);
- }
- void TearDown() override { scheduler_->JoinForTesting(); }
-
- std::unique_ptr<TaskSchedulerImpl> scheduler_;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(TaskSchedulerImplTest);
-};
-
#if ENABLE_THREAD_RESTRICTIONS
// Returns whether I/O calls are allowed on the current thread.
bool GetIOAllowed() {
@@ -152,6 +135,65 @@ std::vector<TraitsExecutionModePair> GetTraitsExecutionModePairs() {
return params;
}
+enum WorkerPoolType {
+ BACKGROUND_WORKER_POOL = 0,
+ BACKGROUND_FILE_IO_WORKER_POOL,
+ FOREGROUND_WORKER_POOL,
+ FOREGROUND_FILE_IO_WORKER_POOL,
+};
+
+size_t GetThreadPoolIndexForTraits(const TaskTraits& traits) {
+ if (traits.with_file_io()) {
+ return traits.priority() == TaskPriority::BACKGROUND
+ ? BACKGROUND_FILE_IO_WORKER_POOL
+ : FOREGROUND_FILE_IO_WORKER_POOL;
+ }
+ return traits.priority() == TaskPriority::BACKGROUND ? BACKGROUND_WORKER_POOL
+ : FOREGROUND_WORKER_POOL;
+}
+
+class TaskSchedulerImplTest
+ : public testing::TestWithParam<TraitsExecutionModePair> {
+ protected:
+ TaskSchedulerImplTest() = default;
+
+ void SetUp() override {
+ using IORestriction = SchedulerWorkerPoolImpl::IORestriction;
+
+ std::vector<TaskSchedulerImpl::WorkerPoolCreationArgs> worker_pools;
+
+ EXPECT_EQ(BACKGROUND_WORKER_POOL, worker_pools.size());
robliao 2016/06/28 00:24:24 These should probably be ASSERTS. If an index mism
fdoray 2016/06/28 15:23:58 Done.
+ worker_pools.push_back({"TaskSchedulerBackground",
+ ThreadPriority::BACKGROUND,
+ IORestriction::DISALLOWED, 1U});
+
+ EXPECT_EQ(BACKGROUND_FILE_IO_WORKER_POOL, worker_pools.size());
+ worker_pools.push_back({"TaskSchedulerBackgroundFileIO",
+ ThreadPriority::BACKGROUND, IORestriction::ALLOWED,
+ 3U});
+
+ EXPECT_EQ(FOREGROUND_WORKER_POOL, worker_pools.size());
+ worker_pools.push_back({"TaskSchedulerForeground", ThreadPriority::NORMAL,
+ IORestriction::DISALLOWED, 4U});
+
+ DCHECK_EQ(FOREGROUND_FILE_IO_WORKER_POOL, worker_pools.size());
robliao 2016/06/28 00:24:24 Typo?
fdoray 2016/06/28 15:23:58 Done.
+ worker_pools.push_back({"TaskSchedulerForegroundFileIO",
+ ThreadPriority::NORMAL, IORestriction::ALLOWED,
+ 12U});
+
+ scheduler_ = TaskSchedulerImpl::Create(worker_pools,
+ Bind(&GetThreadPoolIndexForTraits));
+ ASSERT_TRUE(scheduler_);
+ }
+
+ void TearDown() override { scheduler_->JoinForTesting(); }
+
+ std::unique_ptr<TaskSchedulerImpl> scheduler_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TaskSchedulerImplTest);
+};
+
} // namespace
// Verifies that a Task posted via PostTaskWithTraits with parameterized
@@ -194,13 +236,11 @@ INSTANTIATE_TEST_CASE_P(OneTraitsExecutionModePair,
// TaskTraits and ExecutionModes. Verifies that each Task runs on a thread with
// the expected priority and I/O restrictions and respects the characteristics
// of its ExecutionMode.
-TEST(TaskSchedulerImplTest, MultipleTraitsExecutionModePairs) {
- std::unique_ptr<TaskSchedulerImpl> scheduler = TaskSchedulerImpl::Create();
-
+TEST_F(TaskSchedulerImplTest, MultipleTraitsExecutionModePairs) {
std::vector<std::unique_ptr<ThreadPostingTasks>> threads_posting_tasks;
for (const auto& traits_execution_mode_pair : GetTraitsExecutionModePairs()) {
threads_posting_tasks.push_back(WrapUnique(new ThreadPostingTasks(
- scheduler.get(), traits_execution_mode_pair.traits,
+ scheduler_.get(), traits_execution_mode_pair.traits,
traits_execution_mode_pair.execution_mode)));
threads_posting_tasks.back()->Start();
}
@@ -209,8 +249,6 @@ TEST(TaskSchedulerImplTest, MultipleTraitsExecutionModePairs) {
thread->WaitForAllTasksToRun();
thread->Join();
}
-
- scheduler->JoinForTesting();
}
// TODO(fdoray): Add tests with Sequences that move around worker pools once
« no previous file with comments | « base/task_scheduler/task_scheduler_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698