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