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

Side by Side Diff: base/task_scheduler/scheduler_worker_thread_unittest.cc

Issue 1906083002: TaskScheduler: Remove base/task_scheduler/utils.h/.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sched_2_stack
Patch Set: typos Created 4 years, 7 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "base/task_scheduler/scheduler_worker_thread.h" 5 #include "base/task_scheduler/scheduler_worker_thread.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 return num_run_tasks_; 70 return num_run_tasks_;
71 } 71 }
72 72
73 std::vector<scoped_refptr<Sequence>> CreatedSequences() { 73 std::vector<scoped_refptr<Sequence>> CreatedSequences() {
74 AutoSchedulerLock auto_lock(lock_); 74 AutoSchedulerLock auto_lock(lock_);
75 return created_sequences_; 75 return created_sequences_;
76 } 76 }
77 77
78 std::vector<scoped_refptr<Sequence>> EnqueuedSequences() { 78 std::vector<scoped_refptr<Sequence>> EnqueuedSequences() {
79 AutoSchedulerLock auto_lock(lock_); 79 AutoSchedulerLock auto_lock(lock_);
80 return enqueued_sequences_; 80 return re_enqueued_sequences_;
81 } 81 }
82 82
83 std::unique_ptr<SchedulerWorkerThread> worker_thread_; 83 std::unique_ptr<SchedulerWorkerThread> worker_thread_;
84 84
85 private: 85 private:
86 // SchedulerWorkerThread::Delegate: 86 // SchedulerWorkerThread::Delegate:
87 void OnMainEntry() override { 87 void OnMainEntry() override {
88 // Without this |auto_lock|, OnMainEntry() could be called twice without 88 // Without this |auto_lock|, OnMainEntry() could be called twice without
89 // generating an error. 89 // generating an error.
90 AutoSchedulerLock auto_lock(lock_); 90 AutoSchedulerLock auto_lock(lock_);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 { 126 {
127 // Add the Sequence to the vector of created Sequences. 127 // Add the Sequence to the vector of created Sequences.
128 AutoSchedulerLock auto_lock(lock_); 128 AutoSchedulerLock auto_lock(lock_);
129 created_sequences_.push_back(sequence); 129 created_sequences_.push_back(sequence);
130 } 130 }
131 131
132 return sequence; 132 return sequence;
133 } 133 }
134 134
135 // This override verifies that |sequence| contains the expected number of 135 // This override verifies that |sequence| contains the expected number of
136 // Tasks and adds it to |enqueued_sequences_|. Unlike a normal EnqueueSequence 136 // Tasks and adds it to |re_enqueued_sequences_|. Unlike a normal
137 // implementation, it doesn't reinsert |sequence| into a queue for further 137 // ReEnqueueSequence implementation, it doesn't reinsert |sequence| into a
138 // execution. 138 // queue for further execution.
139 void EnqueueSequence(scoped_refptr<Sequence> sequence) override { 139 void ReEnqueueSequence(scoped_refptr<Sequence> sequence) override {
140 EXPECT_GT(TasksPerSequence(), 1U); 140 EXPECT_GT(TasksPerSequence(), 1U);
141 141
142 // Verify that |sequence| contains TasksPerSequence() - 1 Tasks. 142 // Verify that |sequence| contains TasksPerSequence() - 1 Tasks.
143 for (size_t i = 0; i < TasksPerSequence() - 1; ++i) { 143 for (size_t i = 0; i < TasksPerSequence() - 1; ++i) {
144 EXPECT_TRUE(sequence->PeekTask()); 144 EXPECT_TRUE(sequence->PeekTask());
145 sequence->PopTask(); 145 sequence->PopTask();
146 } 146 }
147 EXPECT_FALSE(sequence->PeekTask()); 147 EXPECT_FALSE(sequence->PeekTask());
148 148
149 // Add |sequence| to |enqueued_sequences_|. 149 // Add |sequence| to |re_enqueued_sequences_|.
150 AutoSchedulerLock auto_lock(lock_); 150 AutoSchedulerLock auto_lock(lock_);
151 enqueued_sequences_.push_back(std::move(sequence)); 151 re_enqueued_sequences_.push_back(std::move(sequence));
152 EXPECT_LE(enqueued_sequences_.size(), created_sequences_.size()); 152 EXPECT_LE(re_enqueued_sequences_.size(), created_sequences_.size());
153 } 153 }
154 154
155 void RunTaskCallback() { 155 void RunTaskCallback() {
156 AutoSchedulerLock auto_lock(lock_); 156 AutoSchedulerLock auto_lock(lock_);
157 ++num_run_tasks_; 157 ++num_run_tasks_;
158 EXPECT_LE(num_run_tasks_, created_sequences_.size()); 158 EXPECT_LE(num_run_tasks_, created_sequences_.size());
159 } 159 }
160 160
161 TaskTracker task_tracker_; 161 TaskTracker task_tracker_;
162 162
(...skipping 13 matching lines...) Expand all
176 // Maximum number of times that GetWork() can be called. 176 // Maximum number of times that GetWork() can be called.
177 size_t max_get_work_ = 0; 177 size_t max_get_work_ = 0;
178 178
179 // Condition variable signaled when |num_get_work_| is incremented. 179 // Condition variable signaled when |num_get_work_| is incremented.
180 std::unique_ptr<ConditionVariable> num_get_work_cv_; 180 std::unique_ptr<ConditionVariable> num_get_work_cv_;
181 181
182 // Sequences created by GetWork(). 182 // Sequences created by GetWork().
183 std::vector<scoped_refptr<Sequence>> created_sequences_; 183 std::vector<scoped_refptr<Sequence>> created_sequences_;
184 184
185 // Sequences passed to EnqueueSequence(). 185 // Sequences passed to EnqueueSequence().
186 std::vector<scoped_refptr<Sequence>> enqueued_sequences_; 186 std::vector<scoped_refptr<Sequence>> re_enqueued_sequences_;
187 187
188 // Number of times that RunTaskCallback() has been called. 188 // Number of times that RunTaskCallback() has been called.
189 size_t num_run_tasks_ = 0; 189 size_t num_run_tasks_ = 0;
190 190
191 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerWorkerThreadTest); 191 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerWorkerThreadTest);
192 }; 192 };
193 193
194 // Verify that when GetWork() continuously returns Sequences, all Tasks in these 194 // Verify that when GetWork() continuously returns Sequences, all Tasks in these
195 // Sequences run successfully. The test wakes up the SchedulerWorkerThread once. 195 // Sequences run successfully. The test wakes up the SchedulerWorkerThread once.
196 TEST_P(TaskSchedulerWorkerThreadTest, ContinuousWork) { 196 TEST_P(TaskSchedulerWorkerThreadTest, ContinuousWork) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 INSTANTIATE_TEST_CASE_P(OneTaskPerSequence, 255 INSTANTIATE_TEST_CASE_P(OneTaskPerSequence,
256 TaskSchedulerWorkerThreadTest, 256 TaskSchedulerWorkerThreadTest,
257 ::testing::Values(1)); 257 ::testing::Values(1));
258 INSTANTIATE_TEST_CASE_P(TwoTasksPerSequence, 258 INSTANTIATE_TEST_CASE_P(TwoTasksPerSequence,
259 TaskSchedulerWorkerThreadTest, 259 TaskSchedulerWorkerThreadTest,
260 ::testing::Values(2)); 260 ::testing::Values(2));
261 261
262 } // namespace 262 } // namespace
263 } // namespace internal 263 } // namespace internal
264 } // namespace base 264 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698