Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 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 | #include <memory> |
| 11 | |
Danil Chapovalov | bda5068 | 2018-02-14 09:08:28 +0000 | [diff] [blame] | 12 | #include "modules/congestion_controller/probe_controller.h" |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 13 | #include "modules/pacing/mock/mock_paced_sender.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #include "rtc_base/logging.h" |
| 15 | #include "system_wrappers/include/clock.h" |
| 16 | #include "test/gmock.h" |
| 17 | #include "test/gtest.h" |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 18 | |
| 19 | using testing::_; |
| 20 | using testing::AtLeast; |
| 21 | using testing::NiceMock; |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 22 | using testing::Return; |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
| 25 | namespace test { |
| 26 | |
| 27 | namespace { |
| 28 | |
| 29 | constexpr int kMinBitrateBps = 100; |
| 30 | constexpr int kStartBitrateBps = 300; |
sergeyu | 07c147d | 2016-11-03 11:59:50 -0700 | [diff] [blame] | 31 | constexpr int kMaxBitrateBps = 10000; |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 32 | |
Irfan Sheriff | 9b7b753 | 2016-09-16 11:30:44 -0700 | [diff] [blame] | 33 | constexpr int kExponentialProbingTimeoutMs = 5000; |
| 34 | |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 35 | constexpr int kAlrProbeInterval = 5000; |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 36 | constexpr int kAlrEndedTimeoutMs = 3000; |
| 37 | constexpr int kBitrateDropTimeoutMs = 5000; |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 38 | |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 39 | } // namespace |
| 40 | |
| 41 | class ProbeControllerTest : public ::testing::Test { |
| 42 | protected: |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 43 | ProbeControllerTest() : clock_(100000000L) { |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 44 | probe_controller_.reset(new ProbeController(&pacer_, &clock_)); |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 45 | } |
| 46 | ~ProbeControllerTest() override {} |
| 47 | |
| 48 | SimulatedClock clock_; |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 49 | NiceMock<MockPacedSender> pacer_; |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 50 | std::unique_ptr<ProbeController> probe_controller_; |
| 51 | }; |
| 52 | |
| 53 | TEST_F(ProbeControllerTest, InitiatesProbingAtStart) { |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 54 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(AtLeast(2)); |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 55 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 56 | kMaxBitrateBps); |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Sergey Ulanov | e2b1501 | 2016-11-22 16:08:30 -0800 | [diff] [blame] | 59 | TEST_F(ProbeControllerTest, ProbeOnlyWhenNetworkIsUp) { |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 60 | probe_controller_->OnNetworkStateChanged(kNetworkDown); |
| 61 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); |
Sergey Ulanov | e2b1501 | 2016-11-22 16:08:30 -0800 | [diff] [blame] | 62 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 63 | kMaxBitrateBps); |
Sergey Ulanov | e2b1501 | 2016-11-22 16:08:30 -0800 | [diff] [blame] | 64 | |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 65 | testing::Mock::VerifyAndClearExpectations(&pacer_); |
| 66 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(AtLeast(2)); |
| 67 | probe_controller_->OnNetworkStateChanged(kNetworkUp); |
Sergey Ulanov | e2b1501 | 2016-11-22 16:08:30 -0800 | [diff] [blame] | 68 | } |
| 69 | |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 70 | TEST_F(ProbeControllerTest, InitiatesProbingOnMaxBitrateIncrease) { |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 71 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(AtLeast(2)); |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 72 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 73 | kMaxBitrateBps); |
Irfan Sheriff | 9b7b753 | 2016-09-16 11:30:44 -0700 | [diff] [blame] | 74 | // Long enough to time out exponential probing. |
| 75 | clock_.AdvanceTimeMilliseconds(kExponentialProbingTimeoutMs); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 76 | probe_controller_->SetEstimatedBitrate(kStartBitrateBps); |
| 77 | probe_controller_->Process(); |
Irfan Sheriff | 9b7b753 | 2016-09-16 11:30:44 -0700 | [diff] [blame] | 78 | |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 79 | EXPECT_CALL(pacer_, CreateProbeCluster(kMaxBitrateBps + 100)); |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 80 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 81 | kMaxBitrateBps + 100); |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 82 | } |
| 83 | |
philipel | da5e9d0 | 2017-01-17 02:08:28 -0800 | [diff] [blame] | 84 | TEST_F(ProbeControllerTest, InitiatesProbingOnMaxBitrateIncreaseAtMaxBitrate) { |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 85 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(AtLeast(2)); |
philipel | da5e9d0 | 2017-01-17 02:08:28 -0800 | [diff] [blame] | 86 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 87 | kMaxBitrateBps); |
philipel | da5e9d0 | 2017-01-17 02:08:28 -0800 | [diff] [blame] | 88 | // Long enough to time out exponential probing. |
| 89 | clock_.AdvanceTimeMilliseconds(kExponentialProbingTimeoutMs); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 90 | probe_controller_->SetEstimatedBitrate(kStartBitrateBps); |
| 91 | probe_controller_->Process(); |
philipel | da5e9d0 | 2017-01-17 02:08:28 -0800 | [diff] [blame] | 92 | |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 93 | probe_controller_->SetEstimatedBitrate(kMaxBitrateBps); |
| 94 | EXPECT_CALL(pacer_, CreateProbeCluster(kMaxBitrateBps + 100)); |
philipel | da5e9d0 | 2017-01-17 02:08:28 -0800 | [diff] [blame] | 95 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 96 | kMaxBitrateBps + 100); |
philipel | da5e9d0 | 2017-01-17 02:08:28 -0800 | [diff] [blame] | 97 | } |
| 98 | |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 99 | TEST_F(ProbeControllerTest, TestExponentialProbing) { |
| 100 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 101 | kMaxBitrateBps); |
sergeyu | 07c147d | 2016-11-03 11:59:50 -0700 | [diff] [blame] | 102 | |
sergeyu | 5bc3945 | 2016-12-15 10:42:09 -0800 | [diff] [blame] | 103 | // Repeated probe should only be sent when estimated bitrate climbs above |
| 104 | // 0.7 * 6 * kStartBitrateBps = 1260. |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 105 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); |
| 106 | probe_controller_->SetEstimatedBitrate(1000); |
| 107 | testing::Mock::VerifyAndClearExpectations(&pacer_); |
sergeyu | 9cef11b | 2016-12-02 11:03:01 -0800 | [diff] [blame] | 108 | |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 109 | EXPECT_CALL(pacer_, CreateProbeCluster(2 * 1800)); |
| 110 | probe_controller_->SetEstimatedBitrate(1800); |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | TEST_F(ProbeControllerTest, TestExponentialProbingTimeout) { |
| 114 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 115 | kMaxBitrateBps); |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 116 | |
| 117 | // Advance far enough to cause a time out in waiting for probing result. |
Irfan Sheriff | 9b7b753 | 2016-09-16 11:30:44 -0700 | [diff] [blame] | 118 | clock_.AdvanceTimeMilliseconds(kExponentialProbingTimeoutMs); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 119 | probe_controller_->Process(); |
sergeyu | 9cef11b | 2016-12-02 11:03:01 -0800 | [diff] [blame] | 120 | |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 121 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); |
| 122 | probe_controller_->SetEstimatedBitrate(1800); |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 123 | } |
| 124 | |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 125 | TEST_F(ProbeControllerTest, RequestProbeInAlr) { |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 126 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 127 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 128 | kMaxBitrateBps); |
| 129 | probe_controller_->SetEstimatedBitrate(500); |
| 130 | testing::Mock::VerifyAndClearExpectations(&pacer_); |
| 131 | EXPECT_CALL(pacer_, CreateProbeCluster(0.85 * 500)).Times(1); |
| 132 | EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) |
| 133 | .WillRepeatedly(Return(clock_.TimeInMilliseconds())); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 134 | clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 135 | probe_controller_->Process(); |
| 136 | probe_controller_->SetEstimatedBitrate(250); |
| 137 | probe_controller_->RequestProbe(); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | TEST_F(ProbeControllerTest, RequestProbeWhenAlrEndedRecently) { |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 141 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 142 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 143 | kMaxBitrateBps); |
| 144 | probe_controller_->SetEstimatedBitrate(500); |
| 145 | testing::Mock::VerifyAndClearExpectations(&pacer_); |
| 146 | EXPECT_CALL(pacer_, CreateProbeCluster(0.85 * 500)).Times(1); |
| 147 | EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) |
| 148 | .WillRepeatedly(Return(rtc::nullopt)); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 149 | clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 150 | probe_controller_->Process(); |
| 151 | probe_controller_->SetEstimatedBitrate(250); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 152 | probe_controller_->SetAlrEndedTimeMs(clock_.TimeInMilliseconds()); |
| 153 | clock_.AdvanceTimeMilliseconds(kAlrEndedTimeoutMs - 1); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 154 | probe_controller_->RequestProbe(); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | TEST_F(ProbeControllerTest, RequestProbeWhenAlrNotEndedRecently) { |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 158 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 159 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 160 | kMaxBitrateBps); |
| 161 | probe_controller_->SetEstimatedBitrate(500); |
| 162 | testing::Mock::VerifyAndClearExpectations(&pacer_); |
| 163 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); |
| 164 | EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) |
| 165 | .WillRepeatedly(Return(rtc::nullopt)); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 166 | clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 167 | probe_controller_->Process(); |
| 168 | probe_controller_->SetEstimatedBitrate(250); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 169 | probe_controller_->SetAlrEndedTimeMs(clock_.TimeInMilliseconds()); |
| 170 | clock_.AdvanceTimeMilliseconds(kAlrEndedTimeoutMs + 1); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 171 | probe_controller_->RequestProbe(); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | TEST_F(ProbeControllerTest, RequestProbeWhenBweDropNotRecent) { |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 175 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 176 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 177 | kMaxBitrateBps); |
| 178 | probe_controller_->SetEstimatedBitrate(500); |
| 179 | testing::Mock::VerifyAndClearExpectations(&pacer_); |
| 180 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); |
| 181 | EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) |
| 182 | .WillRepeatedly(Return(clock_.TimeInMilliseconds())); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 183 | clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 184 | probe_controller_->Process(); |
| 185 | probe_controller_->SetEstimatedBitrate(250); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 186 | clock_.AdvanceTimeMilliseconds(kBitrateDropTimeoutMs + 1); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 187 | probe_controller_->RequestProbe(); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | TEST_F(ProbeControllerTest, PeriodicProbing) { |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 191 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 192 | probe_controller_->EnablePeriodicAlrProbing(true); |
| 193 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 194 | kMaxBitrateBps); |
| 195 | probe_controller_->SetEstimatedBitrate(500); |
| 196 | testing::Mock::VerifyAndClearExpectations(&pacer_); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 197 | |
| 198 | int64_t start_time = clock_.TimeInMilliseconds(); |
| 199 | |
| 200 | // Expect the controller to send a new probe after 5s has passed. |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 201 | EXPECT_CALL(pacer_, CreateProbeCluster(1000)).Times(1); |
| 202 | EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) |
| 203 | .WillRepeatedly(Return(start_time)); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 204 | clock_.AdvanceTimeMilliseconds(5000); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 205 | probe_controller_->Process(); |
| 206 | probe_controller_->SetEstimatedBitrate(500); |
| 207 | testing::Mock::VerifyAndClearExpectations(&pacer_); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 208 | |
| 209 | // The following probe should be sent at 10s into ALR. |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 210 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); |
| 211 | EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) |
| 212 | .WillRepeatedly(Return(start_time)); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 213 | clock_.AdvanceTimeMilliseconds(4000); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 214 | probe_controller_->Process(); |
| 215 | probe_controller_->SetEstimatedBitrate(500); |
| 216 | testing::Mock::VerifyAndClearExpectations(&pacer_); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 217 | |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 218 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(1); |
| 219 | EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) |
| 220 | .WillRepeatedly(Return(start_time)); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 221 | clock_.AdvanceTimeMilliseconds(1000); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 222 | probe_controller_->Process(); |
| 223 | probe_controller_->SetEstimatedBitrate(500); |
| 224 | testing::Mock::VerifyAndClearExpectations(&pacer_); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 225 | } |
| 226 | |
philipel | d1d247f | 2017-05-04 08:35:52 -0700 | [diff] [blame] | 227 | TEST_F(ProbeControllerTest, PeriodicProbingAfterReset) { |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 228 | testing::StrictMock<MockPacedSender> local_pacer; |
| 229 | probe_controller_.reset(new ProbeController(&local_pacer, &clock_)); |
philipel | d1d247f | 2017-05-04 08:35:52 -0700 | [diff] [blame] | 230 | int64_t alr_start_time = clock_.TimeInMilliseconds(); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 231 | EXPECT_CALL(local_pacer, GetApplicationLimitedRegionStartTime()) |
| 232 | .WillRepeatedly(Return(alr_start_time)); |
philipel | d1d247f | 2017-05-04 08:35:52 -0700 | [diff] [blame] | 233 | |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 234 | EXPECT_CALL(local_pacer, CreateProbeCluster(_)).Times(2); |
philipel | d1d247f | 2017-05-04 08:35:52 -0700 | [diff] [blame] | 235 | probe_controller_->EnablePeriodicAlrProbing(true); |
| 236 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 237 | kMaxBitrateBps); |
| 238 | probe_controller_->Reset(); |
philipel | d1d247f | 2017-05-04 08:35:52 -0700 | [diff] [blame] | 239 | |
| 240 | clock_.AdvanceTimeMilliseconds(10000); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 241 | probe_controller_->Process(); |
philipel | d1d247f | 2017-05-04 08:35:52 -0700 | [diff] [blame] | 242 | |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 243 | EXPECT_CALL(local_pacer, CreateProbeCluster(_)).Times(2); |
philipel | d1d247f | 2017-05-04 08:35:52 -0700 | [diff] [blame] | 244 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 245 | kMaxBitrateBps); |
philipel | d1d247f | 2017-05-04 08:35:52 -0700 | [diff] [blame] | 246 | |
| 247 | // Make sure we use |kStartBitrateBps| as the estimated bitrate |
| 248 | // until SetEstimatedBitrate is called with an updated estimate. |
| 249 | clock_.AdvanceTimeMilliseconds(10000); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 250 | EXPECT_CALL(local_pacer, CreateProbeCluster(kStartBitrateBps*2)); |
| 251 | probe_controller_->Process(); |
philipel | d1d247f | 2017-05-04 08:35:52 -0700 | [diff] [blame] | 252 | } |
| 253 | |
sergeyu | 5bc3945 | 2016-12-15 10:42:09 -0800 | [diff] [blame] | 254 | TEST_F(ProbeControllerTest, TestExponentialProbingOverflow) { |
| 255 | const int64_t kMbpsMultiplier = 1000000; |
| 256 | probe_controller_->SetBitrates(kMinBitrateBps, 10 * kMbpsMultiplier, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 257 | 100 * kMbpsMultiplier); |
sergeyu | 5bc3945 | 2016-12-15 10:42:09 -0800 | [diff] [blame] | 258 | |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 259 | // Verify that probe bitrate is capped at the specified max bitrate |
| 260 | EXPECT_CALL(pacer_, CreateProbeCluster(100 * kMbpsMultiplier)); |
| 261 | probe_controller_->SetEstimatedBitrate(60 * kMbpsMultiplier); |
| 262 | testing::Mock::VerifyAndClearExpectations(&pacer_); |
sergeyu | 5bc3945 | 2016-12-15 10:42:09 -0800 | [diff] [blame] | 263 | |
| 264 | // Verify that repeated probes aren't sent. |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame^] | 265 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); |
| 266 | probe_controller_->SetEstimatedBitrate(100 * kMbpsMultiplier); |
sergeyu | 5bc3945 | 2016-12-15 10:42:09 -0800 | [diff] [blame] | 267 | } |
| 268 | |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 269 | } // namespace test |
| 270 | } // namespace webrtc |