Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(347)

Side by Side Diff: webrtc/modules/congestion_controller/acknowledged_bitrate_estimator_unittest.cc

Issue 2970653004: Reimplemeted "Test and fix for huge bwe drop after alr state" (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2017 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
11 #include "webrtc/modules/congestion_controller/acknowledged_bitrate_estimator.h"
12
13 #include <utility>
14
15 #include "webrtc/base/fakeclock.h"
16 #include "webrtc/base/ptr_util.h"
17 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
18 #include "webrtc/test/gmock.h"
19 #include "webrtc/test/gtest.h"
20
21 using testing::_;
22 using testing::NiceMock;
23 using testing::InSequence;
24 using testing::Return;
25
26 namespace webrtc {
27
28 namespace {
29
30 constexpr int64_t first_arrival_time_ms = 10;
31 constexpr int64_t first_send_time_ms = 10;
32 constexpr uint16_t sequence_number = 1;
33 constexpr size_t payload_size = 10;
34
35 class MockBitrateEstimator : public BitrateEstimator {
36 public:
37 MOCK_METHOD2(Update, void(int64_t now_ms, int bytes));
38 MOCK_CONST_METHOD0(bitrate_bps, rtc::Optional<uint32_t>());
39 MOCK_METHOD0(ExpectFastRateChange, void());
40 };
41
42 struct AcknowledgedBitrateEstimatorTestStates {
43 std::unique_ptr<AcknowledgedBitrateEstimator> acknowledged_bitrate_estimator;
44 MockBitrateEstimator* mock_bitrate_estimator;
45 };
46
47 AcknowledgedBitrateEstimatorTestStates CreateTestStates() {
48 AcknowledgedBitrateEstimatorTestStates states;
49 auto mock_bitrate_estimator = rtc::MakeUnique<MockBitrateEstimator>();
50 states.mock_bitrate_estimator = mock_bitrate_estimator.get();
51 states.acknowledged_bitrate_estimator =
52 rtc::MakeUnique<AcknowledgedBitrateEstimator>(
53 std::move(mock_bitrate_estimator));
54 return states;
55 }
56
57 std::vector<PacketFeedback> CreateFeedbackVector() {
58 std::vector<PacketFeedback> packet_feedback_vector;
59 const PacedPacketInfo pacing_info;
60 packet_feedback_vector.push_back(
61 PacketFeedback(first_arrival_time_ms, first_send_time_ms, sequence_number,
62 payload_size, pacing_info));
63 packet_feedback_vector.push_back(
64 PacketFeedback(first_arrival_time_ms + 10, first_send_time_ms + 10,
65 sequence_number, payload_size + 10, pacing_info));
66 return packet_feedback_vector;
67 }
68
69 } // anonymous namespace
70
71 TEST(TestAcknowledgedBitrateEstimator, DontAddPacketsWhichAreNotInSendHistory) {
72 auto states = CreateTestStates();
73 std::vector<PacketFeedback> packet_feedback_vector;
74 packet_feedback_vector.push_back(
75 PacketFeedback(first_arrival_time_ms, sequence_number));
76 EXPECT_CALL(*states.mock_bitrate_estimator, Update(_, _)).Times(0);
77 states.acknowledged_bitrate_estimator->IncomingPacketFeedbackVector(
78 packet_feedback_vector, false);
79 }
80
81 TEST(TestAcknowledgedBitrateEstimator, UpdateBandwith) {
82 auto states = CreateTestStates();
83 auto packet_feedback_vector = CreateFeedbackVector();
84 {
85 InSequence dummy;
86 EXPECT_CALL(
87 *states.mock_bitrate_estimator,
88 Update(packet_feedback_vector[0].arrival_time_ms,
89 static_cast<int>(packet_feedback_vector[0].payload_size)))
90 .Times(1);
91 EXPECT_CALL(
92 *states.mock_bitrate_estimator,
93 Update(packet_feedback_vector[1].arrival_time_ms,
94 static_cast<int>(packet_feedback_vector[1].payload_size)))
95 .Times(1);
96 }
97 states.acknowledged_bitrate_estimator->IncomingPacketFeedbackVector(
98 packet_feedback_vector, false);
99 }
100
101 TEST(TestAcknowledgedBitrateEstimator, ExpectFastRateChangeWhenLeftAlr) {
102 auto states = CreateTestStates();
103 auto packet_feedback_vector = CreateFeedbackVector();
104 rtc::ScopedFakeClock fake_clock;
105 fake_clock.AdvanceTime(
106 rtc::TimeDelta::FromMilliseconds(first_arrival_time_ms));
107 {
108 InSequence dummy;
109 EXPECT_CALL(
110 *states.mock_bitrate_estimator,
111 Update(packet_feedback_vector[0].arrival_time_ms,
112 static_cast<int>(packet_feedback_vector[0].payload_size)))
113 .Times(1);
114 EXPECT_CALL(*states.mock_bitrate_estimator, ExpectFastRateChange())
115 .Times(1);
116 EXPECT_CALL(
117 *states.mock_bitrate_estimator,
118 Update(packet_feedback_vector[1].arrival_time_ms,
119 static_cast<int>(packet_feedback_vector[1].payload_size)))
120 .Times(1);
121 }
122 states.acknowledged_bitrate_estimator->IncomingPacketFeedbackVector(
123 std::vector<PacketFeedback>(), true);
124 states.acknowledged_bitrate_estimator->IncomingPacketFeedbackVector(
125 std::vector<PacketFeedback>(), false);
126 states.acknowledged_bitrate_estimator->IncomingPacketFeedbackVector(
127 packet_feedback_vector, false);
128 }
129
130 TEST(TestAcknowledgedBitrateEstimator, ReturnBitrate) {
131 auto states = CreateTestStates();
132 rtc::Optional<uint32_t> return_value(42);
133 EXPECT_CALL(*states.mock_bitrate_estimator, bitrate_bps())
134 .Times(1)
135 .WillOnce(Return(return_value));
136 EXPECT_EQ(return_value, states.acknowledged_bitrate_estimator->bitrate_bps());
137 }
138
139 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698