Add StopOutputOnWriteFailure to RtcEventLogImplTest
Bug: chromium:1288710 Change-Id: Ib913fb392077512d43ea408c95115129d3ff3425 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/295800 Reviewed-by: Björn Terelius <terelius@webrtc.org> Commit-Queue: Jianhui J Dai <jianhui.j.dai@intel.com> Reviewed-by: Markus Handell <handellm@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39509}
This commit is contained in:
parent
d4f2ccb7c0
commit
7d6b5b878f
@ -20,7 +20,9 @@
|
|||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
using ::testing::_;
|
||||||
using ::testing::InSequence;
|
using ::testing::InSequence;
|
||||||
|
using ::testing::Invoke;
|
||||||
using ::testing::Mock;
|
using ::testing::Mock;
|
||||||
using ::testing::Property;
|
using ::testing::Property;
|
||||||
using ::testing::Ref;
|
using ::testing::Ref;
|
||||||
@ -54,15 +56,26 @@ class FakeOutput : public RtcEventLogOutput {
|
|||||||
public:
|
public:
|
||||||
explicit FakeOutput(std::string& written_data)
|
explicit FakeOutput(std::string& written_data)
|
||||||
: written_data_(written_data) {}
|
: written_data_(written_data) {}
|
||||||
bool IsActive() const { return true; }
|
bool IsActive() const { return is_active_; }
|
||||||
bool Write(absl::string_view data) override {
|
bool Write(absl::string_view data) override {
|
||||||
written_data_.append(std::string(data));
|
RTC_DCHECK(is_active_);
|
||||||
return true;
|
if (fails_write_) {
|
||||||
|
is_active_ = false;
|
||||||
|
fails_write_ = false;
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
written_data_.append(std::string(data));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void Flush() override {}
|
void Flush() override {}
|
||||||
|
|
||||||
|
void FailsNextWrite() { fails_write_ = true; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string& written_data_;
|
std::string& written_data_;
|
||||||
|
bool is_active_ = true;
|
||||||
|
bool fails_write_ = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FakeEvent : public RtcEvent {
|
class FakeEvent : public RtcEvent {
|
||||||
@ -219,8 +232,7 @@ TEST_F(RtcEventLogImplTest, RewritesAllConfigEventsOnlyOnRestart) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(RtcEventLogImplTest, SchedulesWriteAfterOutputDurationPassed) {
|
TEST_F(RtcEventLogImplTest, SchedulesWriteAfterOutputDurationPassed) {
|
||||||
event_log_.StartLogging(std::make_unique<FakeOutput>(written_data_),
|
event_log_.StartLogging(std::move(output_), kOutputPeriod.ms());
|
||||||
kOutputPeriod.ms());
|
|
||||||
event_log_.Log(std::make_unique<FakeConfigEvent>());
|
event_log_.Log(std::make_unique<FakeConfigEvent>());
|
||||||
event_log_.Log(std::make_unique<FakeEvent>());
|
event_log_.Log(std::make_unique<FakeEvent>());
|
||||||
EXPECT_CALL(*encoder_ptr_,
|
EXPECT_CALL(*encoder_ptr_,
|
||||||
@ -232,10 +244,9 @@ TEST_F(RtcEventLogImplTest, SchedulesWriteAfterOutputDurationPassed) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(RtcEventLogImplTest, DoNotDropEventsIfHistoryFullAfterStarted) {
|
TEST_F(RtcEventLogImplTest, DoNotDropEventsIfHistoryFullAfterStarted) {
|
||||||
const size_t kNumberOfEvents = 10 * kMaxEventsInHistory;
|
constexpr size_t kNumberOfEvents = 10 * kMaxEventsInHistory;
|
||||||
|
|
||||||
event_log_.StartLogging(std::make_unique<FakeOutput>(written_data_),
|
event_log_.StartLogging(std::move(output_), kOutputPeriod.ms());
|
||||||
kOutputPeriod.ms());
|
|
||||||
event_log_.Log(std::make_unique<FakeConfigEvent>());
|
event_log_.Log(std::make_unique<FakeConfigEvent>());
|
||||||
for (size_t i = 0; i < kNumberOfEvents; i++) {
|
for (size_t i = 0; i < kNumberOfEvents; i++) {
|
||||||
event_log_.Log(std::make_unique<FakeEvent>());
|
event_log_.Log(std::make_unique<FakeEvent>());
|
||||||
@ -249,5 +260,38 @@ TEST_F(RtcEventLogImplTest, DoNotDropEventsIfHistoryFullAfterStarted) {
|
|||||||
Mock::VerifyAndClearExpectations(encoder_ptr_);
|
Mock::VerifyAndClearExpectations(encoder_ptr_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(RtcEventLogImplTest, StopOutputOnWriteFailure) {
|
||||||
|
constexpr size_t kNumberOfEvents = 10;
|
||||||
|
constexpr size_t kFailsWriteOnEventsCount = 5;
|
||||||
|
|
||||||
|
size_t number_of_encoded_events = 0;
|
||||||
|
EXPECT_CALL(*encoder_ptr_, OnEncode(_))
|
||||||
|
.WillRepeatedly(Invoke([this, &number_of_encoded_events]() {
|
||||||
|
++number_of_encoded_events;
|
||||||
|
if (number_of_encoded_events == kFailsWriteOnEventsCount) {
|
||||||
|
output_ptr_->FailsNextWrite();
|
||||||
|
}
|
||||||
|
return std::string();
|
||||||
|
}));
|
||||||
|
|
||||||
|
event_log_.StartLogging(std::move(output_), kOutputPeriod.ms());
|
||||||
|
|
||||||
|
// Fails `RtcEventLogOutput` on the last event.
|
||||||
|
for (size_t i = 0; i < kFailsWriteOnEventsCount; i++) {
|
||||||
|
event_log_.Log(std::make_unique<FakeEvent>());
|
||||||
|
}
|
||||||
|
time_controller_.AdvanceTime(kOutputPeriod);
|
||||||
|
// Expect that the remainder events are not encoded.
|
||||||
|
for (size_t i = kFailsWriteOnEventsCount; i < kNumberOfEvents; i++) {
|
||||||
|
event_log_.Log(std::make_unique<FakeEvent>());
|
||||||
|
}
|
||||||
|
time_controller_.AdvanceTime(kOutputPeriod);
|
||||||
|
event_log_.StopLogging();
|
||||||
|
|
||||||
|
EXPECT_EQ(number_of_encoded_events, kFailsWriteOnEventsCount);
|
||||||
|
|
||||||
|
Mock::VerifyAndClearExpectations(encoder_ptr_);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user