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

Side by Side Diff: webrtc/rtc_base/task_queue_unittest.cc

Issue 3004873002: Delete static method TaskQueue::IsCurrent. (Closed)
Patch Set: Created 3 years, 3 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
« no previous file with comments | « webrtc/rtc_base/task_queue_libevent.cc ('k') | webrtc/rtc_base/task_queue_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 29 matching lines...) Expand all
40 timeEndPeriod(1); 40 timeEndPeriod(1);
41 } 41 }
42 42
43 private: 43 private:
44 const bool enabled_; 44 const bool enabled_;
45 #endif 45 #endif
46 }; 46 };
47 } 47 }
48 48
49 namespace { 49 namespace {
50 void CheckCurrent(const char* expected_queue, Event* signal, TaskQueue* queue) { 50 void CheckCurrent(Event* signal, TaskQueue* queue) {
51 EXPECT_TRUE(TaskQueue::IsCurrent(expected_queue));
52 EXPECT_TRUE(queue->IsCurrent()); 51 EXPECT_TRUE(queue->IsCurrent());
53 if (signal) 52 if (signal)
54 signal->Set(); 53 signal->Set();
55 } 54 }
56 55
57 } // namespace 56 } // namespace
58 57
59 TEST(TaskQueueTest, Construct) { 58 TEST(TaskQueueTest, Construct) {
60 static const char kQueueName[] = "Construct"; 59 static const char kQueueName[] = "Construct";
61 TaskQueue queue(kQueueName); 60 TaskQueue queue(kQueueName);
62 EXPECT_FALSE(queue.IsCurrent()); 61 EXPECT_FALSE(queue.IsCurrent());
63 } 62 }
64 63
65 TEST(TaskQueueTest, PostAndCheckCurrent) { 64 TEST(TaskQueueTest, PostAndCheckCurrent) {
66 static const char kQueueName[] = "PostAndCheckCurrent"; 65 static const char kQueueName[] = "PostAndCheckCurrent";
67 Event event(false, false); 66 Event event(false, false);
68 TaskQueue queue(kQueueName); 67 TaskQueue queue(kQueueName);
69 68
70 // We're not running a task, so there shouldn't be a current queue. 69 // We're not running a task, so there shouldn't be a current queue.
71 EXPECT_FALSE(queue.IsCurrent()); 70 EXPECT_FALSE(queue.IsCurrent());
72 EXPECT_FALSE(TaskQueue::Current()); 71 EXPECT_FALSE(TaskQueue::Current());
73 72
74 queue.PostTask(Bind(&CheckCurrent, kQueueName, &event, &queue)); 73 queue.PostTask(Bind(&CheckCurrent, &event, &queue));
75 EXPECT_TRUE(event.Wait(1000)); 74 EXPECT_TRUE(event.Wait(1000));
76 } 75 }
77 76
78 TEST(TaskQueueTest, PostCustomTask) { 77 TEST(TaskQueueTest, PostCustomTask) {
79 static const char kQueueName[] = "PostCustomImplementation"; 78 static const char kQueueName[] = "PostCustomImplementation";
80 Event event(false, false); 79 Event event(false, false);
81 TaskQueue queue(kQueueName); 80 TaskQueue queue(kQueueName);
82 81
83 class CustomTask : public QueuedTask { 82 class CustomTask : public QueuedTask {
84 public: 83 public:
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 [&event, &queue]() { queue.PostTask([&event]() { event.Set(); }); }); 124 [&event, &queue]() { queue.PostTask([&event]() { event.Set(); }); });
126 EXPECT_TRUE(event.Wait(1000)); 125 EXPECT_TRUE(event.Wait(1000));
127 } 126 }
128 127
129 TEST(TaskQueueTest, PostDelayed) { 128 TEST(TaskQueueTest, PostDelayed) {
130 static const char kQueueName[] = "PostDelayed"; 129 static const char kQueueName[] = "PostDelayed";
131 Event event(false, false); 130 Event event(false, false);
132 TaskQueue queue(kQueueName, TaskQueue::Priority::HIGH); 131 TaskQueue queue(kQueueName, TaskQueue::Priority::HIGH);
133 132
134 uint32_t start = Time(); 133 uint32_t start = Time();
135 queue.PostDelayedTask(Bind(&CheckCurrent, kQueueName, &event, &queue), 100); 134 queue.PostDelayedTask(Bind(&CheckCurrent, &event, &queue), 100);
136 EXPECT_TRUE(event.Wait(1000)); 135 EXPECT_TRUE(event.Wait(1000));
137 uint32_t end = Time(); 136 uint32_t end = Time();
138 // These tests are a little relaxed due to how "powerful" our test bots can 137 // These tests are a little relaxed due to how "powerful" our test bots can
139 // be. Most recently we've seen windows bots fire the callback after 94-99ms, 138 // be. Most recently we've seen windows bots fire the callback after 94-99ms,
140 // which is why we have a little bit of leeway backwards as well. 139 // which is why we have a little bit of leeway backwards as well.
141 EXPECT_GE(end - start, 90u); 140 EXPECT_GE(end - start, 90u);
142 EXPECT_NEAR(end - start, 190u, 100u); // Accept 90-290. 141 EXPECT_NEAR(end - start, 190u, 100u); // Accept 90-290.
143 } 142 }
144 143
145 // This task needs to be run manually due to the slowness of some of our bots. 144 // This task needs to be run manually due to the slowness of some of our bots.
146 // TODO(tommi): Can we run this on the perf bots? 145 // TODO(tommi): Can we run this on the perf bots?
147 TEST(TaskQueueTest, DISABLED_PostDelayedHighRes) { 146 TEST(TaskQueueTest, DISABLED_PostDelayedHighRes) {
148 EnableHighResTimers high_res_scope; 147 EnableHighResTimers high_res_scope;
149 148
150 static const char kQueueName[] = "PostDelayedHighRes"; 149 static const char kQueueName[] = "PostDelayedHighRes";
151 Event event(false, false); 150 Event event(false, false);
152 TaskQueue queue(kQueueName, TaskQueue::Priority::HIGH); 151 TaskQueue queue(kQueueName, TaskQueue::Priority::HIGH);
153 152
154 uint32_t start = Time(); 153 uint32_t start = Time();
155 queue.PostDelayedTask(Bind(&CheckCurrent, kQueueName, &event, &queue), 3); 154 queue.PostDelayedTask(Bind(&CheckCurrent, &event, &queue), 3);
156 EXPECT_TRUE(event.Wait(1000)); 155 EXPECT_TRUE(event.Wait(1000));
157 uint32_t end = TimeMillis(); 156 uint32_t end = TimeMillis();
158 // These tests are a little relaxed due to how "powerful" our test bots can 157 // These tests are a little relaxed due to how "powerful" our test bots can
159 // be. Most recently we've seen windows bots fire the callback after 94-99ms, 158 // be. Most recently we've seen windows bots fire the callback after 94-99ms,
160 // which is why we have a little bit of leeway backwards as well. 159 // which is why we have a little bit of leeway backwards as well.
161 EXPECT_GE(end - start, 3u); 160 EXPECT_GE(end - start, 3u);
162 EXPECT_NEAR(end - start, 3, 3u); 161 EXPECT_NEAR(end - start, 3, 3u);
163 } 162 }
164 163
165 TEST(TaskQueueTest, PostMultipleDelayed) { 164 TEST(TaskQueueTest, PostMultipleDelayed) {
166 static const char kQueueName[] = "PostMultipleDelayed"; 165 static const char kQueueName[] = "PostMultipleDelayed";
167 TaskQueue queue(kQueueName); 166 TaskQueue queue(kQueueName);
168 167
169 std::vector<std::unique_ptr<Event>> events; 168 std::vector<std::unique_ptr<Event>> events;
170 for (int i = 0; i < 100; ++i) { 169 for (int i = 0; i < 100; ++i) {
171 events.push_back(std::unique_ptr<Event>(new Event(false, false))); 170 events.push_back(std::unique_ptr<Event>(new Event(false, false)));
172 queue.PostDelayedTask( 171 queue.PostDelayedTask(
173 Bind(&CheckCurrent, kQueueName, events.back().get(), &queue), i); 172 Bind(&CheckCurrent, events.back().get(), &queue), i);
174 } 173 }
175 174
176 for (const auto& e : events) 175 for (const auto& e : events)
177 EXPECT_TRUE(e->Wait(1000)); 176 EXPECT_TRUE(e->Wait(1000));
178 } 177 }
179 178
180 TEST(TaskQueueTest, PostDelayedAfterDestruct) { 179 TEST(TaskQueueTest, PostDelayedAfterDestruct) {
181 static const char kQueueName[] = "PostDelayedAfterDestruct"; 180 static const char kQueueName[] = "PostDelayedAfterDestruct";
182 Event event(false, false); 181 Event event(false, false);
183 { 182 {
184 TaskQueue queue(kQueueName); 183 TaskQueue queue(kQueueName);
185 queue.PostDelayedTask(Bind(&CheckCurrent, kQueueName, &event, &queue), 100); 184 queue.PostDelayedTask(Bind(&CheckCurrent, &event, &queue), 100);
186 } 185 }
187 EXPECT_FALSE(event.Wait(200)); // Task should not run. 186 EXPECT_FALSE(event.Wait(200)); // Task should not run.
188 } 187 }
189 188
190 TEST(TaskQueueTest, PostAndReply) { 189 TEST(TaskQueueTest, PostAndReply) {
191 static const char kPostQueue[] = "PostQueue"; 190 static const char kPostQueue[] = "PostQueue";
192 static const char kReplyQueue[] = "ReplyQueue"; 191 static const char kReplyQueue[] = "ReplyQueue";
193 Event event(false, false); 192 Event event(false, false);
194 TaskQueue post_queue(kPostQueue); 193 TaskQueue post_queue(kPostQueue);
195 TaskQueue reply_queue(kReplyQueue); 194 TaskQueue reply_queue(kReplyQueue);
196 195
197 post_queue.PostTaskAndReply( 196 post_queue.PostTaskAndReply(
198 Bind(&CheckCurrent, kPostQueue, nullptr, &post_queue), 197 Bind(&CheckCurrent, nullptr, &post_queue),
199 Bind(&CheckCurrent, kReplyQueue, &event, &reply_queue), &reply_queue); 198 Bind(&CheckCurrent, &event, &reply_queue), &reply_queue);
200 EXPECT_TRUE(event.Wait(1000)); 199 EXPECT_TRUE(event.Wait(1000));
201 } 200 }
202 201
203 TEST(TaskQueueTest, PostAndReuse) { 202 TEST(TaskQueueTest, PostAndReuse) {
204 static const char kPostQueue[] = "PostQueue"; 203 static const char kPostQueue[] = "PostQueue";
205 static const char kReplyQueue[] = "ReplyQueue"; 204 static const char kReplyQueue[] = "ReplyQueue";
206 Event event(false, false); 205 Event event(false, false);
207 TaskQueue post_queue(kPostQueue); 206 TaskQueue post_queue(kPostQueue);
208 TaskQueue reply_queue(kReplyQueue); 207 TaskQueue reply_queue(kReplyQueue);
209 208
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 Event event(false, false); 269 Event event(false, false);
271 TaskQueue post_queue("PostQueue"); 270 TaskQueue post_queue("PostQueue");
272 TaskQueue reply_queue("ReplyQueue"); 271 TaskQueue reply_queue("ReplyQueue");
273 272
274 post_queue.PostTaskAndReply([&event]() { event.Set(); }, []() {}, 273 post_queue.PostTaskAndReply([&event]() { event.Set(); }, []() {},
275 &reply_queue); 274 &reply_queue);
276 EXPECT_TRUE(event.Wait(1000)); 275 EXPECT_TRUE(event.Wait(1000));
277 } 276 }
278 277
279 void TestPostTaskAndReply(TaskQueue* work_queue, 278 void TestPostTaskAndReply(TaskQueue* work_queue,
280 const char* work_queue_name,
281 Event* event) { 279 Event* event) {
282 ASSERT_FALSE(work_queue->IsCurrent()); 280 ASSERT_FALSE(work_queue->IsCurrent());
283 work_queue->PostTaskAndReply( 281 work_queue->PostTaskAndReply(
284 Bind(&CheckCurrent, work_queue_name, nullptr, work_queue), 282 Bind(&CheckCurrent, nullptr, work_queue),
285 NewClosure([event]() { event->Set(); })); 283 NewClosure([event]() { event->Set(); }));
286 } 284 }
287 285
288 // Does a PostTaskAndReply from within a task to post and reply to the current 286 // Does a PostTaskAndReply from within a task to post and reply to the current
289 // queue. All in all there will be 3 tasks posted and run. 287 // queue. All in all there will be 3 tasks posted and run.
290 TEST(TaskQueueTest, PostAndReply2) { 288 TEST(TaskQueueTest, PostAndReply2) {
291 static const char kQueueName[] = "PostAndReply2"; 289 static const char kQueueName[] = "PostAndReply2";
292 static const char kWorkQueueName[] = "PostAndReply2_Worker"; 290 static const char kWorkQueueName[] = "PostAndReply2_Worker";
293 Event event(false, false); 291 Event event(false, false);
294 TaskQueue queue(kQueueName); 292 TaskQueue queue(kQueueName);
295 TaskQueue work_queue(kWorkQueueName); 293 TaskQueue work_queue(kWorkQueueName);
296 294
297 queue.PostTask( 295 queue.PostTask(
298 Bind(&TestPostTaskAndReply, &work_queue, kWorkQueueName, &event)); 296 Bind(&TestPostTaskAndReply, &work_queue, &event));
299 EXPECT_TRUE(event.Wait(1000)); 297 EXPECT_TRUE(event.Wait(1000));
300 } 298 }
301 299
302 // Tests posting more messages than a queue can queue up. 300 // Tests posting more messages than a queue can queue up.
303 // In situations like that, tasks will get dropped. 301 // In situations like that, tasks will get dropped.
304 TEST(TaskQueueTest, PostALot) { 302 TEST(TaskQueueTest, PostALot) {
305 // To destruct the event after the queue has gone out of scope. 303 // To destruct the event after the queue has gone out of scope.
306 Event event(false, false); 304 Event event(false, false);
307 305
308 int tasks_executed = 0; 306 int tasks_executed = 0;
(...skipping 13 matching lines...) Expand all
322 queue.PostTask(NewClosure([&tasks_executed]() { ++tasks_executed; }, 320 queue.PostTask(NewClosure([&tasks_executed]() { ++tasks_executed; },
323 [&tasks_cleaned_up]() { ++tasks_cleaned_up; })); 321 [&tasks_cleaned_up]() { ++tasks_cleaned_up; }));
324 event.Set(); // Unblock the first task. 322 event.Set(); // Unblock the first task.
325 } 323 }
326 324
327 EXPECT_GE(tasks_cleaned_up, tasks_executed); 325 EXPECT_GE(tasks_cleaned_up, tasks_executed);
328 EXPECT_EQ(kTaskCount, tasks_cleaned_up); 326 EXPECT_EQ(kTaskCount, tasks_cleaned_up);
329 } 327 }
330 328
331 } // namespace rtc 329 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/rtc_base/task_queue_libevent.cc ('k') | webrtc/rtc_base/task_queue_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698