OLD | NEW |
---|---|
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 25 matching lines...) Expand all Loading... | |
36 } | 36 } |
37 | 37 |
38 TEST(TaskQueueTest, PostAndCheckCurrent) { | 38 TEST(TaskQueueTest, PostAndCheckCurrent) { |
39 static const char kQueueName[] = "PostAndCheckCurrent"; | 39 static const char kQueueName[] = "PostAndCheckCurrent"; |
40 TaskQueue queue(kQueueName); | 40 TaskQueue queue(kQueueName); |
41 | 41 |
42 // We're not running a task, so there shouldn't be a current queue. | 42 // We're not running a task, so there shouldn't be a current queue. |
43 EXPECT_FALSE(queue.IsCurrent()); | 43 EXPECT_FALSE(queue.IsCurrent()); |
44 EXPECT_FALSE(TaskQueue::Current()); | 44 EXPECT_FALSE(TaskQueue::Current()); |
45 | 45 |
46 Event event(false, false); | 46 Event event(false, false); |
Taylor Brandstetter
2017/02/22 00:24:27
These tests still should put the Event above the T
tommi
2017/02/22 12:43:54
Ah, I was wondering why you moved the event object
| |
47 queue.PostTask(Bind(&CheckCurrent, kQueueName, &event, &queue)); | 47 queue.PostTask(Bind(&CheckCurrent, kQueueName, &event, &queue)); |
48 EXPECT_TRUE(event.Wait(1000)); | 48 EXPECT_TRUE(event.Wait(1000)); |
49 } | 49 } |
50 | 50 |
51 TEST(TaskQueueTest, PostCustomTask) { | 51 TEST(TaskQueueTest, PostCustomTask) { |
52 static const char kQueueName[] = "PostCustomImplementation"; | 52 static const char kQueueName[] = "PostCustomImplementation"; |
53 TaskQueue queue(kQueueName); | 53 TaskQueue queue(kQueueName); |
54 | 54 |
55 Event event(false, false); | 55 Event event(false, false); |
56 | 56 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 TaskQueue reply_queue(kReplyQueue); | 199 TaskQueue reply_queue(kReplyQueue); |
200 | 200 |
201 Event event(false, false); | 201 Event event(false, false); |
202 bool my_flag = false; | 202 bool my_flag = false; |
203 post_queue.PostTaskAndReply([&my_flag]() { my_flag = true; }, | 203 post_queue.PostTaskAndReply([&my_flag]() { my_flag = true; }, |
204 [&event]() { event.Set(); }, &reply_queue); | 204 [&event]() { event.Set(); }, &reply_queue); |
205 EXPECT_TRUE(event.Wait(1000)); | 205 EXPECT_TRUE(event.Wait(1000)); |
206 EXPECT_TRUE(my_flag); | 206 EXPECT_TRUE(my_flag); |
207 } | 207 } |
208 | 208 |
209 // This test covers a particular bug that we had in the libevent implementation | |
210 // where we could hit a deadlock while trying to post a reply task to a queue | |
211 // that was being deleted. The test isn't guaranteed to hit that case but it's | |
212 // written in a way that makes it likely and by running with --gtest_repeat=1000 | |
213 // the bug would occur. Alas, now it should be fixed. | |
214 TEST(TaskQueueTest, PostAndReplyDeadlock) { | |
215 static const char kPostQueue[] = "PostQueue"; | |
Taylor Brandstetter
2017/02/22 00:24:27
Out of curiosity, what's the purpose of having "st
tommi
2017/02/22 12:43:54
When I started writing these tests, the constant v
| |
216 static const char kReplyQueue[] = "ReplyQueue"; | |
217 std::unique_ptr<TaskQueue> post_queue(new TaskQueue(kPostQueue)); | |
Taylor Brandstetter
2017/02/22 00:24:28
These don't need to be unique_ptrs
tommi
2017/02/22 12:43:54
Done. I made them unique_ptrs while debugging so
| |
218 std::unique_ptr<TaskQueue> reply_queue(new TaskQueue(kReplyQueue)); | |
219 | |
220 Event event(false, false); | |
221 post_queue->PostTaskAndReply([&event]() { event.Set(); }, []() {}, | |
222 reply_queue.get()); | |
223 EXPECT_TRUE(event.Wait(1000)); | |
224 reply_queue.reset(); | |
225 } | |
226 | |
209 void TestPostTaskAndReply(TaskQueue* work_queue, | 227 void TestPostTaskAndReply(TaskQueue* work_queue, |
210 const char* work_queue_name, | 228 const char* work_queue_name, |
211 Event* event) { | 229 Event* event) { |
212 ASSERT_FALSE(work_queue->IsCurrent()); | 230 ASSERT_FALSE(work_queue->IsCurrent()); |
213 work_queue->PostTaskAndReply( | 231 work_queue->PostTaskAndReply( |
214 Bind(&CheckCurrent, work_queue_name, nullptr, work_queue), | 232 Bind(&CheckCurrent, work_queue_name, nullptr, work_queue), |
215 NewClosure([event]() { event->Set(); })); | 233 NewClosure([event]() { event->Set(); })); |
216 } | 234 } |
217 | 235 |
218 // Does a PostTaskAndReply from within a task to post and reply to the current | 236 // Does a PostTaskAndReply from within a task to post and reply to the current |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 queue.PostTask(NewClosure([&tasks_executed]() { ++tasks_executed; }, | 270 queue.PostTask(NewClosure([&tasks_executed]() { ++tasks_executed; }, |
253 [&tasks_cleaned_up]() { ++tasks_cleaned_up; })); | 271 [&tasks_cleaned_up]() { ++tasks_cleaned_up; })); |
254 event.Set(); // Unblock the first task. | 272 event.Set(); // Unblock the first task. |
255 } | 273 } |
256 | 274 |
257 EXPECT_GE(tasks_cleaned_up, tasks_executed); | 275 EXPECT_GE(tasks_cleaned_up, tasks_executed); |
258 EXPECT_EQ(kTaskCount, tasks_cleaned_up); | 276 EXPECT_EQ(kTaskCount, tasks_cleaned_up); |
259 } | 277 } |
260 | 278 |
261 } // namespace rtc | 279 } // namespace rtc |
OLD | NEW |