mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 22:00:47 +01:00

on the current thread. This simplifies writing async tests that use TaskQueue and doesn't require spinning up a new thread for simple things. The implementation is currently based on rtc::Thread, which could also be useful in some circumstances while migrating code over to TQ. Remove PressEnterToContinue from the test_common files since it's very specific and only used from one file. Bug: none Change-Id: I8b2c6c40809271a109ec17cf7e1120847645d58a Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/174260 Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Commit-Queue: Tommi <tommi@webrtc.org> Cr-Commit-Position: refs/heads/master@{#31160}
73 lines
1.8 KiB
C++
73 lines
1.8 KiB
C++
/*
|
|
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
#include "test/run_loop.h"
|
|
|
|
#include "rtc_base/task_utils/to_queued_task.h"
|
|
|
|
namespace webrtc {
|
|
namespace test {
|
|
|
|
RunLoop::RunLoop() {
|
|
worker_thread_.WrapCurrent();
|
|
}
|
|
|
|
RunLoop::~RunLoop() {
|
|
worker_thread_.UnwrapCurrent();
|
|
}
|
|
|
|
TaskQueueBase* RunLoop::task_queue() {
|
|
return &worker_thread_;
|
|
}
|
|
|
|
void RunLoop::Run() {
|
|
worker_thread_.ProcessMessages(WorkerThread::kForever);
|
|
}
|
|
|
|
void RunLoop::Quit() {
|
|
socket_server_.FailNextWait();
|
|
}
|
|
|
|
void RunLoop::Flush() {
|
|
worker_thread_.PostTask(
|
|
ToQueuedTask([this]() { socket_server_.FailNextWait(); }));
|
|
worker_thread_.ProcessMessages(1000);
|
|
}
|
|
|
|
RunLoop::FakeSocketServer::FakeSocketServer() = default;
|
|
RunLoop::FakeSocketServer::~FakeSocketServer() = default;
|
|
|
|
void RunLoop::FakeSocketServer::FailNextWait() {
|
|
fail_next_wait_ = true;
|
|
}
|
|
|
|
bool RunLoop::FakeSocketServer::Wait(int cms, bool process_io) {
|
|
if (fail_next_wait_) {
|
|
fail_next_wait_ = false;
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void RunLoop::FakeSocketServer::WakeUp() {}
|
|
|
|
rtc::Socket* RunLoop::FakeSocketServer::CreateSocket(int family, int type) {
|
|
return nullptr;
|
|
}
|
|
|
|
rtc::AsyncSocket* RunLoop::FakeSocketServer::CreateAsyncSocket(int family,
|
|
int type) {
|
|
return nullptr;
|
|
}
|
|
|
|
RunLoop::WorkerThread::WorkerThread(rtc::SocketServer* ss)
|
|
: rtc::Thread(ss), tq_setter_(this) {}
|
|
|
|
} // namespace test
|
|
} // namespace webrtc
|