/* * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree.
*/
// Note: Since rtc::Thread doesn't support injecting a Clock, we're going // to be using a mix of the fake clock (used by CallStats) as well as the // system clock (used by rtc::Thread). This isn't ideal and will result in // the tests taking longer to execute in some cases than they need to.
SimulatedClock fake_clock_{12345};
CallStats call_stats_{&fake_clock_, loop_.task_queue()};
};
EXPECT_CALL(stats_observer, OnRttUpdate(kRtt, kRtt))
.Times(2)
.WillOnce(InvokeWithoutArgs([this] { // Advance clock and verify we get an update.
fake_clock_.AdvanceTimeMilliseconds(CallStats::kUpdateInterval.ms());
}))
.WillRepeatedly(InvokeWithoutArgs([this] {
AsyncSimulateRttUpdate(kRtt2); // Advance clock just too little to get an update.
fake_clock_.AdvanceTimeMilliseconds(CallStats::kUpdateInterval.ms() -
1);
}));
// In case you're reading this and wondering how this number is arrived at, // please see comments in the ChangeRtt test that go into some detail. static constexpr const int64_t kLastAvg = 94;
EXPECT_CALL(stats_observer, OnRttUpdate(kLastAvg, kRtt2))
.Times(1)
.WillOnce(InvokeWithoutArgs([this] { loop_.Quit(); }));
// Verify all observers get correct estimates and observers can be added and // removed.
TEST_F(CallStats2Test, MultipleObservers) {
MockStatsObserver stats_observer_1;
call_stats_.RegisterStatsObserver(&stats_observer_1); // Add the second observer twice, there should still be only one report to the // observer.
MockStatsObserver stats_observer_2;
call_stats_.RegisterStatsObserver(&stats_observer_2);
call_stats_.RegisterStatsObserver(&stats_observer_2);
// Deregister the first observer.
call_stats_.DeregisterStatsObserver(&stats_observer_1);
// Now make sure we don't get any callbacks.
EXPECT_CALL(stats_observer_1, OnRttUpdate(kRtt, kRtt)).Times(0);
EXPECT_CALL(stats_observer_2, OnRttUpdate(kRtt, kRtt)).Times(0);
AsyncSimulateRttUpdate(kRtt);
// Flush the queue on the process thread to make sure we return after // Process() has been called.
FlushProcessAndWorker();
}
// Verify increasing and decreasing rtt triggers callbacks with correct values.
TEST_F(CallStats2Test, ChangeRtt) { // NOTE: This test assumes things about how old reports are removed // inside of call_stats.cc. The threshold ms value is 1500ms, but it's not // clear here that how the clock is advanced, affects that algorithm and // subsequently the average reported rtt.
// NOTE: This relies on the internal algorithms of call_stats.cc. // There's a weight factor there (0.3), that weighs the previous average to // the new one by 70%, so the number 103 in this case is arrived at like so: // (100) / 1 * 0.7 + (100+120)/2 * 0.3 = 103 static constexpr const int64_t kAvgRtt1 = 103;
EXPECT_CALL(stats_observer, OnRttUpdate(kAvgRtt1, kHighRtt))
.Times(1)
.WillOnce(InvokeWithoutArgs([this] { // This interacts with an internal implementation detail in call_stats // that decays the oldest rtt value. See more below.
fake_clock_.AdvanceTimeMilliseconds(1000);
AsyncSimulateRttUpdate(kLowRtt); // Reported at T2 (2000ms).
}));
// Increase time enough for a new update, but not too much to make the // rtt invalid. Report a lower rtt and verify the old/high value still is sent // in the callback.
// Here, enough time must have passed in order to remove exactly the first // report and nothing else (>1500ms has passed since the first rtt). // So, this value is arrived by doing: // (kAvgRtt1)/1 * 0.7 + (kHighRtt+kLowRtt)/2 * 0.3 = 102.1 static constexpr const int64_t kAvgRtt2 = 102;
EXPECT_CALL(stats_observer, OnRttUpdate(kAvgRtt2, kHighRtt))
.Times(1)
.WillOnce(InvokeWithoutArgs([this] { // Advance time to make the high report invalid, the lower rtt should // now be in the callback.
fake_clock_.AdvanceTimeMilliseconds(1000);
}));
static constexpr const int64_t kRttLow = 10; static constexpr const int64_t kRttHigh = 30; // The following two average numbers dependend on average + weight // calculations in call_stats.cc. static constexpr const int64_t kAvgRtt1 = 13; static constexpr const int64_t kAvgRtt2 = 15;
EXPECT_CALL(stats_observer, OnRttUpdate(kRttLow, kRttLow))
.Times(1)
.WillOnce(InvokeWithoutArgs([this] {
EXPECT_EQ(kRttLow, call_stats_.LastProcessedRtt()); // Don't advance the clock to make sure that low and high rtt values // are associated with the same time stamp.
AsyncSimulateRttUpdate(kRttHigh);
}));
// Set a first values and verify that LastProcessedRtt initially returns the // average rtt.
fake_clock_.AdvanceTimeMilliseconds(CallStats::kUpdateInterval.ms());
AsyncSimulateRttUpdate(kRttLow);
loop_.Run();
EXPECT_EQ(kAvgRtt2, call_stats_.LastProcessedRtt());
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.