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

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

Issue 2628313004: Add TaskScheduler::JoinForTesting(). (Closed)
Patch Set: self-review Created 3 years, 11 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
« no previous file with comments | « base/test/scoped_task_scheduler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/message_loop/message_loop.h" 16 #include "base/message_loop/message_loop.h"
17 #include "base/stl_util.h" 17 #include "base/stl_util.h"
18 #include "base/synchronization/condition_variable.h" 18 #include "base/synchronization/condition_variable.h"
19 #include "base/synchronization/lock.h" 19 #include "base/synchronization/lock.h"
20 #include "base/task_scheduler/scheduler_worker_pool_params.h" 20 #include "base/task_scheduler/scheduler_worker_pool_params.h"
21 #include "base/task_scheduler/task_scheduler.h" 21 #include "base/task_scheduler/task_scheduler.h"
22 #include "base/task_scheduler/task_scheduler_impl.h"
23 #include "base/test/sequenced_task_runner_test_template.h" 22 #include "base/test/sequenced_task_runner_test_template.h"
24 #include "base/test/sequenced_worker_pool_owner.h" 23 #include "base/test/sequenced_worker_pool_owner.h"
25 #include "base/test/task_runner_test_template.h" 24 #include "base/test/task_runner_test_template.h"
26 #include "base/test/test_timeouts.h" 25 #include "base/test/test_timeouts.h"
27 #include "base/threading/platform_thread.h" 26 #include "base/threading/platform_thread.h"
28 #include "base/time/time.h" 27 #include "base/time/time.h"
29 #include "base/tracked_objects.h" 28 #include "base/tracked_objects.h"
30 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
31 30
32 namespace base { 31 namespace base {
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 } 288 }
290 TestTracker* tracker() { return tracker_.get(); } 289 TestTracker* tracker() { return tracker_.get(); }
291 290
292 // Waits until no tasks are running in the SequencedWorkerPool and no 291 // Waits until no tasks are running in the SequencedWorkerPool and no
293 // reference to it remain. Then, destroys the SequencedWorkerPool. 292 // reference to it remain. Then, destroys the SequencedWorkerPool.
294 void DeletePool() { pool_owner_.reset(); } 293 void DeletePool() { pool_owner_.reset(); }
295 294
296 // Destroys and unregisters the registered TaskScheduler, if any. 295 // Destroys and unregisters the registered TaskScheduler, if any.
297 void DeleteTaskScheduler() { 296 void DeleteTaskScheduler() {
298 if (TaskScheduler::GetInstance()) { 297 if (TaskScheduler::GetInstance()) {
299 static_cast<internal::TaskSchedulerImpl*>(TaskScheduler::GetInstance()) 298 TaskScheduler::GetInstance()->JoinForTesting();
300 ->JoinForTesting();
301 TaskScheduler::SetInstance(nullptr); 299 TaskScheduler::SetInstance(nullptr);
302 } 300 }
303 } 301 }
304 302
305 void SetWillWaitForShutdownCallback(const Closure& callback) { 303 void SetWillWaitForShutdownCallback(const Closure& callback) {
306 pool_owner_->SetWillWaitForShutdownCallback(callback); 304 pool_owner_->SetWillWaitForShutdownCallback(callback);
307 } 305 }
308 306
309 // Ensures that the given number of worker threads is created by adding 307 // Ensures that the given number of worker threads is created by adding
310 // tasks and waiting until they complete. Worker thread creation is 308 // tasks and waiting until they complete. Worker thread creation is
(...skipping 929 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 SequencedWorkerPoolSequencedTaskRunner, SequencedTaskRunnerTest, 1238 SequencedWorkerPoolSequencedTaskRunner, SequencedTaskRunnerTest,
1241 SequencedWorkerPoolSequencedTaskRunnerTestDelegate); 1239 SequencedWorkerPoolSequencedTaskRunnerTestDelegate);
1242 INSTANTIATE_TYPED_TEST_CASE_P( 1240 INSTANTIATE_TYPED_TEST_CASE_P(
1243 SequencedWorkerPoolSequencedTaskRunner, 1241 SequencedWorkerPoolSequencedTaskRunner,
1244 SequencedTaskRunnerDelayedTest, 1242 SequencedTaskRunnerDelayedTest,
1245 SequencedWorkerPoolSequencedTaskRunnerTestDelegate); 1243 SequencedWorkerPoolSequencedTaskRunnerTestDelegate);
1246 1244
1247 } // namespace 1245 } // namespace
1248 1246
1249 } // namespace base 1247 } // namespace base
OLDNEW
« no previous file with comments | « base/test/scoped_task_scheduler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698