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

Unified Diff: base/test/test_mock_time_task_runner.cc

Issue 1051873003: Make TestMockTimeTaskRunner run tasks with the same delay in the order they were posted. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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/test_mock_time_task_runner.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/test/test_mock_time_task_runner.cc
diff --git a/base/test/test_mock_time_task_runner.cc b/base/test/test_mock_time_task_runner.cc
index 8cc2e6d5ff1f1366cb4574f5dc3608efd62fcb57..f2e18a3503379588194ca005b27f4da3013663f4 100644
--- a/base/test/test_mock_time_task_runner.cc
+++ b/base/test/test_mock_time_task_runner.cc
@@ -67,15 +67,55 @@ Time MockClock::Now() {
} // namespace
+// TestMockTimeTaskRunner::TestOrderedPendingTask -----------------------------
+
+// Subclass of TestPendingTask which has a strictly monotonically increasing ID
+// for every task, so that tasks posted with the same 'time to run' can be run
+// in the order of being posted.
+struct TestMockTimeTaskRunner::TestOrderedPendingTask
+ : public base::TestPendingTask {
+ TestOrderedPendingTask();
+ TestOrderedPendingTask(const tracked_objects::Location& location,
+ const Closure& task,
+ TimeTicks post_time,
+ TimeDelta delay,
+ size_t ordinal,
+ TestNestability nestability);
+ ~TestOrderedPendingTask();
+
+ size_t ordinal;
+};
+
+TestMockTimeTaskRunner::TestOrderedPendingTask::TestOrderedPendingTask()
+ : ordinal(0) {
+}
+
+TestMockTimeTaskRunner::TestOrderedPendingTask::TestOrderedPendingTask(
+ const tracked_objects::Location& location,
+ const Closure& task,
+ TimeTicks post_time,
+ TimeDelta delay,
+ size_t ordinal,
+ TestNestability nestability)
+ : base::TestPendingTask(location, task, post_time, delay, nestability),
+ ordinal(ordinal) {
+}
+
+TestMockTimeTaskRunner::TestOrderedPendingTask::~TestOrderedPendingTask() {
+}
+
// TestMockTimeTaskRunner -----------------------------------------------------
bool TestMockTimeTaskRunner::TemporalOrder::operator()(
- const TestPendingTask& first_task,
- const TestPendingTask& second_task) const {
+ const TestOrderedPendingTask& first_task,
+ const TestOrderedPendingTask& second_task) const {
+ if (first_task.GetTimeToRun() == second_task.GetTimeToRun())
+ return first_task.ordinal > second_task.ordinal;
return first_task.GetTimeToRun() > second_task.GetTimeToRun();
}
-TestMockTimeTaskRunner::TestMockTimeTaskRunner() : now_(Time::UnixEpoch()) {
+TestMockTimeTaskRunner::TestMockTimeTaskRunner()
+ : now_(Time::UnixEpoch()), next_task_ordinal_(0) {
}
TestMockTimeTaskRunner::~TestMockTimeTaskRunner() {
@@ -152,8 +192,9 @@ bool TestMockTimeTaskRunner::PostDelayedTask(
const Closure& task,
TimeDelta delay) {
AutoLock scoped_lock(tasks_lock_);
- tasks_.push(TestPendingTask(from_here, task, now_ticks_, delay,
- TestPendingTask::NESTABLE));
+ tasks_.push(TestOrderedPendingTask(from_here, task, now_ticks_, delay,
+ next_task_ordinal_++,
+ TestPendingTask::NESTABLE));
return true;
}
« no previous file with comments | « base/test/test_mock_time_task_runner.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698