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

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

Issue 2116163002: Add Lazy Creation and Thread Detachment Support in the Scheduler Worker Pool (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR Feedback Continuation 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/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 <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
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/synchronization/waitable_event.h" 18 #include "base/synchronization/waitable_event.h"
19 #include "base/task_scheduler/scheduler_worker_pool_params.h" 19 #include "base/task_scheduler/scheduler_worker_pool_params.h"
20 #include "base/task_scheduler/task_traits.h" 20 #include "base/task_scheduler/task_traits.h"
21 #include "base/task_scheduler/test_task_factory.h" 21 #include "base/task_scheduler/test_task_factory.h"
22 #include "base/threading/platform_thread.h" 22 #include "base/threading/platform_thread.h"
23 #include "base/threading/simple_thread.h" 23 #include "base/threading/simple_thread.h"
24 #include "base/threading/thread.h" 24 #include "base/threading/thread.h"
25 #include "base/threading/thread_restrictions.h" 25 #include "base/threading/thread_restrictions.h"
26 #include "base/time/time.h"
26 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
27 28
28 namespace base { 29 namespace base {
29 namespace internal { 30 namespace internal {
30 31
31 namespace { 32 namespace {
32 33
33 struct TraitsExecutionModePair { 34 struct TraitsExecutionModePair {
34 TraitsExecutionModePair(const TaskTraits& traits, 35 TraitsExecutionModePair(const TaskTraits& traits,
35 ExecutionMode execution_mode) 36 ExecutionMode execution_mode)
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 protected: 159 protected:
159 TaskSchedulerImplTest() = default; 160 TaskSchedulerImplTest() = default;
160 161
161 void SetUp() override { 162 void SetUp() override {
162 using IORestriction = SchedulerWorkerPoolParams::IORestriction; 163 using IORestriction = SchedulerWorkerPoolParams::IORestriction;
163 164
164 std::vector<SchedulerWorkerPoolParams> params; 165 std::vector<SchedulerWorkerPoolParams> params;
165 166
166 ASSERT_EQ(BACKGROUND_WORKER_POOL, params.size()); 167 ASSERT_EQ(BACKGROUND_WORKER_POOL, params.size());
167 params.emplace_back("TaskSchedulerBackground", ThreadPriority::BACKGROUND, 168 params.emplace_back("TaskSchedulerBackground", ThreadPriority::BACKGROUND,
168 IORestriction::DISALLOWED, 1U); 169 IORestriction::DISALLOWED, 1U, TimeDelta::Max());
169 170
170 ASSERT_EQ(BACKGROUND_FILE_IO_WORKER_POOL, params.size()); 171 ASSERT_EQ(BACKGROUND_FILE_IO_WORKER_POOL, params.size());
171 params.emplace_back("TaskSchedulerBackgroundFileIO", 172 params.emplace_back("TaskSchedulerBackgroundFileIO",
172 ThreadPriority::BACKGROUND, IORestriction::ALLOWED, 3U); 173 ThreadPriority::BACKGROUND, IORestriction::ALLOWED, 3U,
174 TimeDelta::Max());
173 175
174 ASSERT_EQ(FOREGROUND_WORKER_POOL, params.size()); 176 ASSERT_EQ(FOREGROUND_WORKER_POOL, params.size());
175 params.emplace_back("TaskSchedulerForeground", ThreadPriority::NORMAL, 177 params.emplace_back("TaskSchedulerForeground", ThreadPriority::NORMAL,
176 IORestriction::DISALLOWED, 4U); 178 IORestriction::DISALLOWED, 4U, TimeDelta::Max());
177 179
178 ASSERT_EQ(FOREGROUND_FILE_IO_WORKER_POOL, params.size()); 180 ASSERT_EQ(FOREGROUND_FILE_IO_WORKER_POOL, params.size());
179 params.emplace_back("TaskSchedulerForegroundFileIO", ThreadPriority::NORMAL, 181 params.emplace_back("TaskSchedulerForegroundFileIO", ThreadPriority::NORMAL,
180 IORestriction::ALLOWED, 12U); 182 IORestriction::ALLOWED, 12U, TimeDelta::Max());
181 183
182 scheduler_ = TaskSchedulerImpl::Create(params, 184 scheduler_ = TaskSchedulerImpl::Create(params,
183 Bind(&GetThreadPoolIndexForTraits)); 185 Bind(&GetThreadPoolIndexForTraits));
184 ASSERT_TRUE(scheduler_); 186 ASSERT_TRUE(scheduler_);
185 } 187 }
186 188
187 void TearDown() override { scheduler_->JoinForTesting(); } 189 void TearDown() override { scheduler_->JoinForTesting(); }
188 190
189 std::unique_ptr<TaskSchedulerImpl> scheduler_; 191 std::unique_ptr<TaskSchedulerImpl> scheduler_;
190 192
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 thread->WaitForAllTasksToRun(); 249 thread->WaitForAllTasksToRun();
248 thread->Join(); 250 thread->Join();
249 } 251 }
250 } 252 }
251 253
252 // TODO(fdoray): Add tests with Sequences that move around worker pools once 254 // TODO(fdoray): Add tests with Sequences that move around worker pools once
253 // child TaskRunners are supported. 255 // child TaskRunners are supported.
254 256
255 } // namespace internal 257 } // namespace internal
256 } // namespace base 258 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698