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

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

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
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() : unacked_packets_() {
21 : unacked_packets_() {
22 rtt_stats_.UpdateRtt(QuicTime::Delta::FromMilliseconds(100), 21 rtt_stats_.UpdateRtt(QuicTime::Delta::FromMilliseconds(100),
23 QuicTime::Delta::Zero(), 22 QuicTime::Delta::Zero(),
24 clock_.Now()); 23 clock_.Now());
25 } 24 }
26 25
27 void SendDataPacket(QuicPacketSequenceNumber sequence_number) { 26 void SendDataPacket(QuicPacketSequenceNumber sequence_number) {
28 SerializedPacket packet(sequence_number, PACKET_1BYTE_SEQUENCE_NUMBER, 27 SerializedPacket packet(sequence_number,
29 NULL, 0, new RetransmittableFrames()); 28 PACKET_1BYTE_SEQUENCE_NUMBER,
29 NULL,
30 0,
31 new RetransmittableFrames());
30 unacked_packets_.AddPacket(packet); 32 unacked_packets_.AddPacket(packet);
31 unacked_packets_.SetSent(sequence_number, clock_.Now(), 1000, true); 33 unacked_packets_.SetSent(sequence_number, clock_.Now(), 1000, true);
32 } 34 }
33 35
34 void VerifyLosses(QuicPacketSequenceNumber largest_observed, 36 void VerifyLosses(QuicPacketSequenceNumber largest_observed,
35 QuicPacketSequenceNumber* losses_expected, 37 QuicPacketSequenceNumber* losses_expected,
36 size_t num_losses) { 38 size_t num_losses) {
37 SequenceNumberSet lost_packets = 39 SequenceNumberSet lost_packets = loss_algorithm_.DetectLostPackets(
38 loss_algorithm_.DetectLostPackets( 40 unacked_packets_, clock_.Now(), largest_observed, rtt_stats_);
39 unacked_packets_, clock_.Now(), largest_observed, rtt_stats_);
40 EXPECT_EQ(num_losses, lost_packets.size()); 41 EXPECT_EQ(num_losses, lost_packets.size());
41 for (size_t i = 0; i < num_losses; ++i) { 42 for (size_t i = 0; i < num_losses; ++i) {
42 EXPECT_TRUE(ContainsKey(lost_packets, losses_expected[i])); 43 EXPECT_TRUE(ContainsKey(lost_packets, losses_expected[i]));
43 } 44 }
44 } 45 }
45 46
46 QuicUnackedPacketMap unacked_packets_; 47 QuicUnackedPacketMap unacked_packets_;
47 TimeLossAlgorithm loss_algorithm_; 48 TimeLossAlgorithm loss_algorithm_;
48 RttStats rtt_stats_; 49 RttStats rtt_stats_;
49 MockClock clock_; 50 MockClock clock_;
(...skipping 26 matching lines...) Expand all
76 // The packet should not be lost until 1.25 RTTs pass. 77 // The packet should not be lost until 1.25 RTTs pass.
77 unacked_packets_.NackPacket(1, 1); 78 unacked_packets_.NackPacket(1, 1);
78 unacked_packets_.SetNotPending(2); 79 unacked_packets_.SetNotPending(2);
79 VerifyLosses(2, NULL, 0); 80 VerifyLosses(2, NULL, 0);
80 // Expect the timer to be set to 0.25 RTT's in the future. 81 // Expect the timer to be set to 0.25 RTT's in the future.
81 EXPECT_EQ(rtt_stats_.SmoothedRtt().Multiply(0.25), 82 EXPECT_EQ(rtt_stats_.SmoothedRtt().Multiply(0.25),
82 loss_algorithm_.GetLossTimeout().Subtract(clock_.Now())); 83 loss_algorithm_.GetLossTimeout().Subtract(clock_.Now()));
83 unacked_packets_.NackPacket(1, 5); 84 unacked_packets_.NackPacket(1, 5);
84 VerifyLosses(2, NULL, 0); 85 VerifyLosses(2, NULL, 0);
85 clock_.AdvanceTime(rtt_stats_.SmoothedRtt().Multiply(0.25)); 86 clock_.AdvanceTime(rtt_stats_.SmoothedRtt().Multiply(0.25));
86 QuicPacketSequenceNumber lost[] = { 1 }; 87 QuicPacketSequenceNumber lost[] = {1};
87 VerifyLosses(2, lost, arraysize(lost)); 88 VerifyLosses(2, lost, arraysize(lost));
88 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); 89 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout());
89 } 90 }
90 91
91 TEST_F(TimeLossAlgorithmTest, NoLossWithoutNack) { 92 TEST_F(TimeLossAlgorithmTest, NoLossWithoutNack) {
92 const size_t kNumSentPackets = 10; 93 const size_t kNumSentPackets = 10;
93 // Transmit 10 packets at 1/10th an RTT interval. 94 // Transmit 10 packets at 1/10th an RTT interval.
94 for (size_t i = 1; i <= kNumSentPackets; ++i) { 95 for (size_t i = 1; i <= kNumSentPackets; ++i) {
95 SendDataPacket(i); 96 SendDataPacket(i);
96 clock_.AdvanceTime(rtt_stats_.SmoothedRtt().Multiply(0.1)); 97 clock_.AdvanceTime(rtt_stats_.SmoothedRtt().Multiply(0.1));
(...skipping 25 matching lines...) Expand all
122 // The packet should not be lost until 1.25 RTTs pass. 123 // The packet should not be lost until 1.25 RTTs pass.
123 for (size_t i = 1; i < kNumSentPackets; ++i) { 124 for (size_t i = 1; i < kNumSentPackets; ++i) {
124 unacked_packets_.NackPacket(i, 1); 125 unacked_packets_.NackPacket(i, 1);
125 } 126 }
126 unacked_packets_.SetNotPending(10); 127 unacked_packets_.SetNotPending(10);
127 VerifyLosses(10, NULL, 0); 128 VerifyLosses(10, NULL, 0);
128 // Expect the timer to be set to 0.25 RTT's in the future. 129 // Expect the timer to be set to 0.25 RTT's in the future.
129 EXPECT_EQ(rtt_stats_.SmoothedRtt().Multiply(0.25), 130 EXPECT_EQ(rtt_stats_.SmoothedRtt().Multiply(0.25),
130 loss_algorithm_.GetLossTimeout().Subtract(clock_.Now())); 131 loss_algorithm_.GetLossTimeout().Subtract(clock_.Now()));
131 clock_.AdvanceTime(rtt_stats_.SmoothedRtt().Multiply(0.25)); 132 clock_.AdvanceTime(rtt_stats_.SmoothedRtt().Multiply(0.25));
132 QuicPacketSequenceNumber lost[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; 133 QuicPacketSequenceNumber lost[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
133 VerifyLosses(10, lost, arraysize(lost)); 134 VerifyLosses(10, lost, arraysize(lost));
134 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); 135 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout());
135 } 136 }
136 137
137 } // namespace test 138 } // namespace test
138 } // namespace net 139 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698