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 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 13:07:28 +0100 | [diff] [blame] | 41 | class LegacyProbeControllerTest : public ::testing::Test { |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 42 | protected: |
Sebastian Jansson | 56da2f7 | 2018-02-28 13:07:28 +0100 | [diff] [blame] | 43 | LegacyProbeControllerTest() : 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 | } |
Sebastian Jansson | 56da2f7 | 2018-02-28 13:07:28 +0100 | [diff] [blame] | 46 | ~LegacyProbeControllerTest() override {} |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 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 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 13:07:28 +0100 | [diff] [blame] | 53 | TEST_F(LegacyProbeControllerTest, 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 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 13:07:28 +0100 | [diff] [blame] | 59 | TEST_F(LegacyProbeControllerTest, 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 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 13:07:28 +0100 | [diff] [blame] | 70 | TEST_F(LegacyProbeControllerTest, 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 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 13:07:28 +0100 | [diff] [blame] | 84 | TEST_F(LegacyProbeControllerTest, |
| 85 | InitiatesProbingOnMaxBitrateIncreaseAtMaxBitrate) { |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 86 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(AtLeast(2)); |
philipel | da5e9d0 | 2017-01-17 02:08:28 -0800 | [diff] [blame] | 87 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 88 | kMaxBitrateBps); |
philipel | da5e9d0 | 2017-01-17 02:08:28 -0800 | [diff] [blame] | 89 | // Long enough to time out exponential probing. |
| 90 | clock_.AdvanceTimeMilliseconds(kExponentialProbingTimeoutMs); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 91 | probe_controller_->SetEstimatedBitrate(kStartBitrateBps); |
| 92 | probe_controller_->Process(); |
philipel | da5e9d0 | 2017-01-17 02:08:28 -0800 | [diff] [blame] | 93 | |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 94 | probe_controller_->SetEstimatedBitrate(kMaxBitrateBps); |
| 95 | EXPECT_CALL(pacer_, CreateProbeCluster(kMaxBitrateBps + 100)); |
philipel | da5e9d0 | 2017-01-17 02:08:28 -0800 | [diff] [blame] | 96 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 97 | kMaxBitrateBps + 100); |
philipel | da5e9d0 | 2017-01-17 02:08:28 -0800 | [diff] [blame] | 98 | } |
| 99 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 13:07:28 +0100 | [diff] [blame] | 100 | TEST_F(LegacyProbeControllerTest, TestExponentialProbing) { |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 101 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 102 | kMaxBitrateBps); |
sergeyu | 07c147d | 2016-11-03 11:59:50 -0700 | [diff] [blame] | 103 | |
sergeyu | 5bc3945 | 2016-12-15 10:42:09 -0800 | [diff] [blame] | 104 | // Repeated probe should only be sent when estimated bitrate climbs above |
| 105 | // 0.7 * 6 * kStartBitrateBps = 1260. |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 106 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); |
| 107 | probe_controller_->SetEstimatedBitrate(1000); |
| 108 | testing::Mock::VerifyAndClearExpectations(&pacer_); |
sergeyu | 9cef11b | 2016-12-02 11:03:01 -0800 | [diff] [blame] | 109 | |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 110 | EXPECT_CALL(pacer_, CreateProbeCluster(2 * 1800)); |
| 111 | probe_controller_->SetEstimatedBitrate(1800); |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 13:07:28 +0100 | [diff] [blame] | 114 | TEST_F(LegacyProbeControllerTest, TestExponentialProbingTimeout) { |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 115 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 116 | kMaxBitrateBps); |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 117 | |
| 118 | // 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] | 119 | clock_.AdvanceTimeMilliseconds(kExponentialProbingTimeoutMs); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 120 | probe_controller_->Process(); |
sergeyu | 9cef11b | 2016-12-02 11:03:01 -0800 | [diff] [blame] | 121 | |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 122 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); |
| 123 | probe_controller_->SetEstimatedBitrate(1800); |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 13:07:28 +0100 | [diff] [blame] | 126 | TEST_F(LegacyProbeControllerTest, RequestProbeInAlr) { |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 127 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 128 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 129 | kMaxBitrateBps); |
| 130 | probe_controller_->SetEstimatedBitrate(500); |
| 131 | testing::Mock::VerifyAndClearExpectations(&pacer_); |
| 132 | EXPECT_CALL(pacer_, CreateProbeCluster(0.85 * 500)).Times(1); |
| 133 | EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) |
| 134 | .WillRepeatedly(Return(clock_.TimeInMilliseconds())); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 135 | clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 136 | probe_controller_->Process(); |
| 137 | probe_controller_->SetEstimatedBitrate(250); |
| 138 | probe_controller_->RequestProbe(); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 13:07:28 +0100 | [diff] [blame] | 141 | TEST_F(LegacyProbeControllerTest, RequestProbeWhenAlrEndedRecently) { |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 142 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 143 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 144 | kMaxBitrateBps); |
| 145 | probe_controller_->SetEstimatedBitrate(500); |
| 146 | testing::Mock::VerifyAndClearExpectations(&pacer_); |
| 147 | EXPECT_CALL(pacer_, CreateProbeCluster(0.85 * 500)).Times(1); |
| 148 | EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) |
| 149 | .WillRepeatedly(Return(rtc::nullopt)); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 150 | clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 151 | probe_controller_->Process(); |
| 152 | probe_controller_->SetEstimatedBitrate(250); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 153 | probe_controller_->SetAlrEndedTimeMs(clock_.TimeInMilliseconds()); |
| 154 | clock_.AdvanceTimeMilliseconds(kAlrEndedTimeoutMs - 1); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 155 | probe_controller_->RequestProbe(); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 13:07:28 +0100 | [diff] [blame] | 158 | TEST_F(LegacyProbeControllerTest, RequestProbeWhenAlrNotEndedRecently) { |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 159 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 160 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 161 | kMaxBitrateBps); |
| 162 | probe_controller_->SetEstimatedBitrate(500); |
| 163 | testing::Mock::VerifyAndClearExpectations(&pacer_); |
| 164 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); |
| 165 | EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) |
| 166 | .WillRepeatedly(Return(rtc::nullopt)); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 167 | clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 168 | probe_controller_->Process(); |
| 169 | probe_controller_->SetEstimatedBitrate(250); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 170 | probe_controller_->SetAlrEndedTimeMs(clock_.TimeInMilliseconds()); |
| 171 | clock_.AdvanceTimeMilliseconds(kAlrEndedTimeoutMs + 1); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 172 | probe_controller_->RequestProbe(); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 13:07:28 +0100 | [diff] [blame] | 175 | TEST_F(LegacyProbeControllerTest, RequestProbeWhenBweDropNotRecent) { |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 176 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 177 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 178 | kMaxBitrateBps); |
| 179 | probe_controller_->SetEstimatedBitrate(500); |
| 180 | testing::Mock::VerifyAndClearExpectations(&pacer_); |
| 181 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); |
| 182 | EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) |
| 183 | .WillRepeatedly(Return(clock_.TimeInMilliseconds())); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 184 | clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 185 | probe_controller_->Process(); |
| 186 | probe_controller_->SetEstimatedBitrate(250); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 187 | clock_.AdvanceTimeMilliseconds(kBitrateDropTimeoutMs + 1); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 188 | probe_controller_->RequestProbe(); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 189 | } |
| 190 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 13:07:28 +0100 | [diff] [blame] | 191 | TEST_F(LegacyProbeControllerTest, PeriodicProbing) { |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 192 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 193 | probe_controller_->EnablePeriodicAlrProbing(true); |
| 194 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 195 | kMaxBitrateBps); |
| 196 | probe_controller_->SetEstimatedBitrate(500); |
| 197 | testing::Mock::VerifyAndClearExpectations(&pacer_); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 198 | |
| 199 | int64_t start_time = clock_.TimeInMilliseconds(); |
| 200 | |
| 201 | // Expect the controller to send a new probe after 5s has passed. |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 202 | EXPECT_CALL(pacer_, CreateProbeCluster(1000)).Times(1); |
| 203 | EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) |
| 204 | .WillRepeatedly(Return(start_time)); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 205 | clock_.AdvanceTimeMilliseconds(5000); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 206 | probe_controller_->Process(); |
| 207 | probe_controller_->SetEstimatedBitrate(500); |
| 208 | testing::Mock::VerifyAndClearExpectations(&pacer_); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 209 | |
| 210 | // The following probe should be sent at 10s into ALR. |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 211 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); |
| 212 | EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) |
| 213 | .WillRepeatedly(Return(start_time)); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 214 | clock_.AdvanceTimeMilliseconds(4000); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 215 | probe_controller_->Process(); |
| 216 | probe_controller_->SetEstimatedBitrate(500); |
| 217 | testing::Mock::VerifyAndClearExpectations(&pacer_); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 218 | |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 219 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(1); |
| 220 | EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) |
| 221 | .WillRepeatedly(Return(start_time)); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 222 | clock_.AdvanceTimeMilliseconds(1000); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 223 | probe_controller_->Process(); |
| 224 | probe_controller_->SetEstimatedBitrate(500); |
| 225 | testing::Mock::VerifyAndClearExpectations(&pacer_); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 226 | } |
| 227 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 13:07:28 +0100 | [diff] [blame] | 228 | TEST_F(LegacyProbeControllerTest, PeriodicProbingAfterReset) { |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 229 | testing::StrictMock<MockPacedSender> local_pacer; |
| 230 | probe_controller_.reset(new ProbeController(&local_pacer, &clock_)); |
philipel | d1d247f | 2017-05-04 08:35:52 -0700 | [diff] [blame] | 231 | int64_t alr_start_time = clock_.TimeInMilliseconds(); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 232 | EXPECT_CALL(local_pacer, GetApplicationLimitedRegionStartTime()) |
| 233 | .WillRepeatedly(Return(alr_start_time)); |
philipel | d1d247f | 2017-05-04 08:35:52 -0700 | [diff] [blame] | 234 | |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 235 | EXPECT_CALL(local_pacer, CreateProbeCluster(_)).Times(2); |
philipel | d1d247f | 2017-05-04 08:35:52 -0700 | [diff] [blame] | 236 | probe_controller_->EnablePeriodicAlrProbing(true); |
| 237 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 238 | kMaxBitrateBps); |
| 239 | probe_controller_->Reset(); |
philipel | d1d247f | 2017-05-04 08:35:52 -0700 | [diff] [blame] | 240 | |
| 241 | clock_.AdvanceTimeMilliseconds(10000); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 242 | probe_controller_->Process(); |
philipel | d1d247f | 2017-05-04 08:35:52 -0700 | [diff] [blame] | 243 | |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 244 | EXPECT_CALL(local_pacer, CreateProbeCluster(_)).Times(2); |
philipel | d1d247f | 2017-05-04 08:35:52 -0700 | [diff] [blame] | 245 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 246 | kMaxBitrateBps); |
philipel | d1d247f | 2017-05-04 08:35:52 -0700 | [diff] [blame] | 247 | |
| 248 | // Make sure we use |kStartBitrateBps| as the estimated bitrate |
| 249 | // until SetEstimatedBitrate is called with an updated estimate. |
| 250 | clock_.AdvanceTimeMilliseconds(10000); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 251 | EXPECT_CALL(local_pacer, CreateProbeCluster(kStartBitrateBps*2)); |
| 252 | probe_controller_->Process(); |
philipel | d1d247f | 2017-05-04 08:35:52 -0700 | [diff] [blame] | 253 | } |
| 254 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 13:07:28 +0100 | [diff] [blame] | 255 | TEST_F(LegacyProbeControllerTest, TestExponentialProbingOverflow) { |
sergeyu | 5bc3945 | 2016-12-15 10:42:09 -0800 | [diff] [blame] | 256 | const int64_t kMbpsMultiplier = 1000000; |
| 257 | probe_controller_->SetBitrates(kMinBitrateBps, 10 * kMbpsMultiplier, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 258 | 100 * kMbpsMultiplier); |
sergeyu | 5bc3945 | 2016-12-15 10:42:09 -0800 | [diff] [blame] | 259 | |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 260 | // Verify that probe bitrate is capped at the specified max bitrate |
| 261 | EXPECT_CALL(pacer_, CreateProbeCluster(100 * kMbpsMultiplier)); |
| 262 | probe_controller_->SetEstimatedBitrate(60 * kMbpsMultiplier); |
| 263 | testing::Mock::VerifyAndClearExpectations(&pacer_); |
sergeyu | 5bc3945 | 2016-12-15 10:42:09 -0800 | [diff] [blame] | 264 | |
| 265 | // Verify that repeated probes aren't sent. |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 266 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); |
| 267 | probe_controller_->SetEstimatedBitrate(100 * kMbpsMultiplier); |
sergeyu | 5bc3945 | 2016-12-15 10:42:09 -0800 | [diff] [blame] | 268 | } |
| 269 | |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 270 | } // namespace test |
| 271 | } // namespace webrtc |