mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 11 | #include "video/call_stats.h" |
| 12 | |
kwiberg | 27f982b | 2016-03-01 19:52:33 | [diff] [blame] | 13 | #include <memory> |
| 14 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 15 | #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 16 | #include "modules/utility/include/process_thread.h" |
| 17 | #include "rtc_base/event.h" |
| 18 | #include "rtc_base/location.h" |
Danil Chapovalov | 1aa7581 | 2019-03-05 10:11:35 | [diff] [blame] | 19 | #include "rtc_base/task_utils/to_queued_task.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 20 | #include "system_wrappers/include/metrics.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 21 | #include "test/gmock.h" |
| 22 | #include "test/gtest.h" |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 | [diff] [blame] | 23 | |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 | [diff] [blame] | 24 | using ::testing::AnyNumber; |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 25 | using ::testing::InvokeWithoutArgs; |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 | [diff] [blame] | 26 | using ::testing::Return; |
| 27 | |
| 28 | namespace webrtc { |
| 29 | |
fischman@webrtc.org | aea96d3 | 2013-02-19 22:09:36 | [diff] [blame] | 30 | class MockStatsObserver : public CallStatsObserver { |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 | [diff] [blame] | 31 | public: |
| 32 | MockStatsObserver() {} |
| 33 | virtual ~MockStatsObserver() {} |
| 34 | |
stefan | 2328a94 | 2015-08-07 11:27:51 | [diff] [blame] | 35 | MOCK_METHOD2(OnRttUpdate, void(int64_t, int64_t)); |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | class CallStatsTest : public ::testing::Test { |
Peter Boström | d3c9447 | 2015-12-09 10:20:58 | [diff] [blame] | 39 | public: |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 40 | CallStatsTest() { |
| 41 | process_thread_->RegisterModule(&call_stats_, RTC_FROM_HERE); |
| 42 | process_thread_->Start(); |
| 43 | } |
| 44 | ~CallStatsTest() override { |
| 45 | process_thread_->Stop(); |
| 46 | process_thread_->DeRegisterModule(&call_stats_); |
| 47 | } |
Peter Boström | d3c9447 | 2015-12-09 10:20:58 | [diff] [blame] | 48 | |
Tommi | c89468a | 2019-08-05 13:13:20 | [diff] [blame] | 49 | // Queues an rtt update call on the process thread. |
| 50 | void AsyncSimulateRttUpdate(int64_t rtt) { |
| 51 | RtcpRttStats* rtcp_rtt_stats = &call_stats_; |
| 52 | process_thread_->PostTask(ToQueuedTask( |
| 53 | [rtcp_rtt_stats, rtt] { rtcp_rtt_stats->OnRttUpdate(rtt); })); |
| 54 | } |
| 55 | |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 | [diff] [blame] | 56 | protected: |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 57 | std::unique_ptr<ProcessThread> process_thread_{ |
| 58 | ProcessThread::Create("CallStats")}; |
| 59 | SimulatedClock fake_clock_{12345}; |
| 60 | CallStats call_stats_{&fake_clock_, process_thread_.get()}; |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | TEST_F(CallStatsTest, AddAndTriggerCallback) { |
Niels Möller | c572ff3 | 2018-11-07 07:43:50 | [diff] [blame] | 64 | rtc::Event event; |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 65 | |
| 66 | static constexpr const int64_t kRtt = 25; |
| 67 | |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 | [diff] [blame] | 68 | MockStatsObserver stats_observer; |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 69 | EXPECT_CALL(stats_observer, OnRttUpdate(kRtt, kRtt)) |
| 70 | .Times(1) |
| 71 | .WillOnce(InvokeWithoutArgs([&event] { event.Set(); })); |
| 72 | |
| 73 | RtcpRttStats* rtcp_rtt_stats = &call_stats_; |
| 74 | call_stats_.RegisterStatsObserver(&stats_observer); |
sprang | e2d83d6 | 2016-02-19 17:03:26 | [diff] [blame] | 75 | EXPECT_EQ(-1, rtcp_rtt_stats->LastProcessedRtt()); |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 | [diff] [blame] | 76 | |
Tommi | c89468a | 2019-08-05 13:13:20 | [diff] [blame] | 77 | AsyncSimulateRttUpdate(kRtt); |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 78 | |
| 79 | EXPECT_TRUE(event.Wait(1000)); |
Tommi | c89468a | 2019-08-05 13:13:20 | [diff] [blame] | 80 | |
asapersson@webrtc.org | 1ae1d0c | 2013-11-20 12:46:11 | [diff] [blame] | 81 | EXPECT_EQ(kRtt, rtcp_rtt_stats->LastProcessedRtt()); |
| 82 | |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 83 | call_stats_.DeregisterStatsObserver(&stats_observer); |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | TEST_F(CallStatsTest, ProcessTime) { |
Niels Möller | c572ff3 | 2018-11-07 07:43:50 | [diff] [blame] | 87 | rtc::Event event; |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 88 | |
| 89 | static constexpr const int64_t kRtt = 100; |
| 90 | static constexpr const int64_t kRtt2 = 80; |
| 91 | |
| 92 | RtcpRttStats* rtcp_rtt_stats = &call_stats_; |
| 93 | |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 | [diff] [blame] | 94 | MockStatsObserver stats_observer; |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 | [diff] [blame] | 95 | |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 96 | EXPECT_CALL(stats_observer, OnRttUpdate(kRtt, kRtt)) |
| 97 | .Times(2) |
| 98 | .WillOnce(InvokeWithoutArgs([this] { |
| 99 | // Advance clock and verify we get an update. |
| 100 | fake_clock_.AdvanceTimeMilliseconds(CallStats::kUpdateIntervalMs); |
| 101 | })) |
| 102 | .WillRepeatedly(InvokeWithoutArgs([this, rtcp_rtt_stats] { |
| 103 | rtcp_rtt_stats->OnRttUpdate(kRtt2); |
| 104 | // Advance clock just too little to get an update. |
| 105 | fake_clock_.AdvanceTimeMilliseconds(CallStats::kUpdateIntervalMs - 1); |
| 106 | })); |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 | [diff] [blame] | 107 | |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 108 | // In case you're reading this and wondering how this number is arrived at, |
| 109 | // please see comments in the ChangeRtt test that go into some detail. |
| 110 | static constexpr const int64_t kLastAvg = 94; |
| 111 | EXPECT_CALL(stats_observer, OnRttUpdate(kLastAvg, kRtt2)) |
| 112 | .Times(1) |
| 113 | .WillOnce(InvokeWithoutArgs([&event] { event.Set(); })); |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 | [diff] [blame] | 114 | |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 115 | call_stats_.RegisterStatsObserver(&stats_observer); |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 | [diff] [blame] | 116 | |
Tommi | c89468a | 2019-08-05 13:13:20 | [diff] [blame] | 117 | AsyncSimulateRttUpdate(kRtt); |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 118 | EXPECT_TRUE(event.Wait(1000)); |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 | [diff] [blame] | 119 | |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 120 | call_stats_.DeregisterStatsObserver(&stats_observer); |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | // Verify all observers get correct estimates and observers can be added and |
| 124 | // removed. |
| 125 | TEST_F(CallStatsTest, MultipleObservers) { |
| 126 | MockStatsObserver stats_observer_1; |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 127 | call_stats_.RegisterStatsObserver(&stats_observer_1); |
asapersson@webrtc.org | 8084f95 | 2014-12-10 11:04:13 | [diff] [blame] | 128 | // Add the second observer twice, there should still be only one report to the |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 | [diff] [blame] | 129 | // observer. |
| 130 | MockStatsObserver stats_observer_2; |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 131 | call_stats_.RegisterStatsObserver(&stats_observer_2); |
| 132 | call_stats_.RegisterStatsObserver(&stats_observer_2); |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 | [diff] [blame] | 133 | |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 134 | static constexpr const int64_t kRtt = 100; |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 | [diff] [blame] | 135 | |
| 136 | // Verify both observers are updated. |
Niels Möller | c572ff3 | 2018-11-07 07:43:50 | [diff] [blame] | 137 | rtc::Event ev1; |
| 138 | rtc::Event ev2; |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 139 | EXPECT_CALL(stats_observer_1, OnRttUpdate(kRtt, kRtt)) |
| 140 | .Times(AnyNumber()) |
| 141 | .WillOnce(InvokeWithoutArgs([&ev1] { ev1.Set(); })) |
| 142 | .WillRepeatedly(Return()); |
| 143 | EXPECT_CALL(stats_observer_2, OnRttUpdate(kRtt, kRtt)) |
| 144 | .Times(AnyNumber()) |
| 145 | .WillOnce(InvokeWithoutArgs([&ev2] { ev2.Set(); })) |
| 146 | .WillRepeatedly(Return()); |
Tommi | c89468a | 2019-08-05 13:13:20 | [diff] [blame] | 147 | AsyncSimulateRttUpdate(kRtt); |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 148 | ASSERT_TRUE(ev1.Wait(100)); |
| 149 | ASSERT_TRUE(ev2.Wait(100)); |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 | [diff] [blame] | 150 | |
| 151 | // Deregister the second observer and verify update is only sent to the first |
| 152 | // observer. |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 153 | call_stats_.DeregisterStatsObserver(&stats_observer_2); |
| 154 | |
| 155 | EXPECT_CALL(stats_observer_1, OnRttUpdate(kRtt, kRtt)) |
| 156 | .Times(AnyNumber()) |
| 157 | .WillOnce(InvokeWithoutArgs([&ev1] { ev1.Set(); })) |
| 158 | .WillRepeatedly(Return()); |
stefan | 2328a94 | 2015-08-07 11:27:51 | [diff] [blame] | 159 | EXPECT_CALL(stats_observer_2, OnRttUpdate(kRtt, kRtt)).Times(0); |
Tommi | c89468a | 2019-08-05 13:13:20 | [diff] [blame] | 160 | AsyncSimulateRttUpdate(kRtt); |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 161 | ASSERT_TRUE(ev1.Wait(100)); |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 | [diff] [blame] | 162 | |
| 163 | // Deregister the first observer. |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 164 | call_stats_.DeregisterStatsObserver(&stats_observer_1); |
| 165 | |
| 166 | // Now make sure we don't get any callbacks. |
stefan | 2328a94 | 2015-08-07 11:27:51 | [diff] [blame] | 167 | EXPECT_CALL(stats_observer_1, OnRttUpdate(kRtt, kRtt)).Times(0); |
| 168 | EXPECT_CALL(stats_observer_2, OnRttUpdate(kRtt, kRtt)).Times(0); |
Tommi | c89468a | 2019-08-05 13:13:20 | [diff] [blame] | 169 | AsyncSimulateRttUpdate(kRtt); |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 170 | |
| 171 | // Force a call to Process(). |
| 172 | process_thread_->WakeUp(&call_stats_); |
| 173 | |
| 174 | // Flush the queue on the process thread to make sure we return after |
| 175 | // Process() has been called. |
Niels Möller | c572ff3 | 2018-11-07 07:43:50 | [diff] [blame] | 176 | rtc::Event event; |
Danil Chapovalov | 1aa7581 | 2019-03-05 10:11:35 | [diff] [blame] | 177 | process_thread_->PostTask(ToQueuedTask([&event] { event.Set(); })); |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 178 | event.Wait(rtc::Event::kForever); |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | // Verify increasing and decreasing rtt triggers callbacks with correct values. |
| 182 | TEST_F(CallStatsTest, ChangeRtt) { |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 183 | // TODO(tommi): This test assumes things about how old reports are removed |
| 184 | // inside of call_stats.cc. The threshold ms value is 1500ms, but it's not |
| 185 | // clear here that how the clock is advanced, affects that algorithm and |
| 186 | // subsequently the average reported rtt. |
| 187 | |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 | [diff] [blame] | 188 | MockStatsObserver stats_observer; |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 189 | call_stats_.RegisterStatsObserver(&stats_observer); |
| 190 | RtcpRttStats* rtcp_rtt_stats = &call_stats_; |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 | [diff] [blame] | 191 | |
Niels Möller | c572ff3 | 2018-11-07 07:43:50 | [diff] [blame] | 192 | rtc::Event event; |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 | [diff] [blame] | 193 | |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 194 | static constexpr const int64_t kFirstRtt = 100; |
| 195 | static constexpr const int64_t kLowRtt = kFirstRtt - 20; |
| 196 | static constexpr const int64_t kHighRtt = kFirstRtt + 20; |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 | [diff] [blame] | 197 | |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 198 | EXPECT_CALL(stats_observer, OnRttUpdate(kFirstRtt, kFirstRtt)) |
| 199 | .Times(1) |
| 200 | .WillOnce(InvokeWithoutArgs([&rtcp_rtt_stats, this] { |
| 201 | fake_clock_.AdvanceTimeMilliseconds(1000); |
| 202 | rtcp_rtt_stats->OnRttUpdate(kHighRtt); // Reported at T1 (1000ms). |
| 203 | })); |
| 204 | |
| 205 | // TODO(tommi): This relies on the internal algorithms of call_stats.cc. |
| 206 | // There's a weight factor there (0.3), that weighs the previous average to |
| 207 | // the new one by 70%, so the number 103 in this case is arrived at like so: |
| 208 | // (100) / 1 * 0.7 + (100+120)/2 * 0.3 = 103 |
| 209 | static constexpr const int64_t kAvgRtt1 = 103; |
| 210 | EXPECT_CALL(stats_observer, OnRttUpdate(kAvgRtt1, kHighRtt)) |
| 211 | .Times(1) |
| 212 | .WillOnce(InvokeWithoutArgs([&rtcp_rtt_stats, this] { |
| 213 | // This interacts with an internal implementation detail in call_stats |
| 214 | // that decays the oldest rtt value. See more below. |
| 215 | fake_clock_.AdvanceTimeMilliseconds(1000); |
| 216 | rtcp_rtt_stats->OnRttUpdate(kLowRtt); // Reported at T2 (2000ms). |
| 217 | })); |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 | [diff] [blame] | 218 | |
| 219 | // Increase time enough for a new update, but not too much to make the |
| 220 | // rtt invalid. Report a lower rtt and verify the old/high value still is sent |
| 221 | // in the callback. |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 | [diff] [blame] | 222 | |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 223 | // Here, enough time must have passed in order to remove exactly the first |
| 224 | // report and nothing else (>1500ms has passed since the first rtt). |
| 225 | // So, this value is arrived by doing: |
| 226 | // (kAvgRtt1)/1 * 0.7 + (kHighRtt+kLowRtt)/2 * 0.3 = 102.1 |
| 227 | static constexpr const int64_t kAvgRtt2 = 102; |
| 228 | EXPECT_CALL(stats_observer, OnRttUpdate(kAvgRtt2, kHighRtt)) |
| 229 | .Times(1) |
| 230 | .WillOnce(InvokeWithoutArgs([this] { |
| 231 | // Advance time to make the high report invalid, the lower rtt should |
| 232 | // now be in the callback. |
| 233 | fake_clock_.AdvanceTimeMilliseconds(1000); |
| 234 | })); |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 | [diff] [blame] | 235 | |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 236 | static constexpr const int64_t kAvgRtt3 = 95; |
| 237 | EXPECT_CALL(stats_observer, OnRttUpdate(kAvgRtt3, kLowRtt)) |
| 238 | .Times(1) |
| 239 | .WillOnce(InvokeWithoutArgs([&event] { event.Set(); })); |
| 240 | |
| 241 | // Trigger the first rtt value and set off the chain of callbacks. |
Tommi | c89468a | 2019-08-05 13:13:20 | [diff] [blame] | 242 | AsyncSimulateRttUpdate(kFirstRtt); // Reported at T0 (0ms). |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 243 | EXPECT_TRUE(event.Wait(1000)); |
| 244 | |
| 245 | call_stats_.DeregisterStatsObserver(&stats_observer); |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 | [diff] [blame] | 246 | } |
| 247 | |
asapersson@webrtc.org | 8084f95 | 2014-12-10 11:04:13 | [diff] [blame] | 248 | TEST_F(CallStatsTest, LastProcessedRtt) { |
Niels Möller | c572ff3 | 2018-11-07 07:43:50 | [diff] [blame] | 249 | rtc::Event event; |
asapersson@webrtc.org | 8084f95 | 2014-12-10 11:04:13 | [diff] [blame] | 250 | MockStatsObserver stats_observer; |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 251 | call_stats_.RegisterStatsObserver(&stats_observer); |
| 252 | RtcpRttStats* rtcp_rtt_stats = &call_stats_; |
| 253 | |
| 254 | static constexpr const int64_t kRttLow = 10; |
| 255 | static constexpr const int64_t kRttHigh = 30; |
| 256 | // The following two average numbers dependend on average + weight |
| 257 | // calculations in call_stats.cc. |
| 258 | static constexpr const int64_t kAvgRtt1 = 13; |
| 259 | static constexpr const int64_t kAvgRtt2 = 15; |
| 260 | |
| 261 | EXPECT_CALL(stats_observer, OnRttUpdate(kRttLow, kRttLow)) |
| 262 | .Times(1) |
| 263 | .WillOnce(InvokeWithoutArgs([rtcp_rtt_stats] { |
| 264 | EXPECT_EQ(kRttLow, rtcp_rtt_stats->LastProcessedRtt()); |
| 265 | // Don't advance the clock to make sure that low and high rtt values |
| 266 | // are associated with the same time stamp. |
| 267 | rtcp_rtt_stats->OnRttUpdate(kRttHigh); |
| 268 | })); |
| 269 | |
| 270 | EXPECT_CALL(stats_observer, OnRttUpdate(kAvgRtt1, kRttHigh)) |
| 271 | .Times(1) |
| 272 | .WillOnce(InvokeWithoutArgs([rtcp_rtt_stats, this] { |
| 273 | EXPECT_EQ(kAvgRtt1, rtcp_rtt_stats->LastProcessedRtt()); |
| 274 | fake_clock_.AdvanceTimeMilliseconds(CallStats::kUpdateIntervalMs); |
| 275 | rtcp_rtt_stats->OnRttUpdate(kRttLow); |
| 276 | rtcp_rtt_stats->OnRttUpdate(kRttHigh); |
| 277 | })); |
| 278 | |
| 279 | EXPECT_CALL(stats_observer, OnRttUpdate(kAvgRtt2, kRttHigh)) |
| 280 | .Times(1) |
| 281 | .WillOnce(InvokeWithoutArgs([rtcp_rtt_stats, &event] { |
| 282 | EXPECT_EQ(kAvgRtt2, rtcp_rtt_stats->LastProcessedRtt()); |
| 283 | event.Set(); |
| 284 | })); |
asapersson@webrtc.org | 8084f95 | 2014-12-10 11:04:13 | [diff] [blame] | 285 | |
| 286 | // Set a first values and verify that LastProcessedRtt initially returns the |
| 287 | // average rtt. |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 288 | fake_clock_.AdvanceTimeMilliseconds(CallStats::kUpdateIntervalMs); |
Tommi | c89468a | 2019-08-05 13:13:20 | [diff] [blame] | 289 | AsyncSimulateRttUpdate(kRttLow); |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 290 | EXPECT_TRUE(event.Wait(1000)); |
| 291 | EXPECT_EQ(kAvgRtt2, rtcp_rtt_stats->LastProcessedRtt()); |
asapersson@webrtc.org | 8084f95 | 2014-12-10 11:04:13 | [diff] [blame] | 292 | |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 293 | call_stats_.DeregisterStatsObserver(&stats_observer); |
asapersson@webrtc.org | 8084f95 | 2014-12-10 11:04:13 | [diff] [blame] | 294 | } |
| 295 | |
sprang | e2d83d6 | 2016-02-19 17:03:26 | [diff] [blame] | 296 | TEST_F(CallStatsTest, ProducesHistogramMetrics) { |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 297 | metrics::Reset(); |
Niels Möller | c572ff3 | 2018-11-07 07:43:50 | [diff] [blame] | 298 | rtc::Event event; |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 299 | static constexpr const int64_t kRtt = 123; |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 300 | MockStatsObserver stats_observer; |
| 301 | call_stats_.RegisterStatsObserver(&stats_observer); |
| 302 | EXPECT_CALL(stats_observer, OnRttUpdate(kRtt, kRtt)) |
| 303 | .Times(AnyNumber()) |
Tommi | c89468a | 2019-08-05 13:13:20 | [diff] [blame] | 304 | .WillRepeatedly(InvokeWithoutArgs([&event] { event.Set(); })); |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 305 | |
Tommi | c89468a | 2019-08-05 13:13:20 | [diff] [blame] | 306 | AsyncSimulateRttUpdate(kRtt); |
| 307 | EXPECT_TRUE(event.Wait(1000)); |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 308 | fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * |
| 309 | CallStats::kUpdateIntervalMs); |
Tommi | c89468a | 2019-08-05 13:13:20 | [diff] [blame] | 310 | AsyncSimulateRttUpdate(kRtt); |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 311 | EXPECT_TRUE(event.Wait(1000)); |
| 312 | |
| 313 | call_stats_.DeregisterStatsObserver(&stats_observer); |
| 314 | |
| 315 | process_thread_->Stop(); |
| 316 | call_stats_.UpdateHistogramsForTest(); |
sprang | e2d83d6 | 2016-02-19 17:03:26 | [diff] [blame] | 317 | |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 318 | EXPECT_EQ(1, metrics::NumSamples( |
sprang | e2d83d6 | 2016-02-19 17:03:26 | [diff] [blame] | 319 | "WebRTC.Video.AverageRoundTripTimeInMilliseconds")); |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 320 | EXPECT_EQ(1, metrics::NumEvents( |
| 321 | "WebRTC.Video.AverageRoundTripTimeInMilliseconds", kRtt)); |
sprang | e2d83d6 | 2016-02-19 17:03:26 | [diff] [blame] | 322 | } |
| 323 | |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 | [diff] [blame] | 324 | } // namespace webrtc |