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 | |
philipel | db4fa4b | 2018-03-06 18:29:22 +0100 | [diff] [blame] | 48 | const int64_t kMbpsMultiplier = 1000000; |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 49 | SimulatedClock clock_; |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 50 | NiceMock<MockPacedSender> pacer_; |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 51 | std::unique_ptr<ProbeController> probe_controller_; |
| 52 | }; |
| 53 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 13:07:28 +0100 | [diff] [blame] | 54 | TEST_F(LegacyProbeControllerTest, InitiatesProbingAtStart) { |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 55 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(AtLeast(2)); |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 56 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 57 | kMaxBitrateBps); |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 13:07:28 +0100 | [diff] [blame] | 60 | TEST_F(LegacyProbeControllerTest, ProbeOnlyWhenNetworkIsUp) { |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 61 | probe_controller_->OnNetworkStateChanged(kNetworkDown); |
| 62 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); |
Sergey Ulanov | e2b1501 | 2016-11-22 16:08:30 -0800 | [diff] [blame] | 63 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 64 | kMaxBitrateBps); |
Sergey Ulanov | e2b1501 | 2016-11-22 16:08:30 -0800 | [diff] [blame] | 65 | |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 66 | testing::Mock::VerifyAndClearExpectations(&pacer_); |
| 67 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(AtLeast(2)); |
| 68 | probe_controller_->OnNetworkStateChanged(kNetworkUp); |
Sergey Ulanov | e2b1501 | 2016-11-22 16:08:30 -0800 | [diff] [blame] | 69 | } |
| 70 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 13:07:28 +0100 | [diff] [blame] | 71 | TEST_F(LegacyProbeControllerTest, InitiatesProbingOnMaxBitrateIncrease) { |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 72 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(AtLeast(2)); |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 73 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 74 | kMaxBitrateBps); |
Irfan Sheriff | 9b7b753 | 2016-09-16 11:30:44 -0700 | [diff] [blame] | 75 | // Long enough to time out exponential probing. |
| 76 | clock_.AdvanceTimeMilliseconds(kExponentialProbingTimeoutMs); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 77 | probe_controller_->SetEstimatedBitrate(kStartBitrateBps); |
| 78 | probe_controller_->Process(); |
Irfan Sheriff | 9b7b753 | 2016-09-16 11:30:44 -0700 | [diff] [blame] | 79 | |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 80 | EXPECT_CALL(pacer_, CreateProbeCluster(kMaxBitrateBps + 100)); |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 81 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 82 | kMaxBitrateBps + 100); |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 13:07:28 +0100 | [diff] [blame] | 85 | TEST_F(LegacyProbeControllerTest, |
| 86 | InitiatesProbingOnMaxBitrateIncreaseAtMaxBitrate) { |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 87 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(AtLeast(2)); |
philipel | da5e9d0 | 2017-01-17 02:08:28 -0800 | [diff] [blame] | 88 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 89 | kMaxBitrateBps); |
philipel | da5e9d0 | 2017-01-17 02:08:28 -0800 | [diff] [blame] | 90 | // Long enough to time out exponential probing. |
| 91 | clock_.AdvanceTimeMilliseconds(kExponentialProbingTimeoutMs); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 92 | probe_controller_->SetEstimatedBitrate(kStartBitrateBps); |
| 93 | probe_controller_->Process(); |
philipel | da5e9d0 | 2017-01-17 02:08:28 -0800 | [diff] [blame] | 94 | |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 95 | probe_controller_->SetEstimatedBitrate(kMaxBitrateBps); |
| 96 | EXPECT_CALL(pacer_, CreateProbeCluster(kMaxBitrateBps + 100)); |
philipel | da5e9d0 | 2017-01-17 02:08:28 -0800 | [diff] [blame] | 97 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 98 | kMaxBitrateBps + 100); |
philipel | da5e9d0 | 2017-01-17 02:08:28 -0800 | [diff] [blame] | 99 | } |
| 100 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 13:07:28 +0100 | [diff] [blame] | 101 | TEST_F(LegacyProbeControllerTest, TestExponentialProbing) { |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 102 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 103 | kMaxBitrateBps); |
sergeyu | 07c147d | 2016-11-03 11:59:50 -0700 | [diff] [blame] | 104 | |
sergeyu | 5bc3945 | 2016-12-15 10:42:09 -0800 | [diff] [blame] | 105 | // Repeated probe should only be sent when estimated bitrate climbs above |
| 106 | // 0.7 * 6 * kStartBitrateBps = 1260. |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 107 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); |
| 108 | probe_controller_->SetEstimatedBitrate(1000); |
| 109 | testing::Mock::VerifyAndClearExpectations(&pacer_); |
sergeyu | 9cef11b | 2016-12-02 11:03:01 -0800 | [diff] [blame] | 110 | |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 111 | EXPECT_CALL(pacer_, CreateProbeCluster(2 * 1800)); |
| 112 | probe_controller_->SetEstimatedBitrate(1800); |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 13:07:28 +0100 | [diff] [blame] | 115 | TEST_F(LegacyProbeControllerTest, TestExponentialProbingTimeout) { |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 116 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 117 | kMaxBitrateBps); |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 118 | |
| 119 | // 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] | 120 | clock_.AdvanceTimeMilliseconds(kExponentialProbingTimeoutMs); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 121 | probe_controller_->Process(); |
sergeyu | 9cef11b | 2016-12-02 11:03:01 -0800 | [diff] [blame] | 122 | |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 123 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); |
| 124 | probe_controller_->SetEstimatedBitrate(1800); |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 13:07:28 +0100 | [diff] [blame] | 127 | TEST_F(LegacyProbeControllerTest, RequestProbeInAlr) { |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 128 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 129 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 130 | kMaxBitrateBps); |
| 131 | probe_controller_->SetEstimatedBitrate(500); |
| 132 | testing::Mock::VerifyAndClearExpectations(&pacer_); |
| 133 | EXPECT_CALL(pacer_, CreateProbeCluster(0.85 * 500)).Times(1); |
| 134 | EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) |
| 135 | .WillRepeatedly(Return(clock_.TimeInMilliseconds())); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 136 | clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 137 | probe_controller_->Process(); |
| 138 | probe_controller_->SetEstimatedBitrate(250); |
| 139 | probe_controller_->RequestProbe(); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 13:07:28 +0100 | [diff] [blame] | 142 | TEST_F(LegacyProbeControllerTest, RequestProbeWhenAlrEndedRecently) { |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 143 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 144 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 145 | kMaxBitrateBps); |
| 146 | probe_controller_->SetEstimatedBitrate(500); |
| 147 | testing::Mock::VerifyAndClearExpectations(&pacer_); |
| 148 | EXPECT_CALL(pacer_, CreateProbeCluster(0.85 * 500)).Times(1); |
| 149 | EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) |
Danil Chapovalov | 0040b66 | 2018-06-18 10:48:16 +0200 | [diff] [blame] | 150 | .WillRepeatedly(Return(absl::nullopt)); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 151 | clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 152 | probe_controller_->Process(); |
| 153 | probe_controller_->SetEstimatedBitrate(250); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 154 | probe_controller_->SetAlrEndedTimeMs(clock_.TimeInMilliseconds()); |
| 155 | clock_.AdvanceTimeMilliseconds(kAlrEndedTimeoutMs - 1); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 156 | probe_controller_->RequestProbe(); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 13:07:28 +0100 | [diff] [blame] | 159 | TEST_F(LegacyProbeControllerTest, RequestProbeWhenAlrNotEndedRecently) { |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 160 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 161 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 162 | kMaxBitrateBps); |
| 163 | probe_controller_->SetEstimatedBitrate(500); |
| 164 | testing::Mock::VerifyAndClearExpectations(&pacer_); |
| 165 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); |
| 166 | EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) |
Danil Chapovalov | 0040b66 | 2018-06-18 10:48:16 +0200 | [diff] [blame] | 167 | .WillRepeatedly(Return(absl::nullopt)); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 168 | clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 169 | probe_controller_->Process(); |
| 170 | probe_controller_->SetEstimatedBitrate(250); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 171 | probe_controller_->SetAlrEndedTimeMs(clock_.TimeInMilliseconds()); |
| 172 | clock_.AdvanceTimeMilliseconds(kAlrEndedTimeoutMs + 1); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 173 | probe_controller_->RequestProbe(); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 13:07:28 +0100 | [diff] [blame] | 176 | TEST_F(LegacyProbeControllerTest, RequestProbeWhenBweDropNotRecent) { |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 177 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 178 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 179 | kMaxBitrateBps); |
| 180 | probe_controller_->SetEstimatedBitrate(500); |
| 181 | testing::Mock::VerifyAndClearExpectations(&pacer_); |
| 182 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); |
| 183 | EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) |
| 184 | .WillRepeatedly(Return(clock_.TimeInMilliseconds())); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 185 | clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 186 | probe_controller_->Process(); |
| 187 | probe_controller_->SetEstimatedBitrate(250); |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 188 | clock_.AdvanceTimeMilliseconds(kBitrateDropTimeoutMs + 1); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 189 | probe_controller_->RequestProbe(); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 190 | } |
| 191 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 13:07:28 +0100 | [diff] [blame] | 192 | TEST_F(LegacyProbeControllerTest, PeriodicProbing) { |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 193 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 194 | probe_controller_->EnablePeriodicAlrProbing(true); |
| 195 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 196 | kMaxBitrateBps); |
| 197 | probe_controller_->SetEstimatedBitrate(500); |
| 198 | testing::Mock::VerifyAndClearExpectations(&pacer_); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 199 | |
| 200 | int64_t start_time = clock_.TimeInMilliseconds(); |
| 201 | |
| 202 | // Expect the controller to send a new probe after 5s has passed. |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 203 | EXPECT_CALL(pacer_, CreateProbeCluster(1000)).Times(1); |
| 204 | EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) |
| 205 | .WillRepeatedly(Return(start_time)); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 206 | clock_.AdvanceTimeMilliseconds(5000); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 207 | probe_controller_->Process(); |
| 208 | probe_controller_->SetEstimatedBitrate(500); |
| 209 | testing::Mock::VerifyAndClearExpectations(&pacer_); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 210 | |
| 211 | // The following probe should be sent at 10s into ALR. |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 212 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); |
| 213 | EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) |
| 214 | .WillRepeatedly(Return(start_time)); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 215 | clock_.AdvanceTimeMilliseconds(4000); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 216 | probe_controller_->Process(); |
| 217 | probe_controller_->SetEstimatedBitrate(500); |
| 218 | testing::Mock::VerifyAndClearExpectations(&pacer_); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 219 | |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 220 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(1); |
| 221 | EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) |
| 222 | .WillRepeatedly(Return(start_time)); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 223 | clock_.AdvanceTimeMilliseconds(1000); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 224 | probe_controller_->Process(); |
| 225 | probe_controller_->SetEstimatedBitrate(500); |
| 226 | testing::Mock::VerifyAndClearExpectations(&pacer_); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 227 | } |
| 228 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 13:07:28 +0100 | [diff] [blame] | 229 | TEST_F(LegacyProbeControllerTest, PeriodicProbingAfterReset) { |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 230 | testing::StrictMock<MockPacedSender> local_pacer; |
| 231 | probe_controller_.reset(new ProbeController(&local_pacer, &clock_)); |
philipel | d1d247f | 2017-05-04 08:35:52 -0700 | [diff] [blame] | 232 | int64_t alr_start_time = clock_.TimeInMilliseconds(); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 233 | EXPECT_CALL(local_pacer, GetApplicationLimitedRegionStartTime()) |
| 234 | .WillRepeatedly(Return(alr_start_time)); |
philipel | d1d247f | 2017-05-04 08:35:52 -0700 | [diff] [blame] | 235 | |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 236 | EXPECT_CALL(local_pacer, CreateProbeCluster(_)).Times(2); |
philipel | d1d247f | 2017-05-04 08:35:52 -0700 | [diff] [blame] | 237 | probe_controller_->EnablePeriodicAlrProbing(true); |
| 238 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 239 | kMaxBitrateBps); |
| 240 | probe_controller_->Reset(); |
philipel | d1d247f | 2017-05-04 08:35:52 -0700 | [diff] [blame] | 241 | |
| 242 | clock_.AdvanceTimeMilliseconds(10000); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 243 | probe_controller_->Process(); |
philipel | d1d247f | 2017-05-04 08:35:52 -0700 | [diff] [blame] | 244 | |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 245 | EXPECT_CALL(local_pacer, CreateProbeCluster(_)).Times(2); |
philipel | d1d247f | 2017-05-04 08:35:52 -0700 | [diff] [blame] | 246 | probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 247 | kMaxBitrateBps); |
philipel | d1d247f | 2017-05-04 08:35:52 -0700 | [diff] [blame] | 248 | |
| 249 | // Make sure we use |kStartBitrateBps| as the estimated bitrate |
| 250 | // until SetEstimatedBitrate is called with an updated estimate. |
| 251 | clock_.AdvanceTimeMilliseconds(10000); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 252 | EXPECT_CALL(local_pacer, CreateProbeCluster(kStartBitrateBps * 2)); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 +0000 | [diff] [blame] | 253 | probe_controller_->Process(); |
philipel | d1d247f | 2017-05-04 08:35:52 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 13:07:28 +0100 | [diff] [blame] | 256 | TEST_F(LegacyProbeControllerTest, TestExponentialProbingOverflow) { |
sergeyu | 5bc3945 | 2016-12-15 10:42:09 -0800 | [diff] [blame] | 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 | |
philipel | db4fa4b | 2018-03-06 18:29:22 +0100 | [diff] [blame] | 270 | TEST_F(LegacyProbeControllerTest, TotalBitrateProbing) { |
| 271 | probe_controller_->SetBitrates(kMinBitrateBps, 1 * kMbpsMultiplier, |
| 272 | 2 * kMbpsMultiplier); |
| 273 | |
| 274 | EXPECT_CALL(pacer_, CreateProbeCluster(1 * kMbpsMultiplier)); |
| 275 | probe_controller_->SetEstimatedBitrate(500000); |
| 276 | probe_controller_->OnMaxTotalAllocatedBitrate(1 * kMbpsMultiplier); |
| 277 | } |
| 278 | |
| 279 | TEST_F(LegacyProbeControllerTest, TotalBitrateNoProbing) { |
| 280 | probe_controller_->SetBitrates(kMinBitrateBps, 1 * kMbpsMultiplier, |
| 281 | 2 * kMbpsMultiplier); |
| 282 | |
| 283 | EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); |
| 284 | probe_controller_->SetEstimatedBitrate(500000); |
| 285 | probe_controller_->OnMaxTotalAllocatedBitrate(250000); |
| 286 | } |
| 287 | |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 288 | } // namespace test |
| 289 | } // namespace webrtc |