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

Unified Diff: base/test/scoped_task_scheduler.cc

Issue 2511473004: Create base::test::ScopedTaskScheduler. (Closed)
Patch Set: rebase 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/test/scoped_task_scheduler.h ('k') | base/threading/sequenced_worker_pool_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/test/scoped_task_scheduler.cc
diff --git a/base/test/scoped_task_scheduler.cc b/base/test/scoped_task_scheduler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..76965378e7eadb032236d7f09d53085ceb302f68
--- /dev/null
+++ b/base/test/scoped_task_scheduler.cc
@@ -0,0 +1,29 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/test/scoped_task_scheduler.h"
+
+#include "base/task_scheduler/task_scheduler.h"
+
+namespace base {
+namespace test {
+
+ScopedTaskScheduler::ScopedTaskScheduler() {
+ DCHECK(!TaskScheduler::GetInstance());
+
+ // Create a TaskScheduler with a single thread to make tests deterministic.
+ constexpr int kMaxThreads = 1;
+ TaskScheduler::CreateAndSetSimpleTaskScheduler(kMaxThreads);
+ task_scheduler_ = TaskScheduler::GetInstance();
+}
+
+ScopedTaskScheduler::~ScopedTaskScheduler() {
+ DCHECK_EQ(task_scheduler_, TaskScheduler::GetInstance());
+ TaskScheduler::GetInstance()->Shutdown();
+ TaskScheduler::GetInstance()->JoinForTesting();
+ TaskScheduler::SetInstance(nullptr);
+}
+
+} // namespace test
+} // namespace base
« no previous file with comments | « base/test/scoped_task_scheduler.h ('k') | base/threading/sequenced_worker_pool_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698