OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/logging.h" | 5 #include "base/logging.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "net/quic/congestion_control/hybrid_slow_start.h" | 7 #include "net/quic/congestion_control/hybrid_slow_start.h" |
8 #include "net/quic/test_tools/mock_clock.h" | 8 #include "net/quic/test_tools/mock_clock.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 namespace net { | 11 namespace net { |
12 namespace test { | 12 namespace test { |
13 | 13 |
14 class HybridSlowStartTest : public ::testing::Test { | 14 class HybridSlowStartTest : public ::testing::Test { |
15 protected: | 15 protected: |
16 HybridSlowStartTest() | 16 HybridSlowStartTest() |
17 : one_ms_(QuicTime::Delta::FromMilliseconds(1)), | 17 : one_ms_(QuicTime::Delta::FromMilliseconds(1)), |
18 rtt_(QuicTime::Delta::FromMilliseconds(60)) { | 18 rtt_(QuicTime::Delta::FromMilliseconds(60)) {} |
19 } | 19 virtual void SetUp() { slowStart_.reset(new HybridSlowStart(&clock_)); } |
20 virtual void SetUp() { | |
21 slowStart_.reset(new HybridSlowStart(&clock_)); | |
22 } | |
23 const QuicTime::Delta one_ms_; | 20 const QuicTime::Delta one_ms_; |
24 const QuicTime::Delta rtt_; | 21 const QuicTime::Delta rtt_; |
25 MockClock clock_; | 22 MockClock clock_; |
26 scoped_ptr<HybridSlowStart> slowStart_; | 23 scoped_ptr<HybridSlowStart> slowStart_; |
27 }; | 24 }; |
28 | 25 |
29 TEST_F(HybridSlowStartTest, Simple) { | 26 TEST_F(HybridSlowStartTest, Simple) { |
30 QuicPacketSequenceNumber sequence_number = 1; | 27 QuicPacketSequenceNumber sequence_number = 1; |
31 QuicPacketSequenceNumber end_sequence_number = 3; | 28 QuicPacketSequenceNumber end_sequence_number = 3; |
32 slowStart_->StartReceiveRound(end_sequence_number); | 29 slowStart_->StartReceiveRound(end_sequence_number); |
(...skipping 24 matching lines...) Expand all Loading... |
57 // we expect to be able to send a burst of 30 packet before we trigger the | 54 // we expect to be able to send a burst of 30 packet before we trigger the |
58 // ack train detection. | 55 // ack train detection. |
59 const int kMaxLoopCount = 5; | 56 const int kMaxLoopCount = 5; |
60 QuicPacketSequenceNumber sequence_number = 2; | 57 QuicPacketSequenceNumber sequence_number = 2; |
61 QuicPacketSequenceNumber end_sequence_number = 2; | 58 QuicPacketSequenceNumber end_sequence_number = 2; |
62 for (int burst = 0; burst < kMaxLoopCount; ++burst) { | 59 for (int burst = 0; burst < kMaxLoopCount; ++burst) { |
63 slowStart_->StartReceiveRound(end_sequence_number); | 60 slowStart_->StartReceiveRound(end_sequence_number); |
64 do { | 61 do { |
65 clock_.AdvanceTime(one_ms_); | 62 clock_.AdvanceTime(one_ms_); |
66 EXPECT_FALSE(slowStart_->ShouldExitSlowStart(rtt_, rtt_, 100)); | 63 EXPECT_FALSE(slowStart_->ShouldExitSlowStart(rtt_, rtt_, 100)); |
67 } while (!slowStart_->IsEndOfRound(sequence_number++)); | 64 } while (!slowStart_->IsEndOfRound(sequence_number++)); |
68 end_sequence_number *= 2; // Exponential growth. | 65 end_sequence_number *= 2; // Exponential growth. |
69 } | 66 } |
70 slowStart_->StartReceiveRound(end_sequence_number); | 67 slowStart_->StartReceiveRound(end_sequence_number); |
71 | 68 |
72 for (int n = 0; n < 29 && !slowStart_->IsEndOfRound(sequence_number++); ++n) { | 69 for (int n = 0; n < 29 && !slowStart_->IsEndOfRound(sequence_number++); ++n) { |
73 clock_.AdvanceTime(one_ms_); | 70 clock_.AdvanceTime(one_ms_); |
74 EXPECT_FALSE(slowStart_->ShouldExitSlowStart(rtt_, rtt_, 100)); | 71 EXPECT_FALSE(slowStart_->ShouldExitSlowStart(rtt_, rtt_, 100)); |
75 } | 72 } |
76 clock_.AdvanceTime(one_ms_); | 73 clock_.AdvanceTime(one_ms_); |
77 EXPECT_TRUE(slowStart_->ShouldExitSlowStart(rtt_, rtt_, 100)); | 74 EXPECT_TRUE(slowStart_->ShouldExitSlowStart(rtt_, rtt_, 100)); |
(...skipping 19 matching lines...) Expand all Loading... |
97 rtt_.Add(QuicTime::Delta::FromMilliseconds(n + 5)), rtt_, 100)); | 94 rtt_.Add(QuicTime::Delta::FromMilliseconds(n + 5)), rtt_, 100)); |
98 } | 95 } |
99 // Expect to trigger since all packets in this burst was above the long term | 96 // Expect to trigger since all packets in this burst was above the long term |
100 // RTT provided. | 97 // RTT provided. |
101 EXPECT_TRUE(slowStart_->ShouldExitSlowStart( | 98 EXPECT_TRUE(slowStart_->ShouldExitSlowStart( |
102 rtt_.Add(QuicTime::Delta::FromMilliseconds(5)), rtt_, 100)); | 99 rtt_.Add(QuicTime::Delta::FromMilliseconds(5)), rtt_, 100)); |
103 } | 100 } |
104 | 101 |
105 } // namespace test | 102 } // namespace test |
106 } // namespace net | 103 } // namespace net |
OLD | NEW |