From 85abbdf526f2dc283942c61ba880c409a611e5f2 Mon Sep 17 00:00:00 2001 From: Xuanxi Leng Date: Thu, 2 Feb 2023 05:08:37 -0500 Subject: [PATCH] RtcEventLogImpl: Add test cases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change adds below test cases: 1. Keep most recent config events on start. 2. Rewrite all previous config events on restart. 3. Do not drop events when far more events than max event history logged on logging start. Bug: chromium:1288710 Change-Id: Ifc227e8be788d33dc2ed65f49281b3d0809231c6 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/291739 Reviewed-by: Markus Handell Reviewed-by: Björn Terelius Commit-Queue: Björn Terelius Cr-Commit-Position: refs/heads/main@{#39253} --- .../rtc_event_log_impl_unittest.cc | 75 +++++++++++++++++-- 1 file changed, 70 insertions(+), 5 deletions(-) diff --git a/logging/rtc_event_log/rtc_event_log_impl_unittest.cc b/logging/rtc_event_log/rtc_event_log_impl_unittest.cc index d32af8fe23..aea6c7974e 100644 --- a/logging/rtc_event_log/rtc_event_log_impl_unittest.cc +++ b/logging/rtc_event_log/rtc_event_log_impl_unittest.cc @@ -80,7 +80,7 @@ class FakeConfigEvent : public RtcEvent { class RtcEventLogImplTest : public ::testing::Test { public: static constexpr size_t kMaxEventsInHistory = 2; - static constexpr size_t kMaxEventsInConfigHistory = 3; + static constexpr size_t kMaxEventsInConfigHistory = 5; static constexpr TimeDelta kOutputPeriod = TimeDelta::Seconds(2); static constexpr Timestamp kStartTime = Timestamp::Seconds(1); @@ -132,6 +132,26 @@ TEST_F(RtcEventLogImplTest, KeepsMostRecentEventsOnStart) { Mock::VerifyAndClearExpectations(encoder_ptr_); } +TEST_F(RtcEventLogImplTest, KeepsConfigEventsOnStart) { + // The config-history is supposed to be unbounded and never overflow. + auto c1 = std::make_unique(); + RtcEvent* c1_ptr = c1.get(); + auto c2 = std::make_unique(); + RtcEvent* c2_ptr = c2.get(); + auto c3 = std::make_unique(); + RtcEvent* c3_ptr = c3.get(); + event_log_.Log(std::move(c1)); + event_log_.Log(std::move(c2)); + event_log_.Log(std::move(c3)); + InSequence s; + EXPECT_CALL(*encoder_ptr_, OnEncode(Ref(*c1_ptr))); + EXPECT_CALL(*encoder_ptr_, OnEncode(Ref(*c2_ptr))); + EXPECT_CALL(*encoder_ptr_, OnEncode(Ref(*c3_ptr))); + event_log_.StartLogging(std::move(output_), kOutputPeriod.ms()); + time_controller_.AdvanceTime(TimeDelta::Zero()); + Mock::VerifyAndClearExpectations(encoder_ptr_); +} + TEST_F(RtcEventLogImplTest, EncodesEventsOnHistoryFullPostponesLastEncode) { auto e1 = std::make_unique(); RtcEvent* e1_ptr = e1.get(); @@ -155,14 +175,41 @@ TEST_F(RtcEventLogImplTest, EncodesEventsOnHistoryFullPostponesLastEncode) { Mock::VerifyAndClearExpectations(encoder_ptr_); } -TEST_F(RtcEventLogImplTest, RewritesConfigEventsOnlyOnRestart) { +TEST_F(RtcEventLogImplTest, RewritesAllConfigEventsOnlyOnRestart) { + auto c1 = std::make_unique(); + RtcEvent* c1_ptr = c1.get(); + auto c2 = std::make_unique(); + RtcEvent* c2_ptr = c2.get(); + auto c3 = std::make_unique(); + RtcEvent* c3_ptr = c3.get(); + auto c4 = std::make_unique(); + RtcEvent* c4_ptr = c4.get(); + auto c5 = std::make_unique(); + RtcEvent* c5_ptr = c5.get(); + // Keep the config event before start. + event_log_.Log(std::move(c1)); + // Start logging. event_log_.StartLogging(std::make_unique(written_data_), kOutputPeriod.ms()); - event_log_.Log(std::make_unique()); + event_log_.Log(std::move(c2)); + event_log_.Log(std::move(c3)); + event_log_.StopLogging(); + time_controller_.AdvanceTime(TimeDelta::Zero()); + // Restart logging. + event_log_.StartLogging(std::make_unique(written_data_), + kOutputPeriod.ms()); + event_log_.Log(std::move(c4)); + event_log_.Log(std::move(c5)); event_log_.Log(std::make_unique()); event_log_.StopLogging(); - EXPECT_CALL(*encoder_ptr_, - OnEncode(Property(&RtcEvent::IsConfigEvent, true))); + time_controller_.AdvanceTime(TimeDelta::Zero()); + InSequence s; + // Rewrite all config events in sequence on next restart. + EXPECT_CALL(*encoder_ptr_, OnEncode(Ref(*c1_ptr))); + EXPECT_CALL(*encoder_ptr_, OnEncode(Ref(*c2_ptr))); + EXPECT_CALL(*encoder_ptr_, OnEncode(Ref(*c3_ptr))); + EXPECT_CALL(*encoder_ptr_, OnEncode(Ref(*c4_ptr))); + EXPECT_CALL(*encoder_ptr_, OnEncode(Ref(*c5_ptr))); EXPECT_CALL(*encoder_ptr_, OnEncode(Property(&RtcEvent::IsConfigEvent, false))) .Times(0); @@ -184,5 +231,23 @@ TEST_F(RtcEventLogImplTest, SchedulesWriteAfterOutputDurationPassed) { Mock::VerifyAndClearExpectations(encoder_ptr_); } +TEST_F(RtcEventLogImplTest, DoNotDropEventsIfHistoryFullAfterStarted) { + const size_t kNumberOfEvents = 10 * kMaxEventsInHistory; + + event_log_.StartLogging(std::make_unique(written_data_), + kOutputPeriod.ms()); + event_log_.Log(std::make_unique()); + for (size_t i = 0; i < kNumberOfEvents; i++) { + event_log_.Log(std::make_unique()); + } + EXPECT_CALL(*encoder_ptr_, + OnEncode(Property(&RtcEvent::IsConfigEvent, true))); + EXPECT_CALL(*encoder_ptr_, + OnEncode(Property(&RtcEvent::IsConfigEvent, false))) + .Times(kNumberOfEvents); + time_controller_.AdvanceTime(kOutputPeriod); + Mock::VerifyAndClearExpectations(encoder_ptr_); +} + } // namespace } // namespace webrtc