commit 3221035361e56e63f3a550b3004555e00be10176
parent faec86244032335e37586082db62c4ee7de1f1c9
Author: Dan Baker <dbaker@mozilla.com>
Date: Mon, 1 Dec 2025 16:34:22 -0700
Bug 2000941 - Vendor libwebrtc from a1586f1353
Upstream commit: https://webrtc.googlesource.com/src/+/a1586f13539ea0a409e26dca620ad97200c6d952
Reland "Remove use of global clocks in TestClient"
This is a reland of commit 5b634ccedca5ab7969edc68fca15d327aa0440d3
Safe to reland: Reverted changes to the test_client API
Original change's description:
> Remove use of global clocks in TestClient
>
> The functions that are relevant here can be abstracted away with
> WaitUntil, which is available since this is a test-only target. This
> may be updated once the ClockVariant is simplified to relevant clocks
> for testing.
>
> Bug: webrtc:42223992
> Change-Id: I68a0514be56931e44777f4cd086f5ea794da377a
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/407405
> Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
> Commit-Queue: Evan Shrubsole <eshr@webrtc.org>
> Auto-Submit: Evan Shrubsole <eshr@webrtc.org>
> Cr-Commit-Position: refs/heads/main@{#45529}
Bug: webrtc:42223992
Change-Id: I6c3e7d485f4c020a206987d6d9e17ce44eb2b901
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/408000
Auto-Submit: Evan Shrubsole <eshr@webrtc.org>
Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org>
Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#45563}
Diffstat:
11 files changed, 39 insertions(+), 57 deletions(-)
diff --git a/third_party/libwebrtc/README.mozilla.last-vendor b/third_party/libwebrtc/README.mozilla.last-vendor
@@ -1,4 +1,4 @@
# ./mach python dom/media/webrtc/third_party_build/vendor-libwebrtc.py --from-local /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc --commit mozpatches libwebrtc
-libwebrtc updated from /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-12-01T17:51:49.772624+00:00.
+libwebrtc updated from /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-12-01T23:34:10.225966+00:00.
# base of lastest vendoring
-20786cda42
+a1586f1353
diff --git a/third_party/libwebrtc/moz-patch-stack/s0001.patch b/third_party/libwebrtc/moz-patch-stack/s0001.patch
@@ -1392,7 +1392,7 @@ index 5ccc3d7d38..cd957416bc 100644
const bool enable_svc_for_simulcast_;
std::optional<SimulcastToSvcConverter> simulcast_to_svc_converter_;
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn
-index 2060770660..00af8c72fc 100644
+index ebdb3a07c9..e894327590 100644
--- a/rtc_base/BUILD.gn
+++ b/rtc_base/BUILD.gn
@@ -449,6 +449,12 @@ rtc_library("logging") {
diff --git a/third_party/libwebrtc/moz-patch-stack/s0027.patch b/third_party/libwebrtc/moz-patch-stack/s0027.patch
@@ -1008,7 +1008,7 @@ index 39aa39a41c..b26e30e8bb 100644
"/config/external/nspr",
"/nsprpub/lib/ds",
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn
-index 00af8c72fc..e9ba704d5c 100644
+index e894327590..6c9d891fff 100644
--- a/rtc_base/BUILD.gn
+++ b/rtc_base/BUILD.gn
@@ -326,6 +326,7 @@ rtc_library("sample_counter") {
@@ -1176,7 +1176,7 @@ index 00af8c72fc..e9ba704d5c 100644
rtc_library("ssl_adapter") {
visibility = [ "*" ]
-@@ -2367,7 +2391,7 @@ if (rtc_include_tests) {
+@@ -2368,7 +2392,7 @@ if (rtc_include_tests) {
}
}
diff --git a/third_party/libwebrtc/moz-patch-stack/s0053.patch b/third_party/libwebrtc/moz-patch-stack/s0053.patch
@@ -29,7 +29,7 @@ index 7db75d5fd3..d0feb5007c 100644
rtc_library("task_queue_test") {
visibility = [ "*" ]
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn
-index e9ba704d5c..18107688b2 100644
+index 6c9d891fff..c476050661 100644
--- a/rtc_base/BUILD.gn
+++ b/rtc_base/BUILD.gn
@@ -664,10 +664,14 @@ if (is_mac || is_ios) {
diff --git a/third_party/libwebrtc/moz-patch-stack/s0091.patch b/third_party/libwebrtc/moz-patch-stack/s0091.patch
@@ -13,7 +13,7 @@ Mercurial Revision: https://hg.mozilla.org/mozilla-central/rev/4e7b3c485e549e7e3
1 file changed, 6 insertions(+)
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn
-index 18107688b2..394508e540 100644
+index c476050661..f419602aa2 100644
--- a/rtc_base/BUILD.gn
+++ b/rtc_base/BUILD.gn
@@ -992,6 +992,12 @@ rtc_library("threading") {
diff --git a/third_party/libwebrtc/moz-patch-stack/s0094.patch b/third_party/libwebrtc/moz-patch-stack/s0094.patch
@@ -9,7 +9,7 @@ Mercurial Revision: https://hg.mozilla.org/mozilla-central/rev/ee2f06666bcc6d22c
1 file changed, 2 insertions(+)
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn
-index 394508e540..407b23107b 100644
+index f419602aa2..836e6d2ca0 100644
--- a/rtc_base/BUILD.gn
+++ b/rtc_base/BUILD.gn
@@ -1679,6 +1679,7 @@ if (!build_with_mozilla) {
diff --git a/third_party/libwebrtc/moz-patch-stack/s0102.patch b/third_party/libwebrtc/moz-patch-stack/s0102.patch
@@ -616,7 +616,7 @@ index 696829d6ca..81bd2a6215 100644
if (rtc_build_libsrtp) {
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn
-index 407b23107b..ed7dfdc027 100644
+index 836e6d2ca0..5439f86438 100644
--- a/rtc_base/BUILD.gn
+++ b/rtc_base/BUILD.gn
@@ -9,8 +9,8 @@
@@ -630,7 +630,7 @@ index 407b23107b..ed7dfdc027 100644
}
rtc_source_set("protobuf_utils") {
-@@ -1920,8 +1920,8 @@ if (!rtc_rusty_base64) {
+@@ -1921,8 +1921,8 @@ if (!rtc_rusty_base64) {
]
}
} else {
diff --git a/third_party/libwebrtc/moz-patch-stack/s0107.patch b/third_party/libwebrtc/moz-patch-stack/s0107.patch
@@ -116,7 +116,7 @@ index ecbb7eae7e..a13fe19324 100644
public_configs = []
if (!build_with_chromium) {
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn
-index ed7dfdc027..72ec909095 100644
+index 5439f86438..6042579110 100644
--- a/rtc_base/BUILD.gn
+++ b/rtc_base/BUILD.gn
@@ -1558,6 +1558,7 @@ rtc_source_set("ssl_header") {
diff --git a/third_party/libwebrtc/rtc_base/BUILD.gn b/third_party/libwebrtc/rtc_base/BUILD.gn
@@ -1769,6 +1769,7 @@ rtc_library("testclient") {
":timeutils",
"../api/units:time_delta",
"../api/units:timestamp",
+ "../test:wait_until",
"network:received_packet",
"synchronization:mutex",
"third_party/sigslot",
diff --git a/third_party/libwebrtc/rtc_base/test_client.cc b/third_party/libwebrtc/rtc_base/test_client.cc
@@ -10,22 +10,20 @@
#include "rtc_base/test_client.h"
-#include <cstdint>
#include <cstring>
#include <memory>
#include <optional>
#include <utility>
+#include <variant>
#include "api/units/time_delta.h"
#include "api/units/timestamp.h"
#include "rtc_base/async_packet_socket.h"
-#include "rtc_base/fake_clock.h"
#include "rtc_base/network/received_packet.h"
#include "rtc_base/socket.h"
#include "rtc_base/socket_address.h"
#include "rtc_base/synchronization/mutex.h"
-#include "rtc_base/thread.h"
-#include "rtc_base/time_utils.h"
+#include "test/wait_until.h"
namespace webrtc {
@@ -34,11 +32,11 @@ namespace webrtc {
// NextPacket.
TestClient::TestClient(std::unique_ptr<AsyncPacketSocket> socket)
- : TestClient(std::move(socket), nullptr) {}
+ : TestClient(std::move(socket), std::monostate()) {}
TestClient::TestClient(std::unique_ptr<AsyncPacketSocket> socket,
- ThreadProcessingFakeClock* fake_clock)
- : fake_clock_(fake_clock), socket_(std::move(socket)) {
+ ClockVariant clock)
+ : clock_(clock), socket_(std::move(socket)) {
socket_->RegisterReceivedPacketCallback(
[&](AsyncPacketSocket* socket, const ReceivedIpPacket& packet) {
OnPacket(socket, packet);
@@ -50,11 +48,8 @@ TestClient::~TestClient() {}
bool TestClient::CheckConnState(AsyncPacketSocket::State state) {
// Wait for our timeout value until the socket reaches the desired state.
- int64_t end = TimeAfter(kTimeoutMs);
- while (socket_->GetState() != state && TimeUntil(end) > 0) {
- AdvanceTime(1);
- }
- return (socket_->GetState() == state);
+ return WaitUntil([&]() { return socket_->GetState() == state; },
+ {.clock = clock_});
}
int TestClient::Send(const char* buf, size_t size) {
@@ -80,22 +75,22 @@ std::unique_ptr<TestClient::Packet> TestClient::NextPacket(int timeout_ms) {
// Note also that we only try to pump our current thread's message queue.
// Pumping another thread's queue could lead to messages being dispatched from
// the wrong thread to non-thread-safe objects.
-
- int64_t end = TimeAfter(timeout_ms);
- while (TimeUntil(end) > 0) {
- {
- MutexLock lock(&mutex_);
- if (!packets_.empty()) {
- break;
- }
- }
- AdvanceTime(1);
- }
+ TimeDelta timeout = TimeDelta::Millis(timeout_ms);
+
+ bool packets_available = WaitUntil(
+ [&] {
+ MutexLock lock(&mutex_);
+ return !packets_.empty();
+ },
+ {
+ .timeout = timeout,
+ .clock = clock_,
+ });
// Return the first packet placed in the queue.
std::unique_ptr<Packet> packet;
MutexLock lock(&mutex_);
- if (!packets_.empty()) {
+ if (packets_available) {
packet = std::move(packets_.front());
packets_.erase(packets_.begin());
}
@@ -132,20 +127,8 @@ bool TestClient::CheckTimestamp(std::optional<Timestamp> packet_timestamp) {
return res;
}
-void TestClient::AdvanceTime(int ms) {
- // If the test is using a fake clock, we must advance the fake clock to
- // advance time. Otherwise, ProcessMessages will work.
- if (fake_clock_) {
- for (int64_t start = TimeMillis(); TimeMillis() < start + ms;) {
- fake_clock_->AdvanceTime(TimeDelta::Millis(1));
- };
- } else {
- Thread::Current()->ProcessMessages(1);
- }
-}
-
bool TestClient::CheckNoPacket() {
- return NextPacket(kNoPacketTimeoutMs) == nullptr;
+ return NextPacket(kNoPacketTimeout.ms()) == nullptr;
}
int TestClient::GetError() {
diff --git a/third_party/libwebrtc/rtc_base/test_client.h b/third_party/libwebrtc/rtc_base/test_client.h
@@ -16,15 +16,16 @@
#include <optional>
#include <vector>
+#include "api/units/time_delta.h"
#include "api/units/timestamp.h"
#include "rtc_base/async_packet_socket.h"
#include "rtc_base/buffer.h"
-#include "rtc_base/fake_clock.h"
#include "rtc_base/network/received_packet.h"
#include "rtc_base/socket.h"
#include "rtc_base/socket_address.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/third_party/sigslot/sigslot.h"
+#include "test/wait_until.h"
namespace webrtc {
@@ -43,7 +44,7 @@ class TestClient : public sigslot::has_slots<> {
};
// Default timeout for NextPacket reads.
- static const int kTimeoutMs = 5000;
+ static constexpr int kTimeoutMs = 5000;
// Creates a client that will send and receive with the given socket and
// will post itself messages with the given thread.
@@ -51,8 +52,7 @@ class TestClient : public sigslot::has_slots<> {
// Create a test client that will use a fake clock. NextPacket needs to wait
// for a packet to be received, and thus it needs to advance the fake clock
// if the test is using one, rather than just sleeping.
- TestClient(std::unique_ptr<AsyncPacketSocket> socket,
- ThreadProcessingFakeClock* fake_clock);
+ TestClient(std::unique_ptr<AsyncPacketSocket> socket, ClockVariant clock);
~TestClient() override;
TestClient(const TestClient&) = delete;
@@ -81,7 +81,7 @@ class TestClient : public sigslot::has_slots<> {
// Checks that the next packet has the given contents. Returns the remote
// address that the packet was sent from.
- bool CheckNextPacket(const char* buf, size_t len, SocketAddress* addr);
+ bool CheckNextPacket(const char* buf, size_t size, SocketAddress* addr);
// Checks that no packets have arrived or will arrive in the next second.
bool CheckNoPacket();
@@ -96,7 +96,7 @@ class TestClient : public sigslot::has_slots<> {
private:
// Timeout for reads when no packet is expected.
- static const int kNoPacketTimeoutMs = 1000;
+ static constexpr TimeDelta kNoPacketTimeout = TimeDelta::Seconds(1);
// Workaround for the fact that AsyncPacketSocket::GetConnState doesn't exist.
Socket::ConnState GetState();
@@ -104,9 +104,8 @@ class TestClient : public sigslot::has_slots<> {
const ReceivedIpPacket& received_packet);
void OnReadyToSend(AsyncPacketSocket* socket);
bool CheckTimestamp(std::optional<Timestamp> packet_timestamp);
- void AdvanceTime(int ms);
- ThreadProcessingFakeClock* fake_clock_ = nullptr;
+ ClockVariant clock_;
Mutex mutex_;
std::unique_ptr<AsyncPacketSocket> socket_;
std::vector<std::unique_ptr<Packet>> packets_;
@@ -116,5 +115,4 @@ class TestClient : public sigslot::has_slots<> {
} // namespace webrtc
-
#endif // RTC_BASE_TEST_CLIENT_H_