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

Side by Side Diff: base/threading/sequenced_worker_pool_unittest.cc

Issue 2445763002: Disallow posting tasks to SequencedWorkerPools by default. (Closed)
Patch Set: self-review Created 4 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/threading/sequenced_worker_pool.h" 5 #include "base/threading/sequenced_worker_pool.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 void SetUp() override { 246 void SetUp() override {
247 if (RedirectedToTaskScheduler()) { 247 if (RedirectedToTaskScheduler()) {
248 std::vector<SchedulerWorkerPoolParams> worker_pool_params; 248 std::vector<SchedulerWorkerPoolParams> worker_pool_params;
249 worker_pool_params.emplace_back( 249 worker_pool_params.emplace_back(
250 "SchedulerWorkerPoolName", ThreadPriority::NORMAL, 250 "SchedulerWorkerPoolName", ThreadPriority::NORMAL,
251 SchedulerWorkerPoolParams::IORestriction::ALLOWED, kNumWorkerThreads, 251 SchedulerWorkerPoolParams::IORestriction::ALLOWED, kNumWorkerThreads,
252 TimeDelta::Max()); 252 TimeDelta::Max());
253 TaskScheduler::CreateAndSetDefaultTaskScheduler( 253 TaskScheduler::CreateAndSetDefaultTaskScheduler(
254 std::move(worker_pool_params), 254 std::move(worker_pool_params),
255 base::Bind([](const TaskTraits&) -> size_t { return 0U; })); 255 base::Bind([](const TaskTraits&) -> size_t { return 0U; }));
256 SequencedWorkerPool::ResetRedirectToTaskSchedulerForProcessForTesting(); 256
257 SequencedWorkerPool::RedirectToTaskSchedulerForProcess(); 257 // Unit tests run in an environment where SequencedWorkerPool is enabled
258 // without redirection to TaskScheduler. For the current unit test,
259 // disable it and re-enable it with redirection to TaskScheduler.
260 SequencedWorkerPool::DisableForProcessForTesting();
261 SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess();
258 } 262 }
259 } 263 }
260 264
261 void TearDown() override { 265 void TearDown() override {
262 // Wait until all references to the SequencedWorkerPool are gone and destroy 266 // Wait until all references to the SequencedWorkerPool are gone and destroy
263 // it. This must be done before destroying the TaskScheduler. Otherwise, the 267 // it. This must be done before destroying the TaskScheduler. Otherwise, the
264 // SequencedWorkerPool could try to redirect tasks to a destroyed 268 // SequencedWorkerPool could try to redirect tasks to a destroyed
265 // TaskScheduler. 269 // TaskScheduler.
266 DeletePool(); 270 DeletePool();
267 271
268 if (RedirectedToTaskScheduler()) { 272 if (RedirectedToTaskScheduler()) {
269 SequencedWorkerPool::ResetRedirectToTaskSchedulerForProcessForTesting(); 273 // Reset SequencedWorkerPool to its original state (i.e. enabled without
274 // redirection to TaskScheduler).
275 SequencedWorkerPool::DisableForProcessForTesting();
276 SequencedWorkerPool::EnableForProcess();
277
278 // Delete the registered TaskScheduler.
270 DeleteTaskScheduler(); 279 DeleteTaskScheduler();
271 } 280 }
272 } 281 }
273 282
274 bool RedirectedToTaskScheduler() const { 283 bool RedirectedToTaskScheduler() const {
275 return GetParam() == SequencedWorkerPoolRedirection::TO_TASK_SCHEDULER; 284 return GetParam() == SequencedWorkerPoolRedirection::TO_TASK_SCHEDULER;
276 } 285 }
277 286
278 const scoped_refptr<SequencedWorkerPool>& pool() { 287 const scoped_refptr<SequencedWorkerPool>& pool() {
279 return pool_owner_->pool(); 288 return pool_owner_->pool();
(...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after
1231 SequencedWorkerPoolSequencedTaskRunner, SequencedTaskRunnerTest, 1240 SequencedWorkerPoolSequencedTaskRunner, SequencedTaskRunnerTest,
1232 SequencedWorkerPoolSequencedTaskRunnerTestDelegate); 1241 SequencedWorkerPoolSequencedTaskRunnerTestDelegate);
1233 INSTANTIATE_TYPED_TEST_CASE_P( 1242 INSTANTIATE_TYPED_TEST_CASE_P(
1234 SequencedWorkerPoolSequencedTaskRunner, 1243 SequencedWorkerPoolSequencedTaskRunner,
1235 SequencedTaskRunnerDelayedTest, 1244 SequencedTaskRunnerDelayedTest,
1236 SequencedWorkerPoolSequencedTaskRunnerTestDelegate); 1245 SequencedWorkerPoolSequencedTaskRunnerTestDelegate);
1237 1246
1238 } // namespace 1247 } // namespace
1239 1248
1240 } // namespace base 1249 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698