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

Unified Diff: content/public/test/test_browser_thread_bundle.h

Issue 2767923002: Always use an async TaskScheduler in TestBrowserThreadBundle. (Closed)
Patch Set: self-review Created 3 years, 9 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: content/public/test/test_browser_thread_bundle.h
diff --git a/content/public/test/test_browser_thread_bundle.h b/content/public/test/test_browser_thread_bundle.h
index 970c9404ef95853db8495f154fd002210b5a0865..1476e233dda4ed0d35d270cbdcd440a3ef9ef857 100644
--- a/content/public/test/test_browser_thread_bundle.h
+++ b/content/public/test/test_browser_thread_bundle.h
@@ -9,26 +9,40 @@
// the first member variable in test classes, so it is destroyed last, and the
// test threads always exist from the perspective of other classes.
//
-// By default, all of the created TestBrowserThreads and the task scheduler will
-// be backed by a single shared MessageLoop. If a test truly needs separate
-// threads, it can do so by passing the appropriate combination of option values
-// during the TestBrowserThreadBundle construction.
+// By default, all of the created TestBrowserThreads will be backed by a single
+// shared MessageLoop. If a test truly needs separate threads, it can do so by
+// passing the appropriate combination of option values during the
+// TestBrowserThreadBundle construction. TaskScheduler and blocking pool tasks
+// always run on dedicated threads.
//
-// To synchronously run tasks posted to task scheduler or to TestBrowserThreads
-// that use the shared MessageLoop, call RunLoop::Run/RunUntilIdle() on the
-// thread where the TestBrowserThreadBundle lives. The destructor of
-// TestBrowserThreadBundle runs remaining TestBrowserThreads tasks, remaining
-// blocking pool tasks, and remaining BLOCK_SHUTDOWN task scheduler tasks.
+// To synchronously run tasks from the shared MessageLoop:
+//
+// ... until there are no undelayed tasks in the shared MessageLoop:
robliao 2017/04/03 17:53:05 Should there be this many ways to flush tasks or w
gab 2017/04/03 18:14:14 I think this distinction matters (and I'm making i
robliao 2017/04/03 18:17:27 Presented that way, I might be able to buy it. We
fdoray 2017/04/03 19:18:32 I expect most that most of the comments added in t
+// base::RunLoop::RunUntilIdle();
+//
+// ... until there are no undelayed tasks in the shared MessageLoop, in
+// TaskScheduler or in the blocking pool (excluding tasks not posted from the
+// shared MessageLoop's thread, TaskScheduler or the blocking pool):
+// content::RunAllBlockingPoolTasksUntilIdle();
+//
+// ... until a condition is met:
+// base::RunLoop run_loop;
+// RegisterCallbackToRunOnMainThreadWhenConditionIsMet(
gab 2017/04/03 18:20:30 I'm no clear on what RegisterCallbackToRunOnMainTh
fdoray 2017/04/03 19:18:32 Done.
+// base::Bind(&base::RunLoop::Quit, base::Unretained(&run_loop)));
gab 2017/04/03 18:20:30 QuitClosure
fdoray 2017/04/03 19:18:33 Done.
+// run_loop.Run();
+//
+// To wait until there are no pending undelayed tasks in TaskScheduler or in the
+// blocking pool, without running tasks from the shared MessageLoop:
+// base::TaskScheduler()->FlushForTesting();
gab 2017/04/03 18:20:30 // Note: base::SequencedWorkerPool::FlushForTestin
fdoray 2017/04/03 19:18:33 Done.
+//
+// The destructor of TestBrowserThreadBundle runs remaining TestBrowserThreads
+// tasks, remaining blocking pool tasks, and remaining BLOCK_SHUTDOWN task
+// scheduler tasks.
//
// If a test needs a MessageLoopForIO on the main thread, it should use the
-// IO_MAINLOOP option. This also allows task scheduler tasks to use
-// FileDescriptorWatcher. Most of the time, IO_MAINLOOP avoids needing to use a
+// IO_MAINLOOP option. Most of the time, IO_MAINLOOP avoids needing to use a
// REAL_IO_THREAD.
//
-// If a test needs a TaskScheduler that runs tasks on a dedicated thread, it
-// should use REAL_TASK_SCHEDULER. Usage of this option should be justified as
-// it is easier to understand and debug a single-threaded unit test.
-//
// For some tests it is important to emulate real browser startup. During real
// browser startup, the main MessageLoop is created before other threads.
// Passing DONT_CREATE_THREADS to constructor will delay creating other threads
@@ -48,7 +62,6 @@ namespace base {
class MessageLoop;
namespace test {
class ScopedAsyncTaskScheduler;
-class ScopedTaskScheduler;
} // namespace test
} // namespace base
@@ -67,8 +80,7 @@ class TestBrowserThreadBundle {
REAL_DB_THREAD = 1 << 1,
REAL_FILE_THREAD = 1 << 2,
REAL_IO_THREAD = 1 << 3,
- REAL_TASK_SCHEDULER = 1 << 4,
- DONT_CREATE_THREADS = 1 << 5,
+ DONT_CREATE_THREADS = 1 << 4,
};
TestBrowserThreadBundle();
@@ -86,7 +98,6 @@ class TestBrowserThreadBundle {
std::unique_ptr<base::MessageLoop> message_loop_;
std::unique_ptr<base::test::ScopedAsyncTaskScheduler>
scoped_async_task_scheduler_;
- std::unique_ptr<base::test::ScopedTaskScheduler> scoped_task_scheduler_;
std::unique_ptr<TestBrowserThread> ui_thread_;
std::unique_ptr<TestBrowserThread> db_thread_;
std::unique_ptr<TestBrowserThread> file_thread_;

Powered by Google App Engine
This is Rietveld 408576698