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

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

Issue 2931873002: Test and fix for huge bwe drop after alr state. (Closed)
Patch Set: Response to comments. Created 3 years, 6 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 "webrtc/base/fakeclock.h"
14 #include "webrtc/base/ptr_util.h"
15 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
16 #include "webrtc/test/gmock.h"
17 #include "webrtc/test/gtest.h"
18
19 using testing::_;
20 using testing::NiceMock;
21 using testing::InSequence;
22 using testing::Return;
23
24 namespace webrtc {
25
26 namespace {
27 class MockBitrateEstimator : public BitrateEstimator {
28 public:
29 ~MockBitrateEstimator() { Die(); }
30
31 MOCK_METHOD0(Die, void());
32 MOCK_METHOD2(Update, void(int64_t now_ms, int bytes));
33 MOCK_CONST_METHOD0(bitrate_bps, rtc::Optional<uint32_t>());
34 };
35
36 struct AcknowledgedBitrateEstimatorTestStates {
philipel 2017/06/14 09:34:05 Maybe change this to a test fixture and use TEST_F
tschumi 2017/06/14 10:57:46 @kwiberg-webrtc
kwiberg-webrtc 2017/06/14 11:49:21 Doing it this way instead of using a gtest test fi
philipel 2017/06/15 16:13:22 I'm not sure I understand, when should we use test
37 std::unique_ptr<AcknowledgedBitrateEstimator> acknowledged_bitrate_estimator;
38 MockBitrateEstimator* bitrate_estimator;
39 };
40
41 class MockBitrateEstimatorCreator : public BitrateEstimatorCreator {
42 public:
43 explicit MockBitrateEstimatorCreator(
44 AcknowledgedBitrateEstimatorTestStates* states)
45 : states_(states) {
46 RTC_CHECK(states_);
47 }
48 std::unique_ptr<BitrateEstimator> Create() const override {
49 auto bitrate_estimator = rtc::MakeUnique<NiceMock<MockBitrateEstimator>>();
50 states_->bitrate_estimator = bitrate_estimator.get();
51 return bitrate_estimator;
52 }
53 AcknowledgedBitrateEstimatorTestStates* states_;
54 };
55
56 AcknowledgedBitrateEstimatorTestStates CreateTestStates() {
57 AcknowledgedBitrateEstimatorTestStates states;
58 states.acknowledged_bitrate_estimator =
59 rtc::MakeUnique<AcknowledgedBitrateEstimator>(
60 rtc::MakeUnique<MockBitrateEstimatorCreator>(&states));
61 EXPECT_CALL(*states.bitrate_estimator, Die()).Times(1);
62 return states;
63 }
64
65 constexpr int64_t first_arrival_time_ms = 10;
66 constexpr int64_t first_send_time_ms = 10;
67 constexpr uint16_t sequence_number = 1;
68 constexpr size_t payload_size = 10;
philipel 2017/06/14 09:34:05 move these to the anonymous namespace
tschumi 2017/06/14 10:57:46 They already are in the anonymous namespace. The n
philipel 2017/06/15 16:13:22 oops
69
70 std::vector<PacketFeedback> CreateFeedbackVector() {
71 std::vector<PacketFeedback> packet_feedback_vector;
72 const PacedPacketInfo pacing_info;
73 packet_feedback_vector.push_back(
74 PacketFeedback(first_arrival_time_ms, first_send_time_ms, sequence_number,
75 payload_size, pacing_info));
76 packet_feedback_vector.push_back(
77 PacketFeedback(first_arrival_time_ms + 10, first_send_time_ms + 10,
78 sequence_number, payload_size + 10, pacing_info));
79 return packet_feedback_vector;
80 }
81
82 } // anonymous namespace
83
84 TEST(TestAcknowledgedBitrateEstimator, DontAddPacketsWhichAreNotInSendHistory) {
85 auto states = CreateTestStates();
86 std::vector<PacketFeedback> packet_feedback_vector;
87 packet_feedback_vector.push_back(
88 PacketFeedback(first_arrival_time_ms, sequence_number));
89 EXPECT_CALL(*states.bitrate_estimator, Update(_, _)).Times(0);
90 states.acknowledged_bitrate_estimator->IncomingPacketFeedbackVector(
91 packet_feedback_vector, false);
92 }
93
94 TEST(TestAcknowledgedBitrateEstimator, UpdateBandwith) {
95 auto states = CreateTestStates();
96 auto packet_feedback_vector = CreateFeedbackVector();
97 {
98 InSequence dummy;
99 EXPECT_CALL(*states.bitrate_estimator,
100 Update(packet_feedback_vector[0].arrival_time_ms,
101 packet_feedback_vector[0].payload_size))
102 .Times(1);
103 EXPECT_CALL(*states.bitrate_estimator,
104 Update(packet_feedback_vector[1].arrival_time_ms,
105 packet_feedback_vector[1].payload_size))
106 .Times(1);
107 }
108 states.acknowledged_bitrate_estimator->IncomingPacketFeedbackVector(
109 packet_feedback_vector, false);
110 }
111
112 TEST(TestAcknowledgedBitrateEstimator,
113 ResetAfterLeafAlrStateAndDontAddOldPackets) {
114 auto states = CreateTestStates();
115 auto packet_feedback_vector = CreateFeedbackVector();
116 states.acknowledged_bitrate_estimator->IncomingPacketFeedbackVector(
117 packet_feedback_vector, true);
118
119 rtc::ScopedFakeClock fake_clock;
120
121 fake_clock.AdvanceTime(
122 rtc::TimeDelta::FromMilliseconds(first_arrival_time_ms + 1));
123 states.acknowledged_bitrate_estimator->IncomingPacketFeedbackVector(
124 std::vector<PacketFeedback>(), false);
125 EXPECT_CALL(*states.bitrate_estimator, Die()).Times(1);
126
127 {
128 InSequence dummy;
129 EXPECT_CALL(*states.bitrate_estimator,
130 Update(packet_feedback_vector[0].arrival_time_ms,
131 packet_feedback_vector[0].payload_size))
132 .Times(0);
133 EXPECT_CALL(*states.bitrate_estimator,
134 Update(packet_feedback_vector[1].arrival_time_ms,
135 packet_feedback_vector[1].payload_size))
136 .Times(1);
137 }
138 states.acknowledged_bitrate_estimator->IncomingPacketFeedbackVector(
139 packet_feedback_vector, false);
140 }
141
142 TEST(TestAcknowledgedBitrateEstimator, ReturnBitrate) {
143 auto states = CreateTestStates();
144 rtc::Optional<uint32_t> return_value(42);
145 EXPECT_CALL(*states.bitrate_estimator, bitrate_bps())
146 .Times(1)
147 .WillOnce(Return(return_value));
148 EXPECT_EQ(return_value, states.acknowledged_bitrate_estimator->bitrate_bps());
149 }
150
151 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698