| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "webrtc/base/logging.h" | 12 #include "webrtc/base/logging.h" |
| 13 #include "webrtc/modules/congestion_controller/probe_controller.h" | 13 #include "webrtc/modules/congestion_controller/probe_controller.h" |
| 14 #include "webrtc/modules/pacing/mock/mock_paced_sender.h" | 14 #include "webrtc/modules/pacing/mock/mock_paced_sender.h" |
| 15 #include "webrtc/system_wrappers/include/clock.h" | 15 #include "webrtc/system_wrappers/include/clock.h" |
| 16 #include "webrtc/test/gmock.h" | 16 #include "webrtc/test/gmock.h" |
| 17 #include "webrtc/test/gtest.h" | 17 #include "webrtc/test/gtest.h" |
| 18 | 18 |
| 19 using testing::_; | 19 using testing::_; |
| 20 using testing::AtLeast; | 20 using testing::AtLeast; |
| 21 using testing::NiceMock; | 21 using testing::NiceMock; |
| 22 using testing::Return; |
| 22 | 23 |
| 23 namespace webrtc { | 24 namespace webrtc { |
| 24 namespace test { | 25 namespace test { |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 constexpr int kMinBitrateBps = 100; | 29 constexpr int kMinBitrateBps = 100; |
| 29 constexpr int kStartBitrateBps = 300; | 30 constexpr int kStartBitrateBps = 300; |
| 30 constexpr int kMaxBitrateBps = 10000; | 31 constexpr int kMaxBitrateBps = 10000; |
| 31 | 32 |
| 32 constexpr int kExponentialProbingTimeoutMs = 5000; | 33 constexpr int kExponentialProbingTimeoutMs = 5000; |
| 33 | 34 |
| 35 constexpr int kAlrProbeInterval = 5000; |
| 36 |
| 34 } // namespace | 37 } // namespace |
| 35 | 38 |
| 36 class ProbeControllerTest : public ::testing::Test { | 39 class ProbeControllerTest : public ::testing::Test { |
| 37 protected: | 40 protected: |
| 38 ProbeControllerTest() : clock_(0) { | 41 ProbeControllerTest() : clock_(100000000L) { |
| 39 probe_controller_.reset(new ProbeController(&pacer_, &clock_)); | 42 probe_controller_.reset(new ProbeController(&pacer_, &clock_)); |
| 40 } | 43 } |
| 41 ~ProbeControllerTest() override {} | 44 ~ProbeControllerTest() override {} |
| 42 | 45 |
| 43 SimulatedClock clock_; | 46 SimulatedClock clock_; |
| 44 NiceMock<MockPacedSender> pacer_; | 47 NiceMock<MockPacedSender> pacer_; |
| 45 std::unique_ptr<ProbeController> probe_controller_; | 48 std::unique_ptr<ProbeController> probe_controller_; |
| 46 }; | 49 }; |
| 47 | 50 |
| 48 TEST_F(ProbeControllerTest, InitiatesProbingAtStart) { | 51 TEST_F(ProbeControllerTest, InitiatesProbingAtStart) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 72 | 75 |
| 73 EXPECT_CALL(pacer_, CreateProbeCluster(kMaxBitrateBps + 100, _)); | 76 EXPECT_CALL(pacer_, CreateProbeCluster(kMaxBitrateBps + 100, _)); |
| 74 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, | 77 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
| 75 kMaxBitrateBps + 100); | 78 kMaxBitrateBps + 100); |
| 76 } | 79 } |
| 77 | 80 |
| 78 TEST_F(ProbeControllerTest, TestExponentialProbing) { | 81 TEST_F(ProbeControllerTest, TestExponentialProbing) { |
| 79 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, | 82 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
| 80 kMaxBitrateBps); | 83 kMaxBitrateBps); |
| 81 | 84 |
| 82 | |
| 83 | |
| 84 EXPECT_CALL(pacer_, CreateProbeCluster(2 * 1800, _)); | 85 EXPECT_CALL(pacer_, CreateProbeCluster(2 * 1800, _)); |
| 85 probe_controller_->SetEstimatedBitrate(1800); | 86 probe_controller_->SetEstimatedBitrate(1800); |
| 86 } | 87 } |
| 87 | 88 |
| 88 TEST_F(ProbeControllerTest, TestExponentialProbingTimeout) { | 89 TEST_F(ProbeControllerTest, TestExponentialProbingTimeout) { |
| 89 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, | 90 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
| 90 kMaxBitrateBps); | 91 kMaxBitrateBps); |
| 91 | 92 |
| 92 // Advance far enough to cause a time out in waiting for probing result. | 93 // Advance far enough to cause a time out in waiting for probing result. |
| 93 clock_.AdvanceTimeMilliseconds(kExponentialProbingTimeoutMs); | 94 clock_.AdvanceTimeMilliseconds(kExponentialProbingTimeoutMs); |
| 94 EXPECT_CALL(pacer_, CreateProbeCluster(2 * 1800, _)).Times(0); | 95 EXPECT_CALL(pacer_, CreateProbeCluster(2 * 1800, _)).Times(0); |
| 95 probe_controller_->SetEstimatedBitrate(1800); | 96 probe_controller_->SetEstimatedBitrate(1800); |
| 96 } | 97 } |
| 97 | 98 |
| 99 TEST_F(ProbeControllerTest, ProbeAfterEstimateDropInAlr) { |
| 100 EXPECT_CALL(pacer_, CreateProbeCluster(_, _)).Times(2); |
| 101 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
| 102 kMaxBitrateBps); |
| 103 probe_controller_->SetEstimatedBitrate(500); |
| 104 testing::Mock::VerifyAndClearExpectations(&pacer_); |
| 105 |
| 106 // When bandwidth estimate drops the controller should send a probe at the |
| 107 // previous bitrate. |
| 108 EXPECT_CALL(pacer_, CreateProbeCluster(500, _)).Times(1); |
| 109 EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) |
| 110 .WillRepeatedly(Return(clock_.TimeInMilliseconds())); |
| 111 clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1); |
| 112 probe_controller_->SetEstimatedBitrate(50); |
| 113 } |
| 114 |
| 115 TEST_F(ProbeControllerTest, PeriodicProbing) { |
| 116 EXPECT_CALL(pacer_, CreateProbeCluster(_, _)).Times(2); |
| 117 probe_controller_->EnablePeriodicProbing(true); |
| 118 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
| 119 kMaxBitrateBps); |
| 120 probe_controller_->SetEstimatedBitrate(500); |
| 121 testing::Mock::VerifyAndClearExpectations(&pacer_); |
| 122 |
| 123 int64_t start_time = clock_.TimeInMilliseconds(); |
| 124 |
| 125 // Expect the controller to send a new probe after 5s has passed. |
| 126 EXPECT_CALL(pacer_, CreateProbeCluster(1000, _)).Times(1); |
| 127 EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) |
| 128 .WillRepeatedly(Return(start_time)); |
| 129 clock_.AdvanceTimeMilliseconds(5000); |
| 130 probe_controller_->Process(); |
| 131 probe_controller_->SetEstimatedBitrate(500); |
| 132 testing::Mock::VerifyAndClearExpectations(&pacer_); |
| 133 |
| 134 // The following probe should be sent at 10s into ALR. |
| 135 EXPECT_CALL(pacer_, CreateProbeCluster(_, _)).Times(0); |
| 136 EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) |
| 137 .WillRepeatedly(Return(start_time)); |
| 138 clock_.AdvanceTimeMilliseconds(4000); |
| 139 probe_controller_->Process(); |
| 140 probe_controller_->SetEstimatedBitrate(500); |
| 141 testing::Mock::VerifyAndClearExpectations(&pacer_); |
| 142 |
| 143 EXPECT_CALL(pacer_, CreateProbeCluster(_, _)).Times(1); |
| 144 EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) |
| 145 .WillRepeatedly(Return(start_time)); |
| 146 clock_.AdvanceTimeMilliseconds(1000); |
| 147 probe_controller_->Process(); |
| 148 probe_controller_->SetEstimatedBitrate(500); |
| 149 testing::Mock::VerifyAndClearExpectations(&pacer_); |
| 150 } |
| 151 |
| 98 } // namespace test | 152 } // namespace test |
| 99 } // namespace webrtc | 153 } // namespace webrtc |
| OLD | NEW |