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

Unified Diff: components/scheduler/child/task_queue_manager_unittest.cc

Issue 1287003003: [scheduler]: Fix a bug with non-nestable tasks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add comment Created 5 years, 4 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 | « components/scheduler/child/task_queue_manager.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/scheduler/child/task_queue_manager_unittest.cc
diff --git a/components/scheduler/child/task_queue_manager_unittest.cc b/components/scheduler/child/task_queue_manager_unittest.cc
index f7d4b263e41af74505abfcbff15698a83d165b8d..7a52a0311c537a57d012183719d63e46c3130c4e 100644
--- a/components/scheduler/child/task_queue_manager_unittest.cc
+++ b/components/scheduler/child/task_queue_manager_unittest.cc
@@ -181,6 +181,53 @@ TEST_F(TaskQueueManagerTest, NonNestableTaskDoesntExecuteInNestedLoop) {
EXPECT_THAT(run_order, ElementsAre(1, 2, 4, 5, 3));
}
+void RepostOnceTestTask(scoped_refptr<base::SingleThreadTaskRunner> runner,
+ int value, std::vector<int>* out_result) {
+ out_result->push_back(value);
+ runner->PostTask(FROM_HERE, base::Bind(&NullTask));
+}
+
+void PostFromNestedRunloopWithAfterWakeupQueue(
+ base::MessageLoop* message_loop,
+ base::SingleThreadTaskRunner* after_wakeup_runner,
+ base::SingleThreadTaskRunner* wakeup_runner,
+ std::vector<std::pair<base::Closure, bool>>* tasks) {
+ base::MessageLoop::ScopedNestableTaskAllower allow(message_loop);
+ for (std::pair<base::Closure, bool>& pair : *tasks) {
+ if (pair.second) {
+ after_wakeup_runner->PostTask(FROM_HERE, pair.first);
+ } else {
+ after_wakeup_runner->PostNonNestableTask(FROM_HERE, pair.first);
+ }
+ }
+ // Post a task to wake up the after wakeup queue.
+ wakeup_runner->PostTask(FROM_HERE, base::Bind(&NullTask));
+ message_loop->RunUntilIdle();
+}
+
+TEST_F(TaskQueueManagerTest, NonNestableTaskUsesPreviousTaskForUpdateQueues) {
+ InitializeWithRealMessageLoop(2u);
+ runners_[0]->SetPumpPolicy(TaskQueue::PumpPolicy::AFTER_WAKEUP);
+
+ std::vector<int> run_order;
+ std::vector<std::pair<base::Closure, bool>> tasks_to_post_from_nested_loop;
+ // This task posts a task, so that there is something in the incoming queue
+ // of the after wakeup task queue when the non-nestable task runs.
+ tasks_to_post_from_nested_loop.push_back(std::make_pair(
+ base::Bind(&RepostOnceTestTask, runners_[0], 1, &run_order), true));
+ tasks_to_post_from_nested_loop.push_back(
+ std::make_pair(base::Bind(&TestTask, 2, &run_order), false));
+
+ runners_[1]->PostTask(
+ FROM_HERE,
+ base::Bind(&PostFromNestedRunloopWithAfterWakeupQueue,
+ message_loop_.get(), runners_[0], runners_[1],
+ base::Unretained(&tasks_to_post_from_nested_loop)));
+
+ message_loop_->RunUntilIdle();
+ EXPECT_THAT(run_order, ElementsAre(1, 2));
+}
+
TEST_F(TaskQueueManagerTest, QueuePolling) {
Initialize(1u);
« no previous file with comments | « components/scheduler/child/task_queue_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698