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

Side by Side Diff: net/quic/congestion_control/time_loss_algorithm_test.cc

Issue 612323013: QUIC - (no behavior change) s/NULL/nullptr/g in .../quic/... (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "net/quic/congestion_control/rtt_stats.h" 9 #include "net/quic/congestion_control/rtt_stats.h"
10 #include "net/quic/congestion_control/time_loss_algorithm.h" 10 #include "net/quic/congestion_control/time_loss_algorithm.h"
11 #include "net/quic/quic_unacked_packet_map.h" 11 #include "net/quic/quic_unacked_packet_map.h"
12 #include "net/quic/test_tools/mock_clock.h" 12 #include "net/quic/test_tools/mock_clock.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace net { 15 namespace net {
16 namespace test { 16 namespace test {
17 17
18 class TimeLossAlgorithmTest : public ::testing::Test { 18 class TimeLossAlgorithmTest : public ::testing::Test {
19 protected: 19 protected:
20 TimeLossAlgorithmTest() 20 TimeLossAlgorithmTest()
21 : unacked_packets_() { 21 : unacked_packets_() {
22 rtt_stats_.UpdateRtt(QuicTime::Delta::FromMilliseconds(100), 22 rtt_stats_.UpdateRtt(QuicTime::Delta::FromMilliseconds(100),
23 QuicTime::Delta::Zero(), 23 QuicTime::Delta::Zero(),
24 clock_.Now()); 24 clock_.Now());
25 } 25 }
26 26
27 void SendDataPacket(QuicPacketSequenceNumber sequence_number) { 27 void SendDataPacket(QuicPacketSequenceNumber sequence_number) {
28 SerializedPacket packet(sequence_number, PACKET_1BYTE_SEQUENCE_NUMBER, 28 SerializedPacket packet(sequence_number, PACKET_1BYTE_SEQUENCE_NUMBER,
29 NULL, 0, new RetransmittableFrames()); 29 nullptr, 0, new RetransmittableFrames());
30 unacked_packets_.AddPacket(packet); 30 unacked_packets_.AddPacket(packet);
31 unacked_packets_.SetSent(sequence_number, clock_.Now(), 1000, true); 31 unacked_packets_.SetSent(sequence_number, clock_.Now(), 1000, true);
32 } 32 }
33 33
34 void VerifyLosses(QuicPacketSequenceNumber largest_observed, 34 void VerifyLosses(QuicPacketSequenceNumber largest_observed,
35 QuicPacketSequenceNumber* losses_expected, 35 QuicPacketSequenceNumber* losses_expected,
36 size_t num_losses) { 36 size_t num_losses) {
37 SequenceNumberSet lost_packets = 37 SequenceNumberSet lost_packets =
38 loss_algorithm_.DetectLostPackets( 38 loss_algorithm_.DetectLostPackets(
39 unacked_packets_, clock_.Now(), largest_observed, rtt_stats_); 39 unacked_packets_, clock_.Now(), largest_observed, rtt_stats_);
(...skipping 11 matching lines...) Expand all
51 51
52 TEST_F(TimeLossAlgorithmTest, NoLossFor500Nacks) { 52 TEST_F(TimeLossAlgorithmTest, NoLossFor500Nacks) {
53 const size_t kNumSentPackets = 5; 53 const size_t kNumSentPackets = 5;
54 // Transmit 5 packets. 54 // Transmit 5 packets.
55 for (size_t i = 1; i <= kNumSentPackets; ++i) { 55 for (size_t i = 1; i <= kNumSentPackets; ++i) {
56 SendDataPacket(i); 56 SendDataPacket(i);
57 } 57 }
58 unacked_packets_.RemoveFromInFlight(2); 58 unacked_packets_.RemoveFromInFlight(2);
59 for (size_t i = 1; i < 500; ++i) { 59 for (size_t i = 1; i < 500; ++i) {
60 unacked_packets_.NackPacket(1, i); 60 unacked_packets_.NackPacket(1, i);
61 VerifyLosses(2, NULL, 0); 61 VerifyLosses(2, nullptr, 0);
62 } 62 }
63 EXPECT_EQ(rtt_stats_.SmoothedRtt().Multiply(1.25), 63 EXPECT_EQ(rtt_stats_.SmoothedRtt().Multiply(1.25),
64 loss_algorithm_.GetLossTimeout().Subtract(clock_.Now())); 64 loss_algorithm_.GetLossTimeout().Subtract(clock_.Now()));
65 } 65 }
66 66
67 TEST_F(TimeLossAlgorithmTest, NoLossUntilTimeout) { 67 TEST_F(TimeLossAlgorithmTest, NoLossUntilTimeout) {
68 const size_t kNumSentPackets = 10; 68 const size_t kNumSentPackets = 10;
69 // Transmit 10 packets at 1/10th an RTT interval. 69 // Transmit 10 packets at 1/10th an RTT interval.
70 for (size_t i = 1; i <= kNumSentPackets; ++i) { 70 for (size_t i = 1; i <= kNumSentPackets; ++i) {
71 SendDataPacket(i); 71 SendDataPacket(i);
72 clock_.AdvanceTime(rtt_stats_.SmoothedRtt().Multiply(0.1)); 72 clock_.AdvanceTime(rtt_stats_.SmoothedRtt().Multiply(0.1));
73 } 73 }
74 // Expect the timer to not be set. 74 // Expect the timer to not be set.
75 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); 75 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout());
76 // The packet should not be lost until 1.25 RTTs pass. 76 // The packet should not be lost until 1.25 RTTs pass.
77 unacked_packets_.NackPacket(1, 1); 77 unacked_packets_.NackPacket(1, 1);
78 unacked_packets_.RemoveFromInFlight(2); 78 unacked_packets_.RemoveFromInFlight(2);
79 VerifyLosses(2, NULL, 0); 79 VerifyLosses(2, nullptr, 0);
80 // Expect the timer to be set to 0.25 RTT's in the future. 80 // Expect the timer to be set to 0.25 RTT's in the future.
81 EXPECT_EQ(rtt_stats_.SmoothedRtt().Multiply(0.25), 81 EXPECT_EQ(rtt_stats_.SmoothedRtt().Multiply(0.25),
82 loss_algorithm_.GetLossTimeout().Subtract(clock_.Now())); 82 loss_algorithm_.GetLossTimeout().Subtract(clock_.Now()));
83 unacked_packets_.NackPacket(1, 5); 83 unacked_packets_.NackPacket(1, 5);
84 VerifyLosses(2, NULL, 0); 84 VerifyLosses(2, nullptr, 0);
85 clock_.AdvanceTime(rtt_stats_.SmoothedRtt().Multiply(0.25)); 85 clock_.AdvanceTime(rtt_stats_.SmoothedRtt().Multiply(0.25));
86 QuicPacketSequenceNumber lost[] = { 1 }; 86 QuicPacketSequenceNumber lost[] = { 1 };
87 VerifyLosses(2, lost, arraysize(lost)); 87 VerifyLosses(2, lost, arraysize(lost));
88 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); 88 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout());
89 } 89 }
90 90
91 TEST_F(TimeLossAlgorithmTest, NoLossWithoutNack) { 91 TEST_F(TimeLossAlgorithmTest, NoLossWithoutNack) {
92 const size_t kNumSentPackets = 10; 92 const size_t kNumSentPackets = 10;
93 // Transmit 10 packets at 1/10th an RTT interval. 93 // Transmit 10 packets at 1/10th an RTT interval.
94 for (size_t i = 1; i <= kNumSentPackets; ++i) { 94 for (size_t i = 1; i <= kNumSentPackets; ++i) {
95 SendDataPacket(i); 95 SendDataPacket(i);
96 clock_.AdvanceTime(rtt_stats_.SmoothedRtt().Multiply(0.1)); 96 clock_.AdvanceTime(rtt_stats_.SmoothedRtt().Multiply(0.1));
97 } 97 }
98 // Expect the timer to not be set. 98 // Expect the timer to not be set.
99 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); 99 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout());
100 // The packet should not be lost without a nack. 100 // The packet should not be lost without a nack.
101 unacked_packets_.RemoveFromInFlight(1); 101 unacked_packets_.RemoveFromInFlight(1);
102 VerifyLosses(1, NULL, 0); 102 VerifyLosses(1, nullptr, 0);
103 // The timer should still not be set. 103 // The timer should still not be set.
104 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); 104 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout());
105 clock_.AdvanceTime(rtt_stats_.SmoothedRtt().Multiply(0.25)); 105 clock_.AdvanceTime(rtt_stats_.SmoothedRtt().Multiply(0.25));
106 VerifyLosses(1, NULL, 0); 106 VerifyLosses(1, nullptr, 0);
107 clock_.AdvanceTime(rtt_stats_.SmoothedRtt()); 107 clock_.AdvanceTime(rtt_stats_.SmoothedRtt());
108 VerifyLosses(1, NULL, 0); 108 VerifyLosses(1, nullptr, 0);
109 109
110 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); 110 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout());
111 } 111 }
112 112
113 TEST_F(TimeLossAlgorithmTest, MultipleLossesAtOnce) { 113 TEST_F(TimeLossAlgorithmTest, MultipleLossesAtOnce) {
114 const size_t kNumSentPackets = 10; 114 const size_t kNumSentPackets = 10;
115 // Transmit 10 packets at once and then go forward an RTT. 115 // Transmit 10 packets at once and then go forward an RTT.
116 for (size_t i = 1; i <= kNumSentPackets; ++i) { 116 for (size_t i = 1; i <= kNumSentPackets; ++i) {
117 SendDataPacket(i); 117 SendDataPacket(i);
118 } 118 }
119 clock_.AdvanceTime(rtt_stats_.SmoothedRtt()); 119 clock_.AdvanceTime(rtt_stats_.SmoothedRtt());
120 // Expect the timer to not be set. 120 // Expect the timer to not be set.
121 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); 121 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout());
122 // The packet should not be lost until 1.25 RTTs pass. 122 // The packet should not be lost until 1.25 RTTs pass.
123 for (size_t i = 1; i < kNumSentPackets; ++i) { 123 for (size_t i = 1; i < kNumSentPackets; ++i) {
124 unacked_packets_.NackPacket(i, 1); 124 unacked_packets_.NackPacket(i, 1);
125 } 125 }
126 unacked_packets_.RemoveFromInFlight(10); 126 unacked_packets_.RemoveFromInFlight(10);
127 VerifyLosses(10, NULL, 0); 127 VerifyLosses(10, nullptr, 0);
128 // Expect the timer to be set to 0.25 RTT's in the future. 128 // Expect the timer to be set to 0.25 RTT's in the future.
129 EXPECT_EQ(rtt_stats_.SmoothedRtt().Multiply(0.25), 129 EXPECT_EQ(rtt_stats_.SmoothedRtt().Multiply(0.25),
130 loss_algorithm_.GetLossTimeout().Subtract(clock_.Now())); 130 loss_algorithm_.GetLossTimeout().Subtract(clock_.Now()));
131 clock_.AdvanceTime(rtt_stats_.SmoothedRtt().Multiply(0.25)); 131 clock_.AdvanceTime(rtt_stats_.SmoothedRtt().Multiply(0.25));
132 QuicPacketSequenceNumber lost[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; 132 QuicPacketSequenceNumber lost[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
133 VerifyLosses(10, lost, arraysize(lost)); 133 VerifyLosses(10, lost, arraysize(lost));
134 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); 134 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout());
135 } 135 }
136 136
137 } // namespace test 137 } // namespace test
138 } // namespace net 138 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/congestion_control/tcp_loss_algorithm_test.cc ('k') | net/quic/crypto/aead_base_decrypter_nss.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698