Add explicit |forceOnlineSignin| to user pod status
[chromium-blink-merge.git] / net / quic / congestion_control / hybrid_slow_start_test.cc
blob0a9f91fd3f03ef6042c41eadca94e5c65c404c4d
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 "base/logging.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "net/quic/congestion_control/hybrid_slow_start.h"
8 #include "net/quic/test_tools/mock_clock.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace net {
12 namespace test {
14 class HybridSlowStartTest : public ::testing::Test {
15 protected:
16 HybridSlowStartTest()
17 : one_ms_(QuicTime::Delta::FromMilliseconds(1)),
18 rtt_(QuicTime::Delta::FromMilliseconds(60)) {
20 virtual void SetUp() {
21 slowStart_.reset(new HybridSlowStart(&clock_));
23 const QuicTime::Delta one_ms_;
24 const QuicTime::Delta rtt_;
25 MockClock clock_;
26 scoped_ptr<HybridSlowStart> slowStart_;
29 TEST_F(HybridSlowStartTest, Simple) {
30 QuicPacketSequenceNumber sequence_number = 1;
31 QuicPacketSequenceNumber end_sequence_number = 3;
32 slowStart_->Reset(end_sequence_number);
34 EXPECT_FALSE(slowStart_->EndOfRound(sequence_number++));
36 // Test duplicates.
37 EXPECT_FALSE(slowStart_->EndOfRound(sequence_number));
39 EXPECT_FALSE(slowStart_->EndOfRound(sequence_number++));
40 EXPECT_TRUE(slowStart_->EndOfRound(sequence_number++));
42 // Test without a new registered end_sequence_number;
43 EXPECT_TRUE(slowStart_->EndOfRound(sequence_number++));
45 end_sequence_number = 20;
46 slowStart_->Reset(end_sequence_number);
47 while (sequence_number < end_sequence_number) {
48 EXPECT_FALSE(slowStart_->EndOfRound(sequence_number++));
50 EXPECT_TRUE(slowStart_->EndOfRound(sequence_number++));
53 TEST_F(HybridSlowStartTest, AckTrain) {
54 // At a typical RTT 60 ms, assuming that the inter arrival is 1 ms,
55 // we expect to be able to send a burst of 30 packet before we trigger the
56 // ack train detection.
57 const int kMaxLoopCount = 5;
58 QuicPacketSequenceNumber sequence_number = 2;
59 QuicPacketSequenceNumber end_sequence_number = 2;
60 for (int burst = 0; burst < kMaxLoopCount; ++burst) {
61 slowStart_->Reset(end_sequence_number);
62 do {
63 clock_.AdvanceTime(one_ms_);
64 slowStart_->Update(rtt_, rtt_);
65 EXPECT_FALSE(slowStart_->Exit());
66 } while (!slowStart_->EndOfRound(sequence_number++));
67 end_sequence_number *= 2; // Exponential growth.
69 slowStart_->Reset(end_sequence_number);
71 for (int n = 0; n < 29 && !slowStart_->EndOfRound(sequence_number++); ++n) {
72 clock_.AdvanceTime(one_ms_);
73 slowStart_->Update(rtt_, rtt_);
74 EXPECT_FALSE(slowStart_->Exit());
76 clock_.AdvanceTime(one_ms_);
77 slowStart_->Update(rtt_, rtt_);
78 EXPECT_TRUE(slowStart_->Exit());
81 TEST_F(HybridSlowStartTest, Delay) {
82 // We expect to detect the increase at +1/16 of the RTT; hence at a typical
83 // RTT of 60ms the detection will happen at 63.75 ms.
84 const int kHybridStartMinSamples = 8; // Number of acks required to trigger.
86 QuicPacketSequenceNumber end_sequence_number = 1;
87 slowStart_->Reset(end_sequence_number++);
89 // Will not trigger since our lowest RTT in our burst is the same as the long
90 // term RTT provided.
91 for (int n = 0; n < kHybridStartMinSamples; ++n) {
92 slowStart_->Update(rtt_.Add(QuicTime::Delta::FromMilliseconds(n)), rtt_);
93 EXPECT_FALSE(slowStart_->Exit());
95 slowStart_->Reset(end_sequence_number++);
96 for (int n = 1; n < kHybridStartMinSamples; ++n) {
97 slowStart_->Update(rtt_.Add(QuicTime::Delta::FromMilliseconds(n + 4)),
98 rtt_);
99 EXPECT_FALSE(slowStart_->Exit());
101 // Expect to trigger since all packets in this burst was above the long term
102 // RTT provided.
103 slowStart_->Update(rtt_.Add(QuicTime::Delta::FromMilliseconds(4)), rtt_);
104 EXPECT_TRUE(slowStart_->Exit());
107 } // namespace test
108 } // namespace net