Fix race in KeepsMostRecentEvents.
The test may spawn threads that reference the global clock, so the code that resets the fake clock, needs to run when those threads have been stopped. Bug: webrtc:13947 Change-Id: I1f7dc921b7a8ff8e7e89e03e4397e635b67d77be Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/258361 Reviewed-by: Björn Terelius <terelius@webrtc.org> Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Cr-Commit-Position: refs/heads/main@{#36489}
This commit is contained in:
parent
137c2a8316
commit
093ce288fd
@ -904,31 +904,39 @@ TEST_P(RtcEventLogCircularBufferTest, KeepsMostRecentEvents) {
|
||||
std::make_unique<rtc::ScopedFakeClock>();
|
||||
fake_clock->SetTime(Timestamp::Seconds(kStartTimeSeconds));
|
||||
|
||||
auto task_queue_factory = CreateDefaultTaskQueueFactory();
|
||||
RtcEventLogFactory rtc_event_log_factory(task_queue_factory.get());
|
||||
// When `log` goes out of scope, the contents are flushed
|
||||
// to the output.
|
||||
std::unique_ptr<RtcEventLog> log =
|
||||
rtc_event_log_factory.CreateRtcEventLog(encoding_type_);
|
||||
// Create a scope for the TQ and event log factories.
|
||||
// This way, we make sure that task queue instances that may rely on a clock
|
||||
// have been torn down before we run the verification steps at the end of
|
||||
// the test.
|
||||
int64_t start_time_us, utc_start_time_us, stop_time_us;
|
||||
|
||||
for (size_t i = 0; i < kNumEvents; i++) {
|
||||
// The purpose of the test is to verify that the log can handle
|
||||
// more events than what fits in the internal circular buffer. The exact
|
||||
// type of events does not matter so we chose ProbeSuccess events for
|
||||
// simplicity.
|
||||
// We base the various values on the index. We use this for some basic
|
||||
// consistency checks when we read back.
|
||||
log->Log(std::make_unique<RtcEventProbeResultSuccess>(
|
||||
i, kStartBitrate + i * 1000));
|
||||
{
|
||||
auto task_queue_factory = CreateDefaultTaskQueueFactory();
|
||||
RtcEventLogFactory rtc_event_log_factory(task_queue_factory.get());
|
||||
// When `log` goes out of scope, the contents are flushed
|
||||
// to the output.
|
||||
std::unique_ptr<RtcEventLog> log =
|
||||
rtc_event_log_factory.CreateRtcEventLog(encoding_type_);
|
||||
|
||||
for (size_t i = 0; i < kNumEvents; i++) {
|
||||
// The purpose of the test is to verify that the log can handle
|
||||
// more events than what fits in the internal circular buffer. The exact
|
||||
// type of events does not matter so we chose ProbeSuccess events for
|
||||
// simplicity.
|
||||
// We base the various values on the index. We use this for some basic
|
||||
// consistency checks when we read back.
|
||||
log->Log(std::make_unique<RtcEventProbeResultSuccess>(
|
||||
i, kStartBitrate + i * 1000));
|
||||
fake_clock->AdvanceTime(TimeDelta::Millis(10));
|
||||
}
|
||||
start_time_us = rtc::TimeMicros();
|
||||
utc_start_time_us = rtc::TimeUTCMicros();
|
||||
log->StartLogging(log_output_factory_->Create(temp_filename),
|
||||
RtcEventLog::kImmediateOutput);
|
||||
fake_clock->AdvanceTime(TimeDelta::Millis(10));
|
||||
stop_time_us = rtc::TimeMicros();
|
||||
log->StopLogging();
|
||||
}
|
||||
int64_t start_time_us = rtc::TimeMicros();
|
||||
int64_t utc_start_time_us = rtc::TimeUTCMicros();
|
||||
log->StartLogging(log_output_factory_->Create(temp_filename),
|
||||
RtcEventLog::kImmediateOutput);
|
||||
fake_clock->AdvanceTime(TimeDelta::Millis(10));
|
||||
int64_t stop_time_us = rtc::TimeMicros();
|
||||
log->StopLogging();
|
||||
|
||||
// Read the generated log from memory.
|
||||
ParsedRtcEventLog parsed_log;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user