RtcEventLogImpl: Add test cases
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 <handellm@webrtc.org> Reviewed-by: Björn Terelius <terelius@webrtc.org> Commit-Queue: Björn Terelius <terelius@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39253}
This commit is contained in:
parent
d1831cb4f8
commit
85abbdf526
|
@ -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<FakeConfigEvent>();
|
||||
RtcEvent* c1_ptr = c1.get();
|
||||
auto c2 = std::make_unique<FakeConfigEvent>();
|
||||
RtcEvent* c2_ptr = c2.get();
|
||||
auto c3 = std::make_unique<FakeConfigEvent>();
|
||||
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<FakeEvent>();
|
||||
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<FakeConfigEvent>();
|
||||
RtcEvent* c1_ptr = c1.get();
|
||||
auto c2 = std::make_unique<FakeConfigEvent>();
|
||||
RtcEvent* c2_ptr = c2.get();
|
||||
auto c3 = std::make_unique<FakeConfigEvent>();
|
||||
RtcEvent* c3_ptr = c3.get();
|
||||
auto c4 = std::make_unique<FakeConfigEvent>();
|
||||
RtcEvent* c4_ptr = c4.get();
|
||||
auto c5 = std::make_unique<FakeConfigEvent>();
|
||||
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<FakeOutput>(written_data_),
|
||||
kOutputPeriod.ms());
|
||||
event_log_.Log(std::make_unique<FakeConfigEvent>());
|
||||
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<FakeOutput>(written_data_),
|
||||
kOutputPeriod.ms());
|
||||
event_log_.Log(std::move(c4));
|
||||
event_log_.Log(std::move(c5));
|
||||
event_log_.Log(std::make_unique<FakeEvent>());
|
||||
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<FakeOutput>(written_data_),
|
||||
kOutputPeriod.ms());
|
||||
event_log_.Log(std::make_unique<FakeConfigEvent>());
|
||||
for (size_t i = 0; i < kNumberOfEvents; i++) {
|
||||
event_log_.Log(std::make_unique<FakeEvent>());
|
||||
}
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue