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

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

Issue 1259583006: Reland: Explicitly track the scheduler task enqueueing order in a new field (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix the DCHECK 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 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/child/task_queue_manager.h" 5 #include "components/scheduler/child/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 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 base::RunLoop run_loop; 1022 base::RunLoop run_loop;
1023 runners_[0]->PostTask( 1023 runners_[0]->PostTask(
1024 FROM_HERE, 1024 FROM_HERE,
1025 base::Bind(&PostAndQuitFromNestedRunloop, base::Unretained(&run_loop), 1025 base::Bind(&PostAndQuitFromNestedRunloop, base::Unretained(&run_loop),
1026 runners_[0], base::Unretained(&was_nested))); 1026 runners_[0], base::Unretained(&was_nested)));
1027 1027
1028 message_loop_->RunUntilIdle(); 1028 message_loop_->RunUntilIdle();
1029 EXPECT_FALSE(was_nested); 1029 EXPECT_FALSE(was_nested);
1030 } 1030 }
1031 1031
1032 class SequenceNumberCapturingTaskObserver
1033 : public base::MessageLoop::TaskObserver {
1034 public:
1035 // MessageLoop::TaskObserver overrides.
1036 void WillProcessTask(const base::PendingTask& pending_task) override {}
1037 void DidProcessTask(const base::PendingTask& pending_task) override {
1038 sequence_numbers_.push_back(pending_task.sequence_num);
1039 }
1040
1041 const std::vector<int>& sequence_numbers() const { return sequence_numbers_; }
1042
1043 private:
1044 std::vector<int> sequence_numbers_;
1045 };
1046
1047 TEST_F(TaskQueueManagerTest, SequenceNumSetWhenTaskIsPosted) {
1048 Initialize(1u);
1049
1050 SequenceNumberCapturingTaskObserver observer;
1051 manager_->AddTaskObserver(&observer);
1052
1053 // Register four tasks that will run in reverse order.
1054 std::vector<int> run_order;
1055 runners_[0]->PostDelayedTask(FROM_HERE, base::Bind(&TestTask, 1, &run_order),
1056 base::TimeDelta::FromMilliseconds(30));
1057 runners_[0]->PostDelayedTask(FROM_HERE, base::Bind(&TestTask, 2, &run_order),
1058 base::TimeDelta::FromMilliseconds(20));
1059 runners_[0]->PostDelayedTask(FROM_HERE, base::Bind(&TestTask, 3, &run_order),
1060 base::TimeDelta::FromMilliseconds(10));
1061 runners_[0]->PostTask(FROM_HERE, base::Bind(&TestTask, 4, &run_order));
1062
1063 test_task_runner_->RunForPeriod(base::TimeDelta::FromMilliseconds(40));
1064 ASSERT_THAT(run_order, ElementsAre(4, 3, 2, 1));
1065
1066 // The sequence numbers are a zero-based monotonically incrememting counter
1067 // which should be set when the task is posted rather than when it's enqueued
1068 // onto the incomming queue.
1069 EXPECT_THAT(observer.sequence_numbers(), ElementsAre(3, 2, 1, 0));
1070
1071 manager_->RemoveTaskObserver(&observer);
1072 }
1073
1032 } // namespace scheduler 1074 } // namespace scheduler
OLDNEW
« no previous file with comments | « components/scheduler/child/task_queue_manager.cc ('k') | components/scheduler/child/task_queue_selector_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698