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

Side by Side 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: 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 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/task_scheduler_impl.h" 5 #include "base/task_scheduler/task_scheduler_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <map>
9 #include <string> 10 #include <string>
10 #include <utility> 11 #include <utility>
11 #include <vector> 12 #include <vector>
12 13
13 #include "base/bind.h" 14 #include "base/bind.h"
14 #include "base/bind_helpers.h" 15 #include "base/bind_helpers.h"
15 #include "base/callback.h" 16 #include "base/callback.h"
16 #include "base/macros.h" 17 #include "base/macros.h"
17 #include "base/memory/ptr_util.h" 18 #include "base/memory/ptr_util.h"
18 #include "base/synchronization/waitable_event.h" 19 #include "base/synchronization/waitable_event.h"
(...skipping 18 matching lines...) Expand all
37 TaskTraits traits; 38 TaskTraits traits;
38 ExecutionMode execution_mode; 39 ExecutionMode execution_mode;
39 }; 40 };
40 41
41 class TaskSchedulerImplTest 42 class TaskSchedulerImplTest
42 : public testing::TestWithParam<TraitsExecutionModePair> { 43 : public testing::TestWithParam<TraitsExecutionModePair> {
43 protected: 44 protected:
44 TaskSchedulerImplTest() = default; 45 TaskSchedulerImplTest() = default;
45 46
46 void SetUp() override { 47 void SetUp() override {
47 scheduler_ = TaskSchedulerImpl::Create(); 48 scheduler_ =
49 TaskSchedulerImpl::Create(std::map<std::string, std::string>());
48 EXPECT_TRUE(scheduler_); 50 EXPECT_TRUE(scheduler_);
49 } 51 }
50 void TearDown() override { scheduler_->JoinForTesting(); } 52 void TearDown() override { scheduler_->JoinForTesting(); }
51 53
52 std::unique_ptr<TaskSchedulerImpl> scheduler_; 54 std::unique_ptr<TaskSchedulerImpl> scheduler_;
53 55
54 private: 56 private:
55 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerImplTest); 57 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerImplTest);
56 }; 58 };
57 59
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 190
189 INSTANTIATE_TEST_CASE_P(OneTraitsExecutionModePair, 191 INSTANTIATE_TEST_CASE_P(OneTraitsExecutionModePair,
190 TaskSchedulerImplTest, 192 TaskSchedulerImplTest,
191 ::testing::ValuesIn(GetTraitsExecutionModePairs())); 193 ::testing::ValuesIn(GetTraitsExecutionModePairs()));
192 194
193 // Spawns threads that simultaneously post Tasks to TaskRunners with various 195 // Spawns threads that simultaneously post Tasks to TaskRunners with various
194 // TaskTraits and ExecutionModes. Verifies that each Task runs on a thread with 196 // TaskTraits and ExecutionModes. Verifies that each Task runs on a thread with
195 // the expected priority and I/O restrictions and respects the characteristics 197 // the expected priority and I/O restrictions and respects the characteristics
196 // of its ExecutionMode. 198 // of its ExecutionMode.
197 TEST(TaskSchedulerImplTest, MultipleTraitsExecutionModePairs) { 199 TEST(TaskSchedulerImplTest, MultipleTraitsExecutionModePairs) {
198 std::unique_ptr<TaskSchedulerImpl> scheduler = TaskSchedulerImpl::Create(); 200 std::unique_ptr<TaskSchedulerImpl> scheduler =
201 TaskSchedulerImpl::Create(std::map<std::string, std::string>());
199 202
200 std::vector<std::unique_ptr<ThreadPostingTasks>> threads_posting_tasks; 203 std::vector<std::unique_ptr<ThreadPostingTasks>> threads_posting_tasks;
201 for (const auto& traits_execution_mode_pair : GetTraitsExecutionModePairs()) { 204 for (const auto& traits_execution_mode_pair : GetTraitsExecutionModePairs()) {
202 threads_posting_tasks.push_back(WrapUnique(new ThreadPostingTasks( 205 threads_posting_tasks.push_back(WrapUnique(new ThreadPostingTasks(
203 scheduler.get(), traits_execution_mode_pair.traits, 206 scheduler.get(), traits_execution_mode_pair.traits,
204 traits_execution_mode_pair.execution_mode))); 207 traits_execution_mode_pair.execution_mode)));
205 threads_posting_tasks.back()->Start(); 208 threads_posting_tasks.back()->Start();
206 } 209 }
207 210
208 for (const auto& thread : threads_posting_tasks) { 211 for (const auto& thread : threads_posting_tasks) {
209 thread->WaitForAllTasksToRun(); 212 thread->WaitForAllTasksToRun();
210 thread->Join(); 213 thread->Join();
211 } 214 }
212 215
213 scheduler->JoinForTesting(); 216 scheduler->JoinForTesting();
214 } 217 }
215 218
216 // TODO(fdoray): Add tests with Sequences that move around thread pools once 219 // TODO(fdoray): Add tests with Sequences that move around thread pools once
217 // child TaskRunners are supported. 220 // child TaskRunners are supported.
218 221
219 } // namespace internal 222 } // namespace internal
220 } // namespace base 223 } // namespace base
OLDNEW
« 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