| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "platform/scheduler/base/task_queue_selector.h" | 5 #include "platform/scheduler/base/task_queue_selector.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/pending_task.h" | 14 #include "base/pending_task.h" |
| 15 #include "platform/scheduler/base/task_queue_impl.h" | 15 #include "platform/scheduler/base/task_queue_impl.h" |
| 16 #include "platform/scheduler/base/virtual_time_domain.h" | 16 #include "platform/scheduler/base/virtual_time_domain.h" |
| 17 #include "platform/scheduler/base/work_queue.h" | 17 #include "platform/scheduler/base/work_queue.h" |
| 18 #include "platform/scheduler/base/work_queue_sets.h" | 18 #include "platform/scheduler/base/work_queue_sets.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 21 |
| 22 using testing::_; | 22 using ::testing::_; |
| 23 | 23 |
| 24 namespace blink { | 24 namespace blink { |
| 25 namespace scheduler { | 25 namespace scheduler { |
| 26 namespace internal { | 26 namespace internal { |
| 27 | 27 |
| 28 class MockObserver : public TaskQueueSelector::Observer { | 28 class MockObserver : public TaskQueueSelector::Observer { |
| 29 public: | 29 public: |
| 30 MockObserver() {} | 30 MockObserver() {} |
| 31 virtual ~MockObserver() {} | 31 virtual ~MockObserver() {} |
| 32 | 32 |
| 33 MOCK_METHOD1(OnTaskQueueEnabled, void(internal::TaskQueueImpl*)); | 33 MOCK_METHOD1(OnTaskQueueEnabled, void(internal::TaskQueueImpl*)); |
| 34 MOCK_METHOD1(OnTriedToSelectBlockedWorkQueue, void(internal::WorkQueue*)); | 34 MOCK_METHOD1(OnTriedToSelectBlockedWorkQueue, void(internal::WorkQueue*)); |
| 35 | 35 |
| 36 private: | 36 private: |
| 37 DISALLOW_COPY_AND_ASSIGN(MockObserver); | 37 DISALLOW_COPY_AND_ASSIGN(MockObserver); |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 class TaskQueueSelectorForTest : public TaskQueueSelector { | 40 class TaskQueueSelectorForTest : public TaskQueueSelector { |
| 41 public: | 41 public: |
| 42 using TaskQueueSelector::SetImmediateStarvationCountForTest; | 42 using TaskQueueSelector::SetImmediateStarvationCountForTest; |
| 43 using TaskQueueSelector::PrioritizingSelector; | 43 using TaskQueueSelector::PrioritizingSelector; |
| 44 using TaskQueueSelector::enabled_selector_for_test; | 44 using TaskQueueSelector::enabled_selector_for_test; |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 class TaskQueueSelectorTest : public testing::Test { | 47 class TaskQueueSelectorTest : public ::testing::Test { |
| 48 public: | 48 public: |
| 49 TaskQueueSelectorTest() | 49 TaskQueueSelectorTest() |
| 50 : test_closure_(base::Bind(&TaskQueueSelectorTest::TestFunction)) {} | 50 : test_closure_(base::Bind(&TaskQueueSelectorTest::TestFunction)) {} |
| 51 ~TaskQueueSelectorTest() override {} | 51 ~TaskQueueSelectorTest() override {} |
| 52 | 52 |
| 53 TaskQueueSelectorForTest::PrioritizingSelector* enabled_selector() { | 53 TaskQueueSelectorForTest::PrioritizingSelector* enabled_selector() { |
| 54 return selector_.enabled_selector_for_test(); | 54 return selector_.enabled_selector_for_test(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 WorkQueueSets* delayed_work_queue_sets() { | 57 WorkQueueSets* delayed_work_queue_sets() { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 base::Closure test_closure_; | 156 base::Closure test_closure_; |
| 157 TaskQueueSelectorForTest selector_; | 157 TaskQueueSelectorForTest selector_; |
| 158 std::unique_ptr<VirtualTimeDomain> virtual_time_domain_; | 158 std::unique_ptr<VirtualTimeDomain> virtual_time_domain_; |
| 159 std::vector<scoped_refptr<TaskQueueImpl>> task_queues_; | 159 std::vector<scoped_refptr<TaskQueueImpl>> task_queues_; |
| 160 std::map<TaskQueueImpl*, size_t> queue_to_index_map_; | 160 std::map<TaskQueueImpl*, size_t> queue_to_index_map_; |
| 161 }; | 161 }; |
| 162 | 162 |
| 163 TEST_F(TaskQueueSelectorTest, TestDefaultPriority) { | 163 TEST_F(TaskQueueSelectorTest, TestDefaultPriority) { |
| 164 size_t queue_order[] = {4, 3, 2, 1, 0}; | 164 size_t queue_order[] = {4, 3, 2, 1, 0}; |
| 165 PushTasks(queue_order, 5); | 165 PushTasks(queue_order, 5); |
| 166 EXPECT_THAT(PopTasks(), testing::ElementsAre(4, 3, 2, 1, 0)); | 166 EXPECT_THAT(PopTasks(), ::testing::ElementsAre(4, 3, 2, 1, 0)); |
| 167 } | 167 } |
| 168 | 168 |
| 169 TEST_F(TaskQueueSelectorTest, TestHighPriority) { | 169 TEST_F(TaskQueueSelectorTest, TestHighPriority) { |
| 170 size_t queue_order[] = {0, 1, 2, 3, 4}; | 170 size_t queue_order[] = {0, 1, 2, 3, 4}; |
| 171 PushTasks(queue_order, 5); | 171 PushTasks(queue_order, 5); |
| 172 selector_.SetQueuePriority(task_queues_[2].get(), TaskQueue::HIGH_PRIORITY); | 172 selector_.SetQueuePriority(task_queues_[2].get(), TaskQueue::HIGH_PRIORITY); |
| 173 EXPECT_THAT(PopTasks(), testing::ElementsAre(2, 0, 1, 3, 4)); | 173 EXPECT_THAT(PopTasks(), ::testing::ElementsAre(2, 0, 1, 3, 4)); |
| 174 } | 174 } |
| 175 | 175 |
| 176 TEST_F(TaskQueueSelectorTest, TestLowPriority) { | 176 TEST_F(TaskQueueSelectorTest, TestLowPriority) { |
| 177 size_t queue_order[] = {0, 1, 2, 3, 4}; | 177 size_t queue_order[] = {0, 1, 2, 3, 4}; |
| 178 PushTasks(queue_order, 5); | 178 PushTasks(queue_order, 5); |
| 179 selector_.SetQueuePriority(task_queues_[2].get(), TaskQueue::LOW_PRIORITY); | 179 selector_.SetQueuePriority(task_queues_[2].get(), TaskQueue::LOW_PRIORITY); |
| 180 EXPECT_THAT(PopTasks(), testing::ElementsAre(0, 1, 3, 4, 2)); | 180 EXPECT_THAT(PopTasks(), ::testing::ElementsAre(0, 1, 3, 4, 2)); |
| 181 } | 181 } |
| 182 | 182 |
| 183 TEST_F(TaskQueueSelectorTest, TestBestEffortPriority) { | 183 TEST_F(TaskQueueSelectorTest, TestBestEffortPriority) { |
| 184 size_t queue_order[] = {0, 1, 2, 3, 4}; | 184 size_t queue_order[] = {0, 1, 2, 3, 4}; |
| 185 PushTasks(queue_order, 5); | 185 PushTasks(queue_order, 5); |
| 186 selector_.SetQueuePriority(task_queues_[0].get(), | 186 selector_.SetQueuePriority(task_queues_[0].get(), |
| 187 TaskQueue::BEST_EFFORT_PRIORITY); | 187 TaskQueue::BEST_EFFORT_PRIORITY); |
| 188 selector_.SetQueuePriority(task_queues_[2].get(), TaskQueue::LOW_PRIORITY); | 188 selector_.SetQueuePriority(task_queues_[2].get(), TaskQueue::LOW_PRIORITY); |
| 189 selector_.SetQueuePriority(task_queues_[3].get(), TaskQueue::HIGH_PRIORITY); | 189 selector_.SetQueuePriority(task_queues_[3].get(), TaskQueue::HIGH_PRIORITY); |
| 190 EXPECT_THAT(PopTasks(), testing::ElementsAre(3, 1, 4, 2, 0)); | 190 EXPECT_THAT(PopTasks(), ::testing::ElementsAre(3, 1, 4, 2, 0)); |
| 191 } | 191 } |
| 192 | 192 |
| 193 TEST_F(TaskQueueSelectorTest, TestControlPriority) { | 193 TEST_F(TaskQueueSelectorTest, TestControlPriority) { |
| 194 size_t queue_order[] = {0, 1, 2, 3, 4}; | 194 size_t queue_order[] = {0, 1, 2, 3, 4}; |
| 195 PushTasks(queue_order, 5); | 195 PushTasks(queue_order, 5); |
| 196 selector_.SetQueuePriority(task_queues_[4].get(), | 196 selector_.SetQueuePriority(task_queues_[4].get(), |
| 197 TaskQueue::CONTROL_PRIORITY); | 197 TaskQueue::CONTROL_PRIORITY); |
| 198 EXPECT_EQ(TaskQueue::CONTROL_PRIORITY, task_queues_[4]->GetQueuePriority()); | 198 EXPECT_EQ(TaskQueue::CONTROL_PRIORITY, task_queues_[4]->GetQueuePriority()); |
| 199 selector_.SetQueuePriority(task_queues_[2].get(), TaskQueue::HIGH_PRIORITY); | 199 selector_.SetQueuePriority(task_queues_[2].get(), TaskQueue::HIGH_PRIORITY); |
| 200 EXPECT_EQ(TaskQueue::HIGH_PRIORITY, task_queues_[2]->GetQueuePriority()); | 200 EXPECT_EQ(TaskQueue::HIGH_PRIORITY, task_queues_[2]->GetQueuePriority()); |
| 201 EXPECT_THAT(PopTasks(), testing::ElementsAre(4, 2, 0, 1, 3)); | 201 EXPECT_THAT(PopTasks(), ::testing::ElementsAre(4, 2, 0, 1, 3)); |
| 202 } | 202 } |
| 203 | 203 |
| 204 TEST_F(TaskQueueSelectorTest, TestObserverWithEnabledQueue) { | 204 TEST_F(TaskQueueSelectorTest, TestObserverWithEnabledQueue) { |
| 205 std::unique_ptr<TaskQueue::QueueEnabledVoter> voter1 = | 205 std::unique_ptr<TaskQueue::QueueEnabledVoter> voter1 = |
| 206 task_queues_[1]->CreateQueueEnabledVoter(); | 206 task_queues_[1]->CreateQueueEnabledVoter(); |
| 207 DisableQueue(voter1.get()); | 207 DisableQueue(voter1.get()); |
| 208 MockObserver mock_observer; | 208 MockObserver mock_observer; |
| 209 selector_.SetTaskQueueSelectorObserver(&mock_observer); | 209 selector_.SetTaskQueueSelectorObserver(&mock_observer); |
| 210 EXPECT_CALL(mock_observer, OnTaskQueueEnabled(_)).Times(1); | 210 EXPECT_CALL(mock_observer, OnTaskQueueEnabled(_)).Times(1); |
| 211 EnableQueue(voter1.get()); | 211 EnableQueue(voter1.get()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 228 PushTasks(queue_order, 5); | 228 PushTasks(queue_order, 5); |
| 229 std::unique_ptr<TaskQueue::QueueEnabledVoter> voter2 = | 229 std::unique_ptr<TaskQueue::QueueEnabledVoter> voter2 = |
| 230 task_queues_[2]->CreateQueueEnabledVoter(); | 230 task_queues_[2]->CreateQueueEnabledVoter(); |
| 231 std::unique_ptr<TaskQueue::QueueEnabledVoter> voter4 = | 231 std::unique_ptr<TaskQueue::QueueEnabledVoter> voter4 = |
| 232 task_queues_[4]->CreateQueueEnabledVoter(); | 232 task_queues_[4]->CreateQueueEnabledVoter(); |
| 233 DisableQueue(voter2.get()); | 233 DisableQueue(voter2.get()); |
| 234 DisableQueue(voter4.get()); | 234 DisableQueue(voter4.get()); |
| 235 // Disabling a queue should not affect its priority. | 235 // Disabling a queue should not affect its priority. |
| 236 EXPECT_EQ(TaskQueue::NORMAL_PRIORITY, task_queues_[2]->GetQueuePriority()); | 236 EXPECT_EQ(TaskQueue::NORMAL_PRIORITY, task_queues_[2]->GetQueuePriority()); |
| 237 EXPECT_EQ(TaskQueue::NORMAL_PRIORITY, task_queues_[4]->GetQueuePriority()); | 237 EXPECT_EQ(TaskQueue::NORMAL_PRIORITY, task_queues_[4]->GetQueuePriority()); |
| 238 EXPECT_THAT(PopTasks(), testing::ElementsAre(0, 1, 3)); | 238 EXPECT_THAT(PopTasks(), ::testing::ElementsAre(0, 1, 3)); |
| 239 | 239 |
| 240 EXPECT_CALL(mock_observer, OnTaskQueueEnabled(_)).Times(2); | 240 EXPECT_CALL(mock_observer, OnTaskQueueEnabled(_)).Times(2); |
| 241 EnableQueue(voter2.get()); | 241 EnableQueue(voter2.get()); |
| 242 selector_.SetQueuePriority(task_queues_[2].get(), | 242 selector_.SetQueuePriority(task_queues_[2].get(), |
| 243 TaskQueue::BEST_EFFORT_PRIORITY); | 243 TaskQueue::BEST_EFFORT_PRIORITY); |
| 244 EXPECT_THAT(PopTasks(), testing::ElementsAre(2)); | 244 EXPECT_THAT(PopTasks(), ::testing::ElementsAre(2)); |
| 245 EnableQueue(voter4.get()); | 245 EnableQueue(voter4.get()); |
| 246 EXPECT_THAT(PopTasks(), testing::ElementsAre(4)); | 246 EXPECT_THAT(PopTasks(), ::testing::ElementsAre(4)); |
| 247 } | 247 } |
| 248 | 248 |
| 249 TEST_F(TaskQueueSelectorTest, TestDisableChangePriorityThenEnable) { | 249 TEST_F(TaskQueueSelectorTest, TestDisableChangePriorityThenEnable) { |
| 250 EXPECT_TRUE(task_queues_[2]->delayed_work_queue()->Empty()); | 250 EXPECT_TRUE(task_queues_[2]->delayed_work_queue()->Empty()); |
| 251 EXPECT_TRUE(task_queues_[2]->immediate_work_queue()->Empty()); | 251 EXPECT_TRUE(task_queues_[2]->immediate_work_queue()->Empty()); |
| 252 | 252 |
| 253 std::unique_ptr<TaskQueue::QueueEnabledVoter> voter2 = | 253 std::unique_ptr<TaskQueue::QueueEnabledVoter> voter2 = |
| 254 task_queues_[2]->CreateQueueEnabledVoter(); | 254 task_queues_[2]->CreateQueueEnabledVoter(); |
| 255 DisableQueue(voter2.get()); | 255 DisableQueue(voter2.get()); |
| 256 selector_.SetQueuePriority(task_queues_[2].get(), TaskQueue::HIGH_PRIORITY); | 256 selector_.SetQueuePriority(task_queues_[2].get(), TaskQueue::HIGH_PRIORITY); |
| 257 | 257 |
| 258 size_t queue_order[] = {0, 1, 2, 3, 4}; | 258 size_t queue_order[] = {0, 1, 2, 3, 4}; |
| 259 PushTasks(queue_order, 5); | 259 PushTasks(queue_order, 5); |
| 260 | 260 |
| 261 EXPECT_TRUE(task_queues_[2]->delayed_work_queue()->Empty()); | 261 EXPECT_TRUE(task_queues_[2]->delayed_work_queue()->Empty()); |
| 262 EXPECT_FALSE(task_queues_[2]->immediate_work_queue()->Empty()); | 262 EXPECT_FALSE(task_queues_[2]->immediate_work_queue()->Empty()); |
| 263 EnableQueue(voter2.get()); | 263 EnableQueue(voter2.get()); |
| 264 | 264 |
| 265 EXPECT_EQ(TaskQueue::HIGH_PRIORITY, task_queues_[2]->GetQueuePriority()); | 265 EXPECT_EQ(TaskQueue::HIGH_PRIORITY, task_queues_[2]->GetQueuePriority()); |
| 266 EXPECT_THAT(PopTasks(), testing::ElementsAre(2, 0, 1, 3, 4)); | 266 EXPECT_THAT(PopTasks(), ::testing::ElementsAre(2, 0, 1, 3, 4)); |
| 267 } | 267 } |
| 268 | 268 |
| 269 TEST_F(TaskQueueSelectorTest, TestEmptyQueues) { | 269 TEST_F(TaskQueueSelectorTest, TestEmptyQueues) { |
| 270 WorkQueue* chosen_work_queue = nullptr; | 270 WorkQueue* chosen_work_queue = nullptr; |
| 271 EXPECT_FALSE(selector_.SelectWorkQueueToService(&chosen_work_queue)); | 271 EXPECT_FALSE(selector_.SelectWorkQueueToService(&chosen_work_queue)); |
| 272 | 272 |
| 273 // Test only disabled queues. | 273 // Test only disabled queues. |
| 274 size_t queue_order[] = {0}; | 274 size_t queue_order[] = {0}; |
| 275 PushTasks(queue_order, 1); | 275 PushTasks(queue_order, 1); |
| 276 std::unique_ptr<TaskQueue::QueueEnabledVoter> voter0 = | 276 std::unique_ptr<TaskQueue::QueueEnabledVoter> voter0 = |
| 277 task_queues_[0]->CreateQueueEnabledVoter(); | 277 task_queues_[0]->CreateQueueEnabledVoter(); |
| 278 DisableQueue(voter0.get()); | 278 DisableQueue(voter0.get()); |
| 279 EXPECT_FALSE(selector_.SelectWorkQueueToService(&chosen_work_queue)); | 279 EXPECT_FALSE(selector_.SelectWorkQueueToService(&chosen_work_queue)); |
| 280 | 280 |
| 281 // These tests are unusual since there's no TQM. To avoid a later DCHECK when | 281 // These tests are unusual since there's no TQM. To avoid a later DCHECK when |
| 282 // deleting the task queue, we re-enable the queue here so the selector | 282 // deleting the task queue, we re-enable the queue here so the selector |
| 283 // doesn't get out of sync. | 283 // doesn't get out of sync. |
| 284 EnableQueue(voter0.get()); | 284 EnableQueue(voter0.get()); |
| 285 } | 285 } |
| 286 | 286 |
| 287 TEST_F(TaskQueueSelectorTest, TestAge) { | 287 TEST_F(TaskQueueSelectorTest, TestAge) { |
| 288 size_t enqueue_order[] = {10, 1, 2, 9, 4}; | 288 size_t enqueue_order[] = {10, 1, 2, 9, 4}; |
| 289 size_t queue_order[] = {0, 1, 2, 3, 4}; | 289 size_t queue_order[] = {0, 1, 2, 3, 4}; |
| 290 PushTasksWithEnqueueOrder(queue_order, enqueue_order, 5); | 290 PushTasksWithEnqueueOrder(queue_order, enqueue_order, 5); |
| 291 EXPECT_THAT(PopTasks(), testing::ElementsAre(1, 2, 4, 3, 0)); | 291 EXPECT_THAT(PopTasks(), ::testing::ElementsAre(1, 2, 4, 3, 0)); |
| 292 } | 292 } |
| 293 | 293 |
| 294 TEST_F(TaskQueueSelectorTest, TestControlStarvesOthers) { | 294 TEST_F(TaskQueueSelectorTest, TestControlStarvesOthers) { |
| 295 size_t queue_order[] = {0, 1, 2, 3}; | 295 size_t queue_order[] = {0, 1, 2, 3}; |
| 296 PushTasks(queue_order, 4); | 296 PushTasks(queue_order, 4); |
| 297 selector_.SetQueuePriority(task_queues_[3].get(), | 297 selector_.SetQueuePriority(task_queues_[3].get(), |
| 298 TaskQueue::CONTROL_PRIORITY); | 298 TaskQueue::CONTROL_PRIORITY); |
| 299 selector_.SetQueuePriority(task_queues_[2].get(), TaskQueue::HIGH_PRIORITY); | 299 selector_.SetQueuePriority(task_queues_[2].get(), TaskQueue::HIGH_PRIORITY); |
| 300 selector_.SetQueuePriority(task_queues_[1].get(), | 300 selector_.SetQueuePriority(task_queues_[1].get(), |
| 301 TaskQueue::BEST_EFFORT_PRIORITY); | 301 TaskQueue::BEST_EFFORT_PRIORITY); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 true); | 506 true); |
| 507 task1.set_enqueue_order(0); | 507 task1.set_enqueue_order(0); |
| 508 task2.set_enqueue_order(1); | 508 task2.set_enqueue_order(1); |
| 509 task_queue->immediate_work_queue()->Push(std::move(task1)); | 509 task_queue->immediate_work_queue()->Push(std::move(task1)); |
| 510 task_queue2->immediate_work_queue()->Push(std::move(task2)); | 510 task_queue2->immediate_work_queue()->Push(std::move(task2)); |
| 511 | 511 |
| 512 // Should still only see one call to OnTriedToSelectBlockedWorkQueue. | 512 // Should still only see one call to OnTriedToSelectBlockedWorkQueue. |
| 513 WorkQueue* chosen_work_queue; | 513 WorkQueue* chosen_work_queue; |
| 514 EXPECT_CALL(mock_observer, OnTriedToSelectBlockedWorkQueue(_)).Times(1); | 514 EXPECT_CALL(mock_observer, OnTriedToSelectBlockedWorkQueue(_)).Times(1); |
| 515 EXPECT_FALSE(selector.SelectWorkQueueToService(&chosen_work_queue)); | 515 EXPECT_FALSE(selector.SelectWorkQueueToService(&chosen_work_queue)); |
| 516 testing::Mock::VerifyAndClearExpectations(&mock_observer); | 516 ::testing::Mock::VerifyAndClearExpectations(&mock_observer); |
| 517 | 517 |
| 518 EXPECT_CALL(mock_observer, OnTaskQueueEnabled(_)).Times(2); | 518 EXPECT_CALL(mock_observer, OnTaskQueueEnabled(_)).Times(2); |
| 519 | 519 |
| 520 voter.reset(); | 520 voter.reset(); |
| 521 selector.EnableQueue(task_queue.get()); | 521 selector.EnableQueue(task_queue.get()); |
| 522 | 522 |
| 523 // Removing the second queue and selecting again should result in another | 523 // Removing the second queue and selecting again should result in another |
| 524 // notification. | 524 // notification. |
| 525 task_queue->UnregisterTaskQueue(); | 525 task_queue->UnregisterTaskQueue(); |
| 526 selector.RemoveQueue(task_queue.get()); | 526 selector.RemoveQueue(task_queue.get()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 544 static const ChooseOldestWithPriorityTestParam | 544 static const ChooseOldestWithPriorityTestParam |
| 545 kChooseOldestWithPriorityTestCases[] = { | 545 kChooseOldestWithPriorityTestCases[] = { |
| 546 {1, 2, 0, "delayed", true}, {1, 2, 1, "delayed", true}, | 546 {1, 2, 0, "delayed", true}, {1, 2, 1, "delayed", true}, |
| 547 {1, 2, 2, "delayed", true}, {1, 2, 3, "immediate", false}, | 547 {1, 2, 2, "delayed", true}, {1, 2, 3, "immediate", false}, |
| 548 {1, 2, 4, "immediate", false}, {2, 1, 4, "immediate", false}, | 548 {1, 2, 4, "immediate", false}, {2, 1, 4, "immediate", false}, |
| 549 {2, 1, 4, "immediate", false}, | 549 {2, 1, 4, "immediate", false}, |
| 550 }; | 550 }; |
| 551 | 551 |
| 552 class ChooseOldestWithPriorityTest | 552 class ChooseOldestWithPriorityTest |
| 553 : public TaskQueueSelectorTest, | 553 : public TaskQueueSelectorTest, |
| 554 public testing::WithParamInterface<ChooseOldestWithPriorityTestParam> {}; | 554 public ::testing::WithParamInterface<ChooseOldestWithPriorityTestParam> { |
| 555 }; |
| 555 | 556 |
| 556 TEST_P(ChooseOldestWithPriorityTest, RoundRobinTest) { | 557 TEST_P(ChooseOldestWithPriorityTest, RoundRobinTest) { |
| 557 task_queues_[0]->immediate_work_queue()->Push( | 558 task_queues_[0]->immediate_work_queue()->Push( |
| 558 TaskQueueImpl::Task(FROM_HERE, test_closure_, base::TimeTicks(), | 559 TaskQueueImpl::Task(FROM_HERE, test_closure_, base::TimeTicks(), |
| 559 GetParam().immediate_task_enqueue_order, true, | 560 GetParam().immediate_task_enqueue_order, true, |
| 560 GetParam().immediate_task_enqueue_order)); | 561 GetParam().immediate_task_enqueue_order)); |
| 561 | 562 |
| 562 task_queues_[0]->delayed_work_queue()->Push( | 563 task_queues_[0]->delayed_work_queue()->Push( |
| 563 TaskQueueImpl::Task(FROM_HERE, test_closure_, base::TimeTicks(), | 564 TaskQueueImpl::Task(FROM_HERE, test_closure_, base::TimeTicks(), |
| 564 GetParam().delayed_task_enqueue_order, true, | 565 GetParam().delayed_task_enqueue_order, true, |
| 565 GetParam().delayed_task_enqueue_order)); | 566 GetParam().delayed_task_enqueue_order)); |
| 566 | 567 |
| 567 selector_.SetImmediateStarvationCountForTest( | 568 selector_.SetImmediateStarvationCountForTest( |
| 568 GetParam().immediate_starvation_count); | 569 GetParam().immediate_starvation_count); |
| 569 | 570 |
| 570 WorkQueue* chosen_work_queue = nullptr; | 571 WorkQueue* chosen_work_queue = nullptr; |
| 571 bool chose_delayed_over_immediate = false; | 572 bool chose_delayed_over_immediate = false; |
| 572 EXPECT_TRUE(enabled_selector()->ChooseOldestWithPriority( | 573 EXPECT_TRUE(enabled_selector()->ChooseOldestWithPriority( |
| 573 TaskQueue::NORMAL_PRIORITY, &chose_delayed_over_immediate, | 574 TaskQueue::NORMAL_PRIORITY, &chose_delayed_over_immediate, |
| 574 &chosen_work_queue)); | 575 &chosen_work_queue)); |
| 575 EXPECT_EQ(chosen_work_queue->task_queue(), task_queues_[0].get()); | 576 EXPECT_EQ(chosen_work_queue->task_queue(), task_queues_[0].get()); |
| 576 EXPECT_STREQ(chosen_work_queue->GetName(), | 577 EXPECT_STREQ(chosen_work_queue->GetName(), |
| 577 GetParam().expected_work_queue_name); | 578 GetParam().expected_work_queue_name); |
| 578 EXPECT_EQ(chose_delayed_over_immediate, | 579 EXPECT_EQ(chose_delayed_over_immediate, |
| 579 GetParam().expected_did_starve_immediate_queue); | 580 GetParam().expected_did_starve_immediate_queue); |
| 580 } | 581 } |
| 581 | 582 |
| 582 INSTANTIATE_TEST_CASE_P(ChooseOldestWithPriorityTest, | 583 INSTANTIATE_TEST_CASE_P( |
| 583 ChooseOldestWithPriorityTest, | 584 ChooseOldestWithPriorityTest, |
| 584 testing::ValuesIn(kChooseOldestWithPriorityTestCases)); | 585 ChooseOldestWithPriorityTest, |
| 586 ::testing::ValuesIn(kChooseOldestWithPriorityTestCases)); |
| 585 | 587 |
| 586 } // namespace internal | 588 } // namespace internal |
| 587 } // namespace scheduler | 589 } // namespace scheduler |
| 588 } // namespace blink | 590 } // namespace blink |
| OLD | NEW |