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

Unified Diff: base/test/scoped_async_task_scheduler.h

Issue 2622633004: Add base::test::ScopedAsyncTaskScheduler. (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 side-by-side diff with in-line comments
Download patch
Index: base/test/scoped_async_task_scheduler.h
diff --git a/base/test/scoped_async_task_scheduler.h b/base/test/scoped_async_task_scheduler.h
new file mode 100644
index 0000000000000000000000000000000000000000..16a1406eca001139fb2f740adbcb98d9fb3ee184
--- /dev/null
+++ b/base/test/scoped_async_task_scheduler.h
@@ -0,0 +1,42 @@
+// Copyright 2017 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.
+
+#ifndef BASE_TEST_SCOPED_ASYNC_TASK_SCHEDULER_H_
+#define BASE_TEST_SCOPED_ASYNC_TASK_SCHEDULER_H_
+
+#include "base/macros.h"
+
+namespace base {
+
+class TaskScheduler;
+
+namespace test {
+
+// Allows usage of the base/task_scheduler/post_task.h API within its scope.
+// Tasks run asynchronously, one at a time.
+//
+// To wait until all posted tasks have run, use
+// TaskScheduler::GetInstance()->FlushForTesting().
+//
+// When possible, use ScopedTaskScheduler instead of this. Tasks posted within
+// the scope of a ScopedTaskScheduler run synchronously, which makes tests more
+// deterministic.
gab 2017/01/09 19:55:46 Does it really make them more deterministic? If th
fdoray 2017/01/09 20:23:48 Done. Note: With a ScopedAsyncTaskScheduler, the
+class ScopedAsyncTaskScheduler {
+ public:
+ // Registers a single-threaded TaskScheduler.
+ ScopedAsyncTaskScheduler();
+
+ // Shuts down and unregisters the TaskScheduler.
+ ~ScopedAsyncTaskScheduler();
+
+ private:
+ const TaskScheduler* task_scheduler_ = nullptr;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedAsyncTaskScheduler);
+};
+
+} // namespace test
+} // namespace base
+
+#endif // BASE_TEST_SCOPED_ASYNC_TASK_SCHEDULER_H_

Powered by Google App Engine
This is Rietveld 408576698