Use RunLoop in rtc_base/ tests Bug: webrtc:469327588 Change-Id: Ib419c8d1d26c5db2107048ba4780d16d6a6a6964 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/461342 Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Auto-Submit: Evan Shrubsole <eshr@webrtc.org> Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Cr-Commit-Position: refs/heads/main@{#47307}
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn index 7f9af04..380090a 100644 --- a/rtc_base/BUILD.gn +++ b/rtc_base/BUILD.gn
@@ -759,6 +759,7 @@ "../api/task_queue", "../api/task_queue:task_queue_test", "../api/units:time_delta", + "../test:run_loop", "../test:test_support", "//third_party/abseil-cpp/absl/strings:string_view", ] @@ -1128,6 +1129,7 @@ deps = [ ":socket", ":socket_address", + "../test:run_loop", "../test:test_support", ] } @@ -1416,6 +1418,7 @@ ":async_packet_socket", ":socket", ":socket_address", + "../test:run_loop", "../test:test_support", "network:received_packet", ] @@ -1436,6 +1439,7 @@ "../api/units:timestamp", "../system_wrappers", "../test:create_test_environment", + "../test:run_loop", "../test:test_support", "network:received_packet", "//third_party/abseil-cpp/absl/memory", @@ -1451,6 +1455,7 @@ ":rtc_base_tests_utils", ":socket", "../test:create_test_environment", + "../test:run_loop", "../test:test_support", ] } @@ -1966,6 +1971,7 @@ sources = [ "untyped_function_unittest.cc" ] deps = [ ":untyped_function", + "../test:run_loop", "../test:test_support", ] } @@ -1982,6 +1988,7 @@ "../api:rtc_error_matchers", "../api:scoped_refptr", "../api/units:time_delta", + "../test:run_loop", "../test:test_support", "../test:wait_until", ] @@ -2154,6 +2161,7 @@ "../system_wrappers", "../test:create_test_environment", "../test:fileutils", + "../test:run_loop", "../test:test_support", "../test/time_controller", "containers:flat_map", @@ -2186,6 +2194,7 @@ ":timeutils", "../api/task_queue", "../api/units:time_delta", + "../test:run_loop", "../test:test_support", "//third_party/abseil-cpp/absl/memory", ] @@ -2200,6 +2209,7 @@ ":rtc_event", ":task_queue_for_test", ":weak_ptr", + "../test:run_loop", "../test:test_support", ] } @@ -2224,6 +2234,7 @@ ":timeutils", ":windowed_min_filter", "../api/units:time_delta", + "../test:run_loop", "../test:test_support", "//testing/gtest", "//third_party/abseil-cpp/absl/algorithm:container", @@ -2237,6 +2248,7 @@ deps = [ ":rtc_base_tests_utils", ":rtc_json", + "../test:run_loop", "../test:test_support", ] }
diff --git a/rtc_base/memory/BUILD.gn b/rtc_base/memory/BUILD.gn index 60da019..2a0ec55 100644 --- a/rtc_base/memory/BUILD.gn +++ b/rtc_base/memory/BUILD.gn
@@ -59,6 +59,7 @@ ":fifo_buffer", "..:stream", "..:threading", + "../../test:run_loop", "../../test:test_support", ] }
diff --git a/rtc_base/memory/fifo_buffer_unittest.cc b/rtc_base/memory/fifo_buffer_unittest.cc index e5f2070..a5ebd88 100644 --- a/rtc_base/memory/fifo_buffer_unittest.cc +++ b/rtc_base/memory/fifo_buffer_unittest.cc
@@ -15,13 +15,13 @@ #include <span> #include "rtc_base/stream.h" -#include "rtc_base/thread.h" #include "test/gtest.h" +#include "test/run_loop.h" namespace webrtc { TEST(FifoBufferTest, TestAll) { - AutoThread main_thread; + test::RunLoop main_thread; const size_t kSize = 16; const uint8_t in[kSize * 2 + 1] = "0123456789ABCDEFGHIJKLMNOPQRSTUV"; uint8_t out[kSize * 2]; @@ -219,7 +219,7 @@ } TEST(FifoBufferTest, FullBufferCheck) { - AutoThread main_thread; + test::RunLoop main_thread; FifoBuffer buff(10); buff.ConsumeWriteBuffer(10);
diff --git a/rtc_base/network_unittest.cc b/rtc_base/network_unittest.cc index 380580f..c93de94 100644 --- a/rtc_base/network_unittest.cc +++ b/rtc_base/network_unittest.cc
@@ -38,10 +38,10 @@ #include "rtc_base/network_monitor_factory.h" #include "rtc_base/physical_socket_server.h" #include "rtc_base/socket_address.h" -#include "rtc_base/thread.h" #include "test/create_test_field_trials.h" #include "test/gmock.h" #include "test/gtest.h" +#include "test/run_loop.h" #include "test/wait_until.h" // IWYU pragma: begin_keep @@ -332,7 +332,7 @@ protected: const FieldTrials field_trials_ = CreateTestFieldTrials(); const Environment env_ = CreateEnvironment(&field_trials_); - AutoThread main_thread_; + test::RunLoop main_thread_; bool callback_called_ = false; }; @@ -430,14 +430,14 @@ EXPECT_EQ(NetworkManager::ENUMERATION_ALLOWED, manager.enumeration_permission()); manager.StartUpdating(); - Thread::Current()->ProcessMessages(0); + main_thread_.Flush(); EXPECT_TRUE(callback_called_); callback_called_ = false; // Callback should be triggered immediately when StartUpdating // is called, after network update signal is already sent. manager.StartUpdating(); EXPECT_TRUE(manager.started()); - Thread::Current()->ProcessMessages(0); + main_thread_.Flush(); EXPECT_TRUE(callback_called_); manager.StopUpdating(); EXPECT_TRUE(manager.started()); @@ -451,7 +451,7 @@ // Callback should be triggered immediately after StartUpdating is called // when start_count_ is reset to 0. manager.StartUpdating(); - Thread::Current()->ProcessMessages(0); + main_thread_.Flush(); EXPECT_TRUE(callback_called_); }
diff --git a/rtc_base/openssl_adapter_unittest.cc b/rtc_base/openssl_adapter_unittest.cc index 7f64cbf..8d40fd8 100644 --- a/rtc_base/openssl_adapter_unittest.cc +++ b/rtc_base/openssl_adapter_unittest.cc
@@ -26,10 +26,10 @@ #include "rtc_base/socket.h" #include "rtc_base/socket_address.h" #include "rtc_base/ssl_certificate.h" -#include "rtc_base/ssl_stream_adapter.h" // IWYU pragma: keep -#include "rtc_base/thread.h" +#include "rtc_base/ssl_stream_adapter.h" // IWYU pragma: keep #include "test/gmock.h" #include "test/gtest.h" +#include "test/run_loop.h" #include "test/wait_until.h" // IWYU pragma: keep namespace webrtc { @@ -145,7 +145,7 @@ // Verifies that SSLStart works when OpenSSLAdapter is started in standalone // mode. TEST(OpenSSLAdapterTest, TestBeginSSLBeforeConnection) { - AutoThread main_thread; + test::RunLoop main_thread; Socket* async_socket = new MockAsyncSocket(); OpenSSLAdapter adapter(async_socket); EXPECT_EQ(adapter.StartSSL("webrtc.org"), 0); @@ -158,7 +158,7 @@ // build and run this test. TEST(OpenSSLAdaptorTest, TestRealSSLConnection) { PhysicalSocketServer socket_server; - AutoSocketServerThread main_thread(&socket_server); + test::RunLoop main_thread(&socket_server); constexpr absl::string_view kHostname = "webrtc.org"; constexpr int kPort = 443; @@ -213,7 +213,7 @@ // Verifies that the adapter factory can create new adapters. TEST(OpenSSLAdapterFactoryTest, CreateSingleOpenSSLAdapter) { - AutoThread main_thread; + test::RunLoop main_thread; OpenSSLAdapterFactory adapter_factory; Socket* async_socket = new MockAsyncSocket(); auto simple_adapter = std::unique_ptr<OpenSSLAdapter>( @@ -224,7 +224,7 @@ // Verifies that setting a custom verifier still allows for adapters to be // created. TEST(OpenSSLAdapterFactoryTest, CreateWorksWithCustomVerifier) { - AutoThread main_thread; + test::RunLoop main_thread; MockCertVerifier* mock_verifier = new MockCertVerifier(); EXPECT_CALL(*mock_verifier, Verify(_)).WillRepeatedly(Return(true)); auto cert_verifier = std::unique_ptr<SSLCertificateVerifier>(mock_verifier);
diff --git a/rtc_base/operations_chain_unittest.cc b/rtc_base/operations_chain_unittest.cc index 9f7ce22..667b189 100644 --- a/rtc_base/operations_chain_unittest.cc +++ b/rtc_base/operations_chain_unittest.cc
@@ -25,6 +25,7 @@ #include "rtc_base/thread.h" #include "test/gmock.h" #include "test/gtest.h" +#include "test/run_loop.h" #include "test/wait_until.h" namespace webrtc { @@ -397,7 +398,7 @@ } TEST(OperationsChainTest, OnChainEmptyCallback) { - AutoThread main_thread; + test::RunLoop main_thread; OperationTrackerProxy operation_tracker_proxy; operation_tracker_proxy.Initialize()->Wait(Event::kForever);
diff --git a/rtc_base/physical_socket_server_unittest.cc b/rtc_base/physical_socket_server_unittest.cc index 56ec609..909c80e 100644 --- a/rtc_base/physical_socket_server_unittest.cc +++ b/rtc_base/physical_socket_server_unittest.cc
@@ -24,9 +24,9 @@ #include "rtc_base/socket_address.h" #include "rtc_base/socket_unittest.h" #include "rtc_base/test_utils.h" -#include "rtc_base/thread.h" #include "test/gmock.h" #include "test/gtest.h" +#include "test/run_loop.h" #include "test/wait_until.h" #define MAYBE_SKIP_IPV4 \ @@ -130,7 +130,7 @@ void WritableAfterPartialWrite(const IPAddress& loopback); FakePhysicalSocketServer server_; - AutoSocketServerThread thread_; + test::RunLoop thread_; bool fail_accept_; int max_send_size_; };
diff --git a/rtc_base/rtc_certificate_generator_unittest.cc b/rtc_base/rtc_certificate_generator_unittest.cc index 06bb581..10b9b4b 100644 --- a/rtc_base/rtc_certificate_generator_unittest.cc +++ b/rtc_base/rtc_certificate_generator_unittest.cc
@@ -24,6 +24,7 @@ #include "rtc_base/thread.h" #include "test/gmock.h" #include "test/gtest.h" +#include "test/run_loop.h" #include "test/wait_until.h" namespace webrtc { @@ -74,7 +75,7 @@ protected: static constexpr TimeDelta kGenerationTimeoutMs = TimeDelta::Millis(10000); - AutoThread main_thread_; + test::RunLoop main_thread_; RTCCertificateGeneratorFixture fixture_; };
diff --git a/rtc_base/ssl_adapter_unittest.cc b/rtc_base/ssl_adapter_unittest.cc index 79c987a..a4a069b 100644 --- a/rtc_base/ssl_adapter_unittest.cc +++ b/rtc_base/ssl_adapter_unittest.cc
@@ -30,6 +30,7 @@ #include "rtc_base/virtual_socket_server.h" #include "test/gmock.h" #include "test/gtest.h" +#include "test/run_loop.h" #include "test/wait_until.h" namespace webrtc { @@ -291,7 +292,7 @@ protected: std::unique_ptr<VirtualSocketServer> vss_; - AutoSocketServerThread thread_; + test::RunLoop thread_; std::unique_ptr<SSLAdapterTestDummyServer> server_; std::unique_ptr<SSLAdapterTestDummyClient> client_; std::unique_ptr<SSLCertificateVerifier> cert_verifier_;