blob: 98e116644ca714c9c17ceb21f64663246746a143 [file] [log] [blame]
Irfan Sheriffb2540bb2016-09-12 12:28:54 -07001/*
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
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070012#include "webrtc/base/logging.h"
13#include "webrtc/modules/congestion_controller/probe_controller.h"
14#include "webrtc/modules/pacing/mock/mock_paced_sender.h"
15#include "webrtc/system_wrappers/include/clock.h"
kwibergac9f8762016-09-30 22:29:43 -070016#include "webrtc/test/gmock.h"
17#include "webrtc/test/gtest.h"
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070018
19using testing::_;
20using testing::AtLeast;
21using testing::NiceMock;
22
23namespace webrtc {
24namespace test {
25
26namespace {
27
28constexpr int kMinBitrateBps = 100;
29constexpr int kStartBitrateBps = 300;
sergeyu07c147d2016-11-03 11:59:50 -070030constexpr int kMaxBitrateBps = 10000;
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070031
Irfan Sheriff9b7b7532016-09-16 11:30:44 -070032constexpr int kExponentialProbingTimeoutMs = 5000;
33
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070034} // namespace
35
36class ProbeControllerTest : public ::testing::Test {
37 protected:
38 ProbeControllerTest() : clock_(0) {
39 probe_controller_.reset(new ProbeController(&pacer_, &clock_));
40 }
41 ~ProbeControllerTest() override {}
42
43 SimulatedClock clock_;
44 NiceMock<MockPacedSender> pacer_;
45 std::unique_ptr<ProbeController> probe_controller_;
46};
47
48TEST_F(ProbeControllerTest, InitiatesProbingAtStart) {
49 EXPECT_CALL(pacer_, CreateProbeCluster(_, _)).Times(AtLeast(2));
50 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
51 kMaxBitrateBps);
52}
53
54TEST_F(ProbeControllerTest, InitiatesProbingOnMaxBitrateIncrease) {
55 EXPECT_CALL(pacer_, CreateProbeCluster(_, _)).Times(AtLeast(2));
56 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
57 kMaxBitrateBps);
Irfan Sheriff9b7b7532016-09-16 11:30:44 -070058 // Long enough to time out exponential probing.
59 clock_.AdvanceTimeMilliseconds(kExponentialProbingTimeoutMs);
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070060 probe_controller_->SetEstimatedBitrate(kStartBitrateBps);
Irfan Sheriff9b7b7532016-09-16 11:30:44 -070061
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070062 EXPECT_CALL(pacer_, CreateProbeCluster(kMaxBitrateBps + 100, _));
63 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
64 kMaxBitrateBps + 100);
65}
66
67TEST_F(ProbeControllerTest, TestExponentialProbing) {
68 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
69 kMaxBitrateBps);
sergeyu07c147d2016-11-03 11:59:50 -070070
71
72
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070073 EXPECT_CALL(pacer_, CreateProbeCluster(2 * 1800, _));
74 probe_controller_->SetEstimatedBitrate(1800);
75}
76
77TEST_F(ProbeControllerTest, TestExponentialProbingTimeout) {
78 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
79 kMaxBitrateBps);
80
81 // Advance far enough to cause a time out in waiting for probing result.
Irfan Sheriff9b7b7532016-09-16 11:30:44 -070082 clock_.AdvanceTimeMilliseconds(kExponentialProbingTimeoutMs);
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070083 EXPECT_CALL(pacer_, CreateProbeCluster(2 * 1800, _)).Times(0);
84 probe_controller_->SetEstimatedBitrate(1800);
85}
86
87} // namespace test
88} // namespace webrtc