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

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: delegate 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 50e0caeb1c7059f467376c2ac7311a3eb01e841f..e2fc882fccf10631eee660ae5c4023c3be797ffd 100644
--- a/base/task_scheduler/task_scheduler_impl_unittest.cc
+++ b/base/task_scheduler/task_scheduler_impl_unittest.cc
@@ -38,13 +38,58 @@ struct TraitsExecutionModePair {
ExecutionMode execution_mode;
};
+class TestTaskSchedulerImplDelegate : public TaskSchedulerImpl::Delegate {
+ public:
+ using ThreadPoolCreationArgs =
+ TaskSchedulerImpl::Delegate::ThreadPoolCreationArgs;
+
+ TestTaskSchedulerImplDelegate() = default;
+ ~TestTaskSchedulerImplDelegate() = default;
+
+ size_t GetNumThreadPools() override { return 4; }
+
+ ThreadPoolCreationArgs GetCreationArgsForThreadPool(size_t pool_index) {
+ switch (pool_index) {
+ case 0:
+ return ThreadPoolCreationArgs{
+ std::string("Background"), ThreadPriority::BACKGROUND,
+ SchedulerThreadPoolImpl::IORestriction::DISALLOWED, 1U};
+ case 1:
+ return ThreadPoolCreationArgs{
+ "BackgroundFileIO", ThreadPriority::BACKGROUND,
+ SchedulerThreadPoolImpl::IORestriction::ALLOWED, 3U};
+ case 2:
+ return ThreadPoolCreationArgs{
+ "Foreground", ThreadPriority::NORMAL,
+ SchedulerThreadPoolImpl::IORestriction::DISALLOWED, 4U};
+ case 3:
+ return ThreadPoolCreationArgs{
+ "ForegroundFileIO", ThreadPriority::NORMAL,
+ SchedulerThreadPoolImpl::IORestriction::ALLOWED, 12U};
+ default:
+ ADD_FAILURE() << "Requested creation args for invalid pool index.";
+ return ThreadPoolCreationArgs{};
+ }
+ }
+
+ size_t GetThreadPoolIndexForTraits(const TaskTraits& traits) override {
+ if (traits.with_file_io())
+ return traits.priority() == TaskPriority::BACKGROUND ? 1U : 3U;
+ return traits.priority() == TaskPriority::BACKGROUND ? 0U : 2U;
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TestTaskSchedulerImplDelegate);
+};
+
class TaskSchedulerImplTest
: public testing::TestWithParam<TraitsExecutionModePair> {
protected:
TaskSchedulerImplTest() = default;
void SetUp() override {
- scheduler_ = TaskSchedulerImpl::Create();
+ scheduler_ = TaskSchedulerImpl::Create(
+ WrapUnique(new TestTaskSchedulerImplDelegate));
EXPECT_TRUE(scheduler_);
}
void TearDown() override { scheduler_->JoinForTesting(); }
@@ -195,7 +240,8 @@ INSTANTIATE_TEST_CASE_P(OneTraitsExecutionModePair,
// the expected priority and I/O restrictions and respects the characteristics
// of its ExecutionMode.
TEST(TaskSchedulerImplTest, MultipleTraitsExecutionModePairs) {
- std::unique_ptr<TaskSchedulerImpl> scheduler = TaskSchedulerImpl::Create();
+ std::unique_ptr<TaskSchedulerImpl> scheduler =
+ TaskSchedulerImpl::Create(WrapUnique(new TestTaskSchedulerImplDelegate));
std::vector<std::unique_ptr<ThreadPostingTasks>> threads_posting_tasks;
for (const auto& traits_execution_mode_pair : GetTraitsExecutionModePairs()) {
« 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