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

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: rebase 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
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..011d4bed42dc9022bdce245ca7757849b35d6674 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,45 @@ std::vector<TraitsExecutionModePair> GetTraitsExecutionModePairs() {
return params;
}
+size_t GetThreadPoolIndexForTraits(const TaskTraits& traits) {
+ if (traits.with_file_io())
+ return traits.priority() == TaskPriority::BACKGROUND ? 1U : 3U;
robliao 2016/06/23 22:37:03 Should we encourage that the return values of thes
gab 2016/06/27 18:48:23 I would like for implementations of this to look s
fdoray 2016/06/27 19:45:04 I now use an enum. Not sure that an enum class tha
+ return traits.priority() == TaskPriority::BACKGROUND ? 0U : 2U;
+}
+
+class TaskSchedulerImplTest
+ : public testing::TestWithParam<TraitsExecutionModePair> {
+ protected:
+ TaskSchedulerImplTest() = default;
+
+ void SetUp() override {
+ using IORestriction = SchedulerWorkerPoolImpl::IORestriction;
+
+ std::vector<TaskSchedulerImpl::WorkerPoolCreationArgs>
robliao 2016/06/23 22:37:03 Since the vector is set up at the get go, we can m
fdoray 2016/06/27 19:45:05 The vector can no longer be const.
robliao 2016/06/28 00:24:24 An alternative is to do a post examination of the
fdoray 2016/06/28 15:23:58 I prefer not to define operator== just for this.
+ worker_pool_creation_args{
gab 2016/06/27 18:48:23 Space before '{' or is no space the style for thes
fdoray 2016/06/27 19:45:05 git cl format removes the space when I add it...
+ {"TaskSchedulerBackground", ThreadPriority::BACKGROUND,
+ IORestriction::DISALLOWED, 1U},
+ {"TaskSchedulerBackgroundFileIO", ThreadPriority::BACKGROUND,
+ IORestriction::ALLOWED, 3U},
+ {"TaskSchedulerForeground", ThreadPriority::NORMAL,
+ IORestriction::DISALLOWED, 4U},
+ {"TaskSchedulerForegroundFileIO", ThreadPriority::NORMAL,
+ IORestriction::ALLOWED, 12U},
gab 2016/06/27 18:48:23 Reinforcing my comment above: I think impls should
fdoray 2016/06/27 19:45:05 Done.
+ };
+
+ scheduler_ = TaskSchedulerImpl::Create(worker_pool_creation_args,
+ Bind(&GetThreadPoolIndexForTraits));
+ EXPECT_TRUE(scheduler_);
robliao 2016/06/23 22:37:03 This should probably be an ASSERT since the guaran
gab 2016/06/27 18:48:23 Agreed, plus the rest of the test is meaningless i
fdoray 2016/06/27 19:45:05 Done.
+ }
+
+ 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 +216,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 +229,6 @@ TEST(TaskSchedulerImplTest, MultipleTraitsExecutionModePairs) {
thread->WaitForAllTasksToRun();
thread->Join();
}
-
- scheduler->JoinForTesting();
}
// TODO(fdoray): Add tests with Sequences that move around worker pools once
« base/task_scheduler/task_scheduler_impl.cc ('K') | « 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