OLD | NEW |
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 <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 1722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1733 | 1733 |
1734 double ratio = static_cast<double>(linear_delayed_task.count()) / | 1734 double ratio = static_cast<double>(linear_delayed_task.count()) / |
1735 static_cast<double>(quadratic_immediate_task.count()); | 1735 static_cast<double>(quadratic_immediate_task.count()); |
1736 | 1736 |
1737 // This is by design, we want to enforce a strict ordering in task execution | 1737 // This is by design, we want to enforce a strict ordering in task execution |
1738 // where by delayed tasks can not skip ahead of non-delayed work. | 1738 // where by delayed tasks can not skip ahead of non-delayed work. |
1739 EXPECT_GT(ratio, 0.0); | 1739 EXPECT_GT(ratio, 0.0); |
1740 EXPECT_LT(ratio, 0.1); | 1740 EXPECT_LT(ratio, 0.1); |
1741 } | 1741 } |
1742 | 1742 |
| 1743 TEST_F(TaskQueueManagerTest, CurrentlyExecutingTaskQueue_NoTaskRunning) { |
| 1744 Initialize(1u); |
| 1745 |
| 1746 EXPECT_EQ(nullptr, manager_->currently_executing_task_queue()); |
| 1747 } |
| 1748 |
| 1749 namespace { |
| 1750 void CurrentlyExecutingTaskQueueTestTask(TaskQueueManager* task_queue_manager, |
| 1751 std::vector<TaskQueue*>* task_sources) { |
| 1752 task_sources->push_back(task_queue_manager->currently_executing_task_queue()); |
| 1753 } |
| 1754 } |
| 1755 |
| 1756 TEST_F(TaskQueueManagerTest, CurrentlyExecutingTaskQueue_TaskRunning) { |
| 1757 Initialize(2u); |
| 1758 |
| 1759 internal::TaskQueueImpl* queue0 = runners_[0].get(); |
| 1760 internal::TaskQueueImpl* queue1 = runners_[1].get(); |
| 1761 |
| 1762 std::vector<TaskQueue*> task_sources; |
| 1763 queue0->PostTask(FROM_HERE, base::Bind(&CurrentlyExecutingTaskQueueTestTask, |
| 1764 manager_.get(), &task_sources)); |
| 1765 queue1->PostTask(FROM_HERE, base::Bind(&CurrentlyExecutingTaskQueueTestTask, |
| 1766 manager_.get(), &task_sources)); |
| 1767 test_task_runner_->RunUntilIdle(); |
| 1768 |
| 1769 EXPECT_THAT(task_sources, ElementsAre(queue0, queue1)); |
| 1770 EXPECT_EQ(nullptr, manager_->currently_executing_task_queue()); |
| 1771 } |
| 1772 |
| 1773 namespace { |
| 1774 void RunloopCurrentlyExecutingTaskQueueTestTask( |
| 1775 base::MessageLoop* message_loop, |
| 1776 TaskQueueManager* task_queue_manager, |
| 1777 std::vector<TaskQueue*>* task_sources, |
| 1778 std::vector<std::pair<base::Closure, TaskQueue*>>* tasks) { |
| 1779 base::MessageLoop::ScopedNestableTaskAllower allow(message_loop); |
| 1780 task_sources->push_back(task_queue_manager->currently_executing_task_queue()); |
| 1781 |
| 1782 for (std::pair<base::Closure, TaskQueue*>& pair : *tasks) { |
| 1783 pair.second->PostTask(FROM_HERE, pair.first); |
| 1784 } |
| 1785 |
| 1786 message_loop->RunUntilIdle(); |
| 1787 task_sources->push_back(task_queue_manager->currently_executing_task_queue()); |
| 1788 } |
| 1789 } |
| 1790 |
| 1791 TEST_F(TaskQueueManagerTest, CurrentlyExecutingTaskQueue_NestedLoop) { |
| 1792 InitializeWithRealMessageLoop(3u); |
| 1793 |
| 1794 TaskQueue* queue0 = runners_[0].get(); |
| 1795 TaskQueue* queue1 = runners_[1].get(); |
| 1796 TaskQueue* queue2 = runners_[2].get(); |
| 1797 |
| 1798 std::vector<TaskQueue*> task_sources; |
| 1799 std::vector<std::pair<base::Closure, TaskQueue*>> |
| 1800 tasks_to_post_from_nested_loop; |
| 1801 tasks_to_post_from_nested_loop.push_back( |
| 1802 std::make_pair(base::Bind(&CurrentlyExecutingTaskQueueTestTask, |
| 1803 manager_.get(), &task_sources), |
| 1804 queue1)); |
| 1805 tasks_to_post_from_nested_loop.push_back( |
| 1806 std::make_pair(base::Bind(&CurrentlyExecutingTaskQueueTestTask, |
| 1807 manager_.get(), &task_sources), |
| 1808 queue2)); |
| 1809 |
| 1810 queue0->PostTask( |
| 1811 FROM_HERE, base::Bind(&RunloopCurrentlyExecutingTaskQueueTestTask, |
| 1812 message_loop_.get(), manager_.get(), &task_sources, |
| 1813 &tasks_to_post_from_nested_loop)); |
| 1814 |
| 1815 message_loop_->RunUntilIdle(); |
| 1816 EXPECT_THAT(task_sources, ElementsAre(queue0, queue1, queue2, queue0)); |
| 1817 EXPECT_EQ(nullptr, manager_->currently_executing_task_queue()); |
| 1818 } |
| 1819 |
1743 } // namespace scheduler | 1820 } // namespace scheduler |
OLD | NEW |