1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "net/quic/congestion_control/hybrid_slow_start.h"
7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "testing/gtest/include/gtest/gtest.h"
14 class HybridSlowStartTest
: public ::testing::Test
{
17 : one_ms_(QuicTime::Delta::FromMilliseconds(1)),
18 rtt_(QuicTime::Delta::FromMilliseconds(60)) {
20 void SetUp() override
{ slow_start_
.reset(new HybridSlowStart()); }
21 const QuicTime::Delta one_ms_
;
22 const QuicTime::Delta rtt_
;
23 scoped_ptr
<HybridSlowStart
> slow_start_
;
26 TEST_F(HybridSlowStartTest
, Simple
) {
27 QuicPacketNumber packet_number
= 1;
28 QuicPacketNumber end_packet_number
= 3;
29 slow_start_
->StartReceiveRound(end_packet_number
);
31 EXPECT_FALSE(slow_start_
->IsEndOfRound(packet_number
++));
34 EXPECT_FALSE(slow_start_
->IsEndOfRound(packet_number
));
36 EXPECT_FALSE(slow_start_
->IsEndOfRound(packet_number
++));
37 EXPECT_TRUE(slow_start_
->IsEndOfRound(packet_number
++));
39 // Test without a new registered end_packet_number;
40 EXPECT_TRUE(slow_start_
->IsEndOfRound(packet_number
++));
42 end_packet_number
= 20;
43 slow_start_
->StartReceiveRound(end_packet_number
);
44 while (packet_number
< end_packet_number
) {
45 EXPECT_FALSE(slow_start_
->IsEndOfRound(packet_number
++));
47 EXPECT_TRUE(slow_start_
->IsEndOfRound(packet_number
++));
50 TEST_F(HybridSlowStartTest
, Delay
) {
51 // We expect to detect the increase at +1/8 of the RTT; hence at a typical
52 // RTT of 60ms the detection will happen at 67.5 ms.
53 const int kHybridStartMinSamples
= 8; // Number of acks required to trigger.
55 QuicPacketNumber end_packet_number
= 1;
56 slow_start_
->StartReceiveRound(end_packet_number
++);
58 // Will not trigger since our lowest RTT in our burst is the same as the long
60 for (int n
= 0; n
< kHybridStartMinSamples
; ++n
) {
61 EXPECT_FALSE(slow_start_
->ShouldExitSlowStart(
62 rtt_
.Add(QuicTime::Delta::FromMilliseconds(n
)), rtt_
, 100));
64 slow_start_
->StartReceiveRound(end_packet_number
++);
65 for (int n
= 1; n
< kHybridStartMinSamples
; ++n
) {
66 EXPECT_FALSE(slow_start_
->ShouldExitSlowStart(
67 rtt_
.Add(QuicTime::Delta::FromMilliseconds(n
+ 10)), rtt_
, 100));
69 // Expect to trigger since all packets in this burst was above the long term
71 EXPECT_TRUE(slow_start_
->ShouldExitSlowStart(
72 rtt_
.Add(QuicTime::Delta::FromMilliseconds(10)), rtt_
, 100));