From ce1320cc4db57f51ed487f8d92b3adb777f88c9d Mon Sep 17 00:00:00 2001 From: Marina Ciocea Date: Mon, 4 May 2020 14:26:05 +0200 Subject: [PATCH] Add WaitForPreviouslyPostedTasks to TaskQueueForTest. Add an utility function to TaskQueueForTest to execute all already posted tasks on the queue. Bug: webrtc:11380 Change-Id: I6cf75bc543cfd2dd1c363935134d3f7bd55eec58 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/174140 Commit-Queue: Marina Ciocea Reviewed-by: Karl Wiberg Reviewed-by: Danil Chapovalov Cr-Commit-Position: refs/heads/master@{#31152} --- rtc_base/task_queue_for_test.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rtc_base/task_queue_for_test.h b/rtc_base/task_queue_for_test.h index 7844dc4ad9..dd5679bc99 100644 --- a/rtc_base/task_queue_for_test.h +++ b/rtc_base/task_queue_for_test.h @@ -66,6 +66,14 @@ class RTC_LOCKABLE TaskQueueForTest : public rtc::TaskQueue { void SendTask(Closure&& task, rtc::Location loc) { ::webrtc::SendTask(loc, Get(), std::forward(task)); } + + // Wait for the completion of all tasks posted prior to the + // WaitForPreviouslyPostedTasks() call. + void WaitForPreviouslyPostedTasks() { + // Post an empty task on the queue and wait for it to finish, to ensure + // that all already posted tasks on the queue get executed. + SendTask([]() {}, RTC_FROM_HERE); + } }; } // namespace webrtc