aboutsummaryrefslogtreecommitdiff
path: root/modules/congestion_controller/goog_cc/congestion_window_pushback_controller_unittest.cc
blob: 4299e054200bc74af93e17a8b3de893a8543b1ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
 *  Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include "modules/congestion_controller/goog_cc/congestion_window_pushback_controller.h"

#include <cstdint>
#include <memory>

#include "api/units/data_size.h"
#include "test/explicit_key_value_config.h"
#include "test/gmock.h"
#include "test/gtest.h"

namespace webrtc {
namespace test {

using ::testing::_;

TEST(CongestionWindowPushbackControllerTest, FullCongestionWindow) {
  CongestionWindowPushbackController cwnd_controller(
      ExplicitKeyValueConfig(""));

  cwnd_controller.UpdateOutstandingData(100000);
  cwnd_controller.SetDataWindow(DataSize::Bytes(50000));

  uint32_t bitrate_bps = 80000;
  bitrate_bps = cwnd_controller.UpdateTargetBitrate(bitrate_bps);
  EXPECT_EQ(72000u, bitrate_bps);

  cwnd_controller.SetDataWindow(DataSize::Bytes(50000));
  bitrate_bps = cwnd_controller.UpdateTargetBitrate(bitrate_bps);
  EXPECT_EQ(static_cast<uint32_t>(72000 * 0.9 * 0.9), bitrate_bps);
}

TEST(CongestionWindowPushbackControllerTest, NormalCongestionWindow) {
  CongestionWindowPushbackController cwnd_controller(
      ExplicitKeyValueConfig(""));

  cwnd_controller.UpdateOutstandingData(199999);
  cwnd_controller.SetDataWindow(DataSize::Bytes(200000));

  uint32_t bitrate_bps = 80000;
  bitrate_bps = cwnd_controller.UpdateTargetBitrate(bitrate_bps);
  EXPECT_EQ(80000u, bitrate_bps);
}

TEST(CongestionWindowPushbackControllerTest, LowBitrate) {
  CongestionWindowPushbackController cwnd_controller(
      ExplicitKeyValueConfig(""));

  cwnd_controller.UpdateOutstandingData(100000);
  cwnd_controller.SetDataWindow(DataSize::Bytes(50000));

  uint32_t bitrate_bps = 35000;
  bitrate_bps = cwnd_controller.UpdateTargetBitrate(bitrate_bps);
  EXPECT_EQ(static_cast<uint32_t>(35000 * 0.9), bitrate_bps);

  cwnd_controller.SetDataWindow(DataSize::Bytes(20000));
  bitrate_bps = cwnd_controller.UpdateTargetBitrate(bitrate_bps);
  EXPECT_EQ(30000u, bitrate_bps);
}

TEST(CongestionWindowPushbackControllerTest, NoPushbackOnDataWindowUnset) {
  CongestionWindowPushbackController cwnd_controller(
      ExplicitKeyValueConfig(""));

  cwnd_controller.UpdateOutstandingData(1e8);  // Large number

  uint32_t bitrate_bps = 80000;
  bitrate_bps = cwnd_controller.UpdateTargetBitrate(bitrate_bps);
  EXPECT_EQ(80000u, bitrate_bps);
}

TEST(CongestionWindowPushbackControllerTest, PushbackOnInititialDataWindow) {
  CongestionWindowPushbackController cwnd_controller(
      ExplicitKeyValueConfig("WebRTC-CongestionWindow/InitWin:100000/"));

  cwnd_controller.UpdateOutstandingData(1e8);  // Large number

  uint32_t bitrate_bps = 80000;
  bitrate_bps = cwnd_controller.UpdateTargetBitrate(bitrate_bps);
  EXPECT_GT(80000u, bitrate_bps);
}

TEST(CongestionWindowPushbackControllerTest, PushbackDropFrame) {
  CongestionWindowPushbackController cwnd_controller(
      ExplicitKeyValueConfig("WebRTC-CongestionWindow/DropFrame:true/"));

  cwnd_controller.UpdateOutstandingData(1e8);  // Large number
  cwnd_controller.SetDataWindow(DataSize::Bytes(50000));

  uint32_t bitrate_bps = 80000;
  bitrate_bps = cwnd_controller.UpdateTargetBitrate(bitrate_bps);
  EXPECT_GT(80000u, bitrate_bps);
}

}  // namespace test
}  // namespace webrtc