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

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

Issue 754433003: Update from https://crrev.com/305340 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « net/quic/congestion_control/time_loss_algorithm.cc ('k') | net/quic/crypto/common_cert_set.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 using std::vector;
16
15 namespace net { 17 namespace net {
16 namespace test { 18 namespace test {
19 namespace {
20
21 // Default packet length.
22 const uint32 kDefaultLength = 1000;
17 23
18 class TimeLossAlgorithmTest : public ::testing::Test { 24 class TimeLossAlgorithmTest : public ::testing::Test {
19 protected: 25 protected:
20 TimeLossAlgorithmTest() 26 TimeLossAlgorithmTest()
21 : unacked_packets_() { 27 : unacked_packets_() {
22 rtt_stats_.UpdateRtt(QuicTime::Delta::FromMilliseconds(100), 28 rtt_stats_.UpdateRtt(QuicTime::Delta::FromMilliseconds(100),
23 QuicTime::Delta::Zero(), 29 QuicTime::Delta::Zero(),
24 clock_.Now()); 30 clock_.Now());
25 } 31 }
26 32
33 ~TimeLossAlgorithmTest() override {
34 STLDeleteElements(&packets_);
35 }
36
27 void SendDataPacket(QuicPacketSequenceNumber sequence_number) { 37 void SendDataPacket(QuicPacketSequenceNumber sequence_number) {
38 packets_.push_back(QuicPacket::NewDataPacket(
39 nullptr, kDefaultLength, false, PACKET_8BYTE_CONNECTION_ID, false,
40 PACKET_1BYTE_SEQUENCE_NUMBER));
28 SerializedPacket packet(sequence_number, PACKET_1BYTE_SEQUENCE_NUMBER, 41 SerializedPacket packet(sequence_number, PACKET_1BYTE_SEQUENCE_NUMBER,
29 nullptr, 0, new RetransmittableFrames()); 42 packets_.back(), 0, new RetransmittableFrames());
30 unacked_packets_.AddSentPacket(packet, 0, NOT_RETRANSMISSION, clock_.Now(), 43 unacked_packets_.AddSentPacket(packet, 0, NOT_RETRANSMISSION, clock_.Now(),
31 1000, true); 44 1000, true);
32 } 45 }
33 46
34 void VerifyLosses(QuicPacketSequenceNumber largest_observed, 47 void VerifyLosses(QuicPacketSequenceNumber largest_observed,
35 QuicPacketSequenceNumber* losses_expected, 48 QuicPacketSequenceNumber* losses_expected,
36 size_t num_losses) { 49 size_t num_losses) {
37 SequenceNumberSet lost_packets = 50 SequenceNumberSet lost_packets =
38 loss_algorithm_.DetectLostPackets( 51 loss_algorithm_.DetectLostPackets(
39 unacked_packets_, clock_.Now(), largest_observed, rtt_stats_); 52 unacked_packets_, clock_.Now(), largest_observed, rtt_stats_);
40 EXPECT_EQ(num_losses, lost_packets.size()); 53 EXPECT_EQ(num_losses, lost_packets.size());
41 for (size_t i = 0; i < num_losses; ++i) { 54 for (size_t i = 0; i < num_losses; ++i) {
42 EXPECT_TRUE(ContainsKey(lost_packets, losses_expected[i])); 55 EXPECT_TRUE(ContainsKey(lost_packets, losses_expected[i]));
43 } 56 }
44 } 57 }
45 58
59 vector<QuicPacket*> packets_;
46 QuicUnackedPacketMap unacked_packets_; 60 QuicUnackedPacketMap unacked_packets_;
47 TimeLossAlgorithm loss_algorithm_; 61 TimeLossAlgorithm loss_algorithm_;
48 RttStats rtt_stats_; 62 RttStats rtt_stats_;
49 MockClock clock_; 63 MockClock clock_;
50 }; 64 };
51 65
52 TEST_F(TimeLossAlgorithmTest, NoLossFor500Nacks) { 66 TEST_F(TimeLossAlgorithmTest, NoLossFor500Nacks) {
53 const size_t kNumSentPackets = 5; 67 const size_t kNumSentPackets = 5;
54 // Transmit 5 packets. 68 // Transmit 5 packets.
55 for (size_t i = 1; i <= kNumSentPackets; ++i) { 69 for (size_t i = 1; i <= kNumSentPackets; ++i) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 VerifyLosses(10, nullptr, 0); 141 VerifyLosses(10, nullptr, 0);
128 // Expect the timer to be set to 0.25 RTT's in the future. 142 // Expect the timer to be set to 0.25 RTT's in the future.
129 EXPECT_EQ(rtt_stats_.smoothed_rtt().Multiply(0.25), 143 EXPECT_EQ(rtt_stats_.smoothed_rtt().Multiply(0.25),
130 loss_algorithm_.GetLossTimeout().Subtract(clock_.Now())); 144 loss_algorithm_.GetLossTimeout().Subtract(clock_.Now()));
131 clock_.AdvanceTime(rtt_stats_.smoothed_rtt().Multiply(0.25)); 145 clock_.AdvanceTime(rtt_stats_.smoothed_rtt().Multiply(0.25));
132 QuicPacketSequenceNumber lost[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; 146 QuicPacketSequenceNumber lost[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
133 VerifyLosses(10, lost, arraysize(lost)); 147 VerifyLosses(10, lost, arraysize(lost));
134 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); 148 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout());
135 } 149 }
136 150
151 } // namespace
137 } // namespace test 152 } // namespace test
138 } // namespace net 153 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/congestion_control/time_loss_algorithm.cc ('k') | net/quic/crypto/common_cert_set.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698