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