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

Side by Side Diff: components/scheduler/base/task_queue_manager_unittest.cc

Issue 1441073006: Move throttling of background timers into the renderer scheduler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Try again for MSVC Created 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/scheduler/base/task_queue_manager.h" 5 #include "components/scheduler/base/task_queue_manager.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/test/simple_test_tick_clock.h" 10 #include "base/test/simple_test_tick_clock.h"
(...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 delay1); 1088 delay1);
1089 runners_[1]->PostDelayedTask(FROM_HERE, base::Bind(&TestTask, 2, &run_order), 1089 runners_[1]->PostDelayedTask(FROM_HERE, base::Bind(&TestTask, 2, &run_order),
1090 delay2); 1090 delay2);
1091 1091
1092 now_src_->Advance(delay1 * 2); 1092 now_src_->Advance(delay1 * 2);
1093 test_task_runner_->RunUntilIdle(); 1093 test_task_runner_->RunUntilIdle();
1094 1094
1095 EXPECT_THAT(run_order, ElementsAre(2, 1)); 1095 EXPECT_THAT(run_order, ElementsAre(2, 1));
1096 } 1096 }
1097 1097
1098 TEST_F(TaskQueueManagerTest, DelayedTaskWithAbsoluteRunTime) {
1099 Initialize(1u);
1100
1101 // One task in the past, two with the exact same run time and one in the
1102 // future.
1103 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(10);
1104 base::TimeTicks runTime1 = now_src_->NowTicks() - delay;
1105 base::TimeTicks runTime2 = now_src_->NowTicks();
1106 base::TimeTicks runTime3 = now_src_->NowTicks();
1107 base::TimeTicks runTime4 = now_src_->NowTicks() + delay;
1108
1109 std::vector<int> run_order;
1110 runners_[0]->PostDelayedTaskAt(
1111 FROM_HERE, base::Bind(&TestTask, 1, &run_order), runTime1);
1112 runners_[0]->PostDelayedTaskAt(
1113 FROM_HERE, base::Bind(&TestTask, 2, &run_order), runTime2);
1114 runners_[0]->PostDelayedTaskAt(
1115 FROM_HERE, base::Bind(&TestTask, 3, &run_order), runTime3);
1116 runners_[0]->PostDelayedTaskAt(
1117 FROM_HERE, base::Bind(&TestTask, 4, &run_order), runTime4);
1118
1119 now_src_->Advance(2 * delay);
1120 test_task_runner_->RunUntilIdle();
1121
1122 EXPECT_THAT(run_order, ElementsAre(1, 2, 3, 4));
1123 }
1124
1125 void CheckIsNested(bool* is_nested) { 1098 void CheckIsNested(bool* is_nested) {
1126 *is_nested = base::MessageLoop::current()->IsNested(); 1099 *is_nested = base::MessageLoop::current()->IsNested();
1127 } 1100 }
1128 1101
1129 void PostAndQuitFromNestedRunloop(base::RunLoop* run_loop, 1102 void PostAndQuitFromNestedRunloop(base::RunLoop* run_loop,
1130 base::SingleThreadTaskRunner* runner, 1103 base::SingleThreadTaskRunner* runner,
1131 bool* was_nested) { 1104 bool* was_nested) {
1132 base::MessageLoop::ScopedNestableTaskAllower allow( 1105 base::MessageLoop::ScopedNestableTaskAllower allow(
1133 base::MessageLoop::current()); 1106 base::MessageLoop::current());
1134 runner->PostTask(FROM_HERE, run_loop->QuitClosure()); 1107 runner->PostTask(FROM_HERE, run_loop->QuitClosure());
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1309 1282
1310 scoped_refptr<internal::TaskQueueImpl> task_queue = 1283 scoped_refptr<internal::TaskQueueImpl> task_queue =
1311 manager_->NewTaskQueue(TaskQueue::Spec("test_queue")); 1284 manager_->NewTaskQueue(TaskQueue::Spec("test_queue"));
1312 1285
1313 EXPECT_CALL(observer, OnUnregisterTaskQueue(_)).Times(1); 1286 EXPECT_CALL(observer, OnUnregisterTaskQueue(_)).Times(1);
1314 task_queue->UnregisterTaskQueue(); 1287 task_queue->UnregisterTaskQueue();
1315 1288
1316 manager_->SetObserver(nullptr); 1289 manager_->SetObserver(nullptr);
1317 } 1290 }
1318 1291
1319 TEST_F(TaskQueueManagerTest, ScheduleDelayedWorkIsNotReEntrant) {
1320 Initialize(1u);
1321
1322 // Post two tasks into the past. The second one used to trigger a deadlock
1323 // because it tried to re-entrantly wake the first task in the same queue.
1324 runners_[0]->PostDelayedTaskAt(
1325 FROM_HERE, base::Bind(&NullTask),
1326 base::TimeTicks() + base::TimeDelta::FromMicroseconds(100));
1327 runners_[0]->PostDelayedTaskAt(
1328 FROM_HERE, base::Bind(&NullTask),
1329 base::TimeTicks() + base::TimeDelta::FromMicroseconds(200));
1330 test_task_runner_->RunUntilIdle();
1331 }
1332
1333 void HasOneRefTask(std::vector<bool>* log, internal::TaskQueueImpl* tq) { 1292 void HasOneRefTask(std::vector<bool>* log, internal::TaskQueueImpl* tq) {
1334 log->push_back(tq->HasOneRef()); 1293 log->push_back(tq->HasOneRef());
1335 } 1294 }
1336 1295
1337 TEST_F(TaskQueueManagerTest, UnregisterTaskQueueInNestedLoop) { 1296 TEST_F(TaskQueueManagerTest, UnregisterTaskQueueInNestedLoop) {
1338 InitializeWithRealMessageLoop(1u); 1297 InitializeWithRealMessageLoop(1u);
1339 1298
1340 // We retain a reference to the task queue even when the manager has deleted 1299 // We retain a reference to the task queue even when the manager has deleted
1341 // its reference. 1300 // its reference.
1342 scoped_refptr<internal::TaskQueueImpl> task_queue = 1301 scoped_refptr<internal::TaskQueueImpl> task_queue =
(...skipping 27 matching lines...) Expand all
1370 // release its reference, and checks that it has. 1329 // release its reference, and checks that it has.
1371 runners_[0]->PostTask(FROM_HERE, 1330 runners_[0]->PostTask(FROM_HERE,
1372 base::Bind(&HasOneRefTask, base::Unretained(&log), 1331 base::Bind(&HasOneRefTask, base::Unretained(&log),
1373 base::Unretained(task_queue.get()))); 1332 base::Unretained(task_queue.get())));
1374 message_loop_->RunUntilIdle(); 1333 message_loop_->RunUntilIdle();
1375 1334
1376 EXPECT_THAT(log, ElementsAre(false, false, true)); 1335 EXPECT_THAT(log, ElementsAre(false, false, true));
1377 } 1336 }
1378 1337
1379 } // namespace scheduler 1338 } // namespace scheduler
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698