| 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 188 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"; |
| 216 static const char kReplyQueue[] = "ReplyQueue"; |
| 217 std::unique_ptr<TaskQueue> post_queue(new TaskQueue(kPostQueue)); |
| 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 |