Use injected clock in ssl_stream_adapter_unittest Removes use of AutoThread and ScopedFakeClock to boot. Bug: webrtc:469327588,webrtc:42223992 Change-Id: I1b06f1666ec68af67fa1896b364981f26a6a6964 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/455941 Auto-Submit: Evan Shrubsole <eshr@webrtc.org> Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org> Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Cr-Commit-Position: refs/heads/main@{#47170}
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn index 59fea18..b98dcd6 100644 --- a/rtc_base/BUILD.gn +++ b/rtc_base/BUILD.gn
@@ -2358,6 +2358,7 @@ "../test:run_loop", "../test:test_support", "../test:wait_until", + "../test/time_controller", "memory:fifo_buffer", "network:received_packet", "synchronization:mutex",
diff --git a/rtc_base/ssl_stream_adapter_unittest.cc b/rtc_base/ssl_stream_adapter_unittest.cc index 67bfc10..8bd26c3 100644 --- a/rtc_base/ssl_stream_adapter_unittest.cc +++ b/rtc_base/ssl_stream_adapter_unittest.cc
@@ -39,22 +39,22 @@ #include "api/task_queue/pending_task_safety_flag.h" #include "api/test/rtc_error_matchers.h" #include "api/units/time_delta.h" +#include "api/units/timestamp.h" #include "rtc_base/buffer.h" #include "rtc_base/buffer_queue.h" #include "rtc_base/callback_list.h" #include "rtc_base/checks.h" #include "rtc_base/crypto_random.h" -#include "rtc_base/fake_clock.h" #include "rtc_base/logging.h" #include "rtc_base/message_digest.h" #include "rtc_base/ssl_certificate.h" #include "rtc_base/ssl_identity.h" #include "rtc_base/stream.h" #include "rtc_base/thread.h" -#include "rtc_base/time_utils.h" #include "test/create_test_field_trials.h" #include "test/gmock.h" #include "test/gtest.h" +#include "test/time_controller/simulated_time_controller.h" #include "test/wait_until.h" namespace webrtc { @@ -591,20 +591,21 @@ (server_ssl_->GetState() == SS_OPEN); }, ::testing::IsTrue(), - {.timeout = handshake_wait_, .clock = &clock_}), + {.timeout = handshake_wait_, .clock = &time_controller_}), IsRtcOk()); } else { - EXPECT_THAT(WaitUntil([&] { return client_ssl_->GetState(); }, - ::testing::Eq(SS_CLOSED), - {.timeout = handshake_wait_, .clock = &clock_}), - IsRtcOk()); + EXPECT_THAT( + WaitUntil([&] { return client_ssl_->GetState(); }, + ::testing::Eq(SS_CLOSED), + {.timeout = handshake_wait_, .clock = &time_controller_}), + IsRtcOk()); } } // This tests that we give up after one hour. // Only works for BoringSSL which allows advancing the fake clock. void TestHandshakeTimeout() { - int64_t time_start = clock_.TimeNanos(); + Timestamp time_start = time_controller_.GetClock()->CurrentTime(); TimeDelta time_increment = TimeDelta::Millis(1000); if (!dtls_) { @@ -632,16 +633,16 @@ // Now wait for the handshake to timeout (or fail after an hour of simulated // time). while (client_ssl_->GetState() == SS_OPENING && - (TimeDiff(clock_.TimeNanos(), time_start) < - 3600 * kNumNanosecsPerSec)) { + (time_controller_.GetClock()->CurrentTime() - time_start < + TimeDelta::Minutes(60))) { EXPECT_THAT(WaitUntil( [&] { return !((client_ssl_->GetState() == SS_OPEN) && (server_ssl_->GetState() == SS_OPEN)); }, - ::testing::IsTrue(), {.clock = &clock_}), + ::testing::IsTrue(), {.clock = &time_controller_}), IsRtcOk()); - clock_.AdvanceTime(time_increment); + time_controller_.AdvanceTime(time_increment); } EXPECT_EQ(client_ssl_->GetState(), SS_CLOSED); } @@ -671,7 +672,7 @@ server_ssl_->IsTlsConnected(); }, ::testing::IsTrue(), - {.timeout = handshake_wait_, .clock = &clock_}), + {.timeout = handshake_wait_, .clock = &time_controller_}), IsRtcOk()); // Until the identity has been verified, the state should still be @@ -863,8 +864,7 @@ return server_ssl_->GetIdentityForTesting(); } - AutoThread main_thread_; - ScopedFakeClock clock_; + GlobalSimulatedTimeController time_controller_{Timestamp::Micros(1234567)}; std::string client_cert_pem_; std::string client_private_key_pem_; KeyParams client_key_type_; @@ -983,19 +983,19 @@ WriteData(); - EXPECT_THAT( - WaitUntil([&] { return sent_; }, ::testing::Eq(count_), - {.timeout = TimeDelta::Millis(10000), .clock = &clock_}), - IsRtcOk()); + EXPECT_THAT(WaitUntil([&] { return sent_; }, ::testing::Eq(count_), + {.timeout = TimeDelta::Millis(10000), + .clock = &time_controller_}), + IsRtcOk()); RTC_LOG(LS_INFO) << "sent_ == " << sent_; if (damage_) { - clock_.AdvanceTime(TimeDelta::Millis(2000)); + time_controller_.AdvanceTime(TimeDelta::Millis(2000)); EXPECT_EQ(0U, received_.size()); } else if (loss_ == 0) { EXPECT_THAT(WaitUntil([&] { return received_.size(); }, ::testing::Eq(static_cast<size_t>(sent_)), - {.clock = &clock_}), + {.clock = &time_controller_}), IsRtcOk()); } else { RTC_LOG(LS_INFO) << "Sent " << sent_ << " packets; received "