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