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

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

Issue 2893823003: Flush all TaskScheduler<->MainLoop tasks in ~TestBrowserThreadBundle() (Closed)
Patch Set: . Created 3 years, 7 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
« no previous file with comments | « base/test/scoped_task_environment.cc ('k') | content/public/test/test_utils.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/test/test_browser_thread_bundle.cc
diff --git a/content/public/test/test_browser_thread_bundle.cc b/content/public/test/test_browser_thread_bundle.cc
index fbcf6fcb5186d8098296e63df675eefe2b2caf91..fa852124094dba6f75e1b1249fbb0ea098237107 100644
--- a/content/public/test/test_browser_thread_bundle.cc
+++ b/content/public/test/test_browser_thread_bundle.cc
@@ -13,6 +13,7 @@
#include "content/browser/browser_thread_impl.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_utils.h"
namespace content {
@@ -58,9 +59,19 @@ TestBrowserThreadBundle::~TestBrowserThreadBundle() {
ui_thread_->Stop();
base::RunLoop().RunUntilIdle();
- scoped_async_task_scheduler_.reset();
+ // This is required to ensure we run all remaining tasks in an atomic step
+ // (instead of ~ScopedAsyncTaskScheduler() followed by another
+ // RunLoop().RunUntilIdle()). Otherwise If a pending task in
+ // |scoped_async_task_scheduler_| posts to |message_loop_|, that task can then
+ // post back to |scoped_async_task_scheduler_| after the former was destroyed.
+ // This is a bit different than production where the main thread is not
+ // flushed after it's done running but this approach is preferred in unit
+ // tests as running more tasks can merely uncover more issues (e.g. if a bad
+ // tasks is posted but never blocked upon it could make a test flaky whereas
+ // by flushing we guarantee it will blow up).
+ RunAllBlockingPoolTasksUntilIdle();
- base::RunLoop().RunUntilIdle();
+ scoped_async_task_scheduler_.reset();
CHECK(base::MessageLoop::current()->IsIdleForTesting());
// |message_loop_| needs to explicitly go away before fake threads in order
« no previous file with comments | « base/test/scoped_task_environment.cc ('k') | content/public/test/test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698