diff --git a/test/single_threaded_task_queue.cc b/test/single_threaded_task_queue.cc index 965cb47547..3cba11748c 100644 --- a/test/single_threaded_task_queue.cc +++ b/test/single_threaded_task_queue.cc @@ -80,12 +80,14 @@ SingleThreadedTaskQueueForTesting::PostDelayedTask(Task task, } void SingleThreadedTaskQueueForTesting::SendTask(Task task) { + RTC_DCHECK(!IsCurrent()); rtc::Event done; PostTask([&task, &done]() { task(); done.Set(); }); - done.Wait(rtc::Event::kForever); + // Give up after 30 seconds, warn after 10. + RTC_CHECK(done.Wait(30000, 10000)); } bool SingleThreadedTaskQueueForTesting::CancelTask(TaskId task_id) { @@ -99,6 +101,10 @@ bool SingleThreadedTaskQueueForTesting::CancelTask(TaskId task_id) { return false; } +bool SingleThreadedTaskQueueForTesting::IsCurrent() { + return rtc::IsThreadRefEqual(thread_.GetThreadRef(), rtc::CurrentThreadRef()); +} + void SingleThreadedTaskQueueForTesting::Run(void* obj) { static_cast(obj)->RunLoop(); } diff --git a/test/single_threaded_task_queue.h b/test/single_threaded_task_queue.h index 5458dd1297..efd14ce604 100644 --- a/test/single_threaded_task_queue.h +++ b/test/single_threaded_task_queue.h @@ -56,6 +56,9 @@ class SingleThreadedTaskQueueForTesting { // only for invalid task IDs, or for tasks which have already been executed. bool CancelTask(TaskId task_id); + // Returns true iff called on the thread associated with the task queue. + bool IsCurrent(); + private: struct QueuedTask { QueuedTask(TaskId task_id, int64_t earliest_execution_time, Task task);