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

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

Issue 992733002: Remove //net (except for Android test stuff) and sdch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <algorithm>
6
7 #include "base/logging.h"
8 #include "base/stl_util.h"
9 #include "net/quic/congestion_control/rtt_stats.h"
10 #include "net/quic/congestion_control/time_loss_algorithm.h"
11 #include "net/quic/quic_unacked_packet_map.h"
12 #include "net/quic/test_tools/mock_clock.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 using std::vector;
16
17 namespace net {
18 namespace test {
19 namespace {
20
21 // Default packet length.
22 const uint32 kDefaultLength = 1000;
23
24 class TimeLossAlgorithmTest : public ::testing::Test {
25 protected:
26 TimeLossAlgorithmTest()
27 : unacked_packets_() {
28 rtt_stats_.UpdateRtt(QuicTime::Delta::FromMilliseconds(100),
29 QuicTime::Delta::Zero(),
30 clock_.Now());
31 }
32
33 ~TimeLossAlgorithmTest() override {
34 STLDeleteElements(&packets_);
35 }
36
37 void SendDataPacket(QuicPacketSequenceNumber sequence_number) {
38 packets_.push_back(new QuicEncryptedPacket(nullptr, kDefaultLength));
39 SerializedPacket packet(sequence_number, PACKET_1BYTE_SEQUENCE_NUMBER,
40 packets_.back(), 0, new RetransmittableFrames());
41 unacked_packets_.AddSentPacket(packet, 0, NOT_RETRANSMISSION, clock_.Now(),
42 1000, true);
43 }
44
45 void VerifyLosses(QuicPacketSequenceNumber largest_observed,
46 QuicPacketSequenceNumber* losses_expected,
47 size_t num_losses) {
48 SequenceNumberSet lost_packets =
49 loss_algorithm_.DetectLostPackets(
50 unacked_packets_, clock_.Now(), largest_observed, rtt_stats_);
51 EXPECT_EQ(num_losses, lost_packets.size());
52 for (size_t i = 0; i < num_losses; ++i) {
53 EXPECT_TRUE(ContainsKey(lost_packets, losses_expected[i]));
54 }
55 }
56
57 vector<QuicEncryptedPacket*> packets_;
58 QuicUnackedPacketMap unacked_packets_;
59 TimeLossAlgorithm loss_algorithm_;
60 RttStats rtt_stats_;
61 MockClock clock_;
62 };
63
64 TEST_F(TimeLossAlgorithmTest, NoLossFor500Nacks) {
65 const size_t kNumSentPackets = 5;
66 // Transmit 5 packets.
67 for (size_t i = 1; i <= kNumSentPackets; ++i) {
68 SendDataPacket(i);
69 }
70 unacked_packets_.RemoveFromInFlight(2);
71 for (size_t i = 1; i < 500; ++i) {
72 unacked_packets_.NackPacket(1, i);
73 VerifyLosses(2, nullptr, 0);
74 }
75 EXPECT_EQ(rtt_stats_.smoothed_rtt().Multiply(1.25),
76 loss_algorithm_.GetLossTimeout().Subtract(clock_.Now()));
77 }
78
79 TEST_F(TimeLossAlgorithmTest, NoLossUntilTimeout) {
80 const size_t kNumSentPackets = 10;
81 // Transmit 10 packets at 1/10th an RTT interval.
82 for (size_t i = 1; i <= kNumSentPackets; ++i) {
83 SendDataPacket(i);
84 clock_.AdvanceTime(rtt_stats_.smoothed_rtt().Multiply(0.1));
85 }
86 // Expect the timer to not be set.
87 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout());
88 // The packet should not be lost until 1.25 RTTs pass.
89 unacked_packets_.NackPacket(1, 1);
90 unacked_packets_.RemoveFromInFlight(2);
91 VerifyLosses(2, nullptr, 0);
92 // Expect the timer to be set to 0.25 RTT's in the future.
93 EXPECT_EQ(rtt_stats_.smoothed_rtt().Multiply(0.25),
94 loss_algorithm_.GetLossTimeout().Subtract(clock_.Now()));
95 unacked_packets_.NackPacket(1, 5);
96 VerifyLosses(2, nullptr, 0);
97 clock_.AdvanceTime(rtt_stats_.smoothed_rtt().Multiply(0.25));
98 QuicPacketSequenceNumber lost[] = { 1 };
99 VerifyLosses(2, lost, arraysize(lost));
100 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout());
101 }
102
103 TEST_F(TimeLossAlgorithmTest, NoLossWithoutNack) {
104 const size_t kNumSentPackets = 10;
105 // Transmit 10 packets at 1/10th an RTT interval.
106 for (size_t i = 1; i <= kNumSentPackets; ++i) {
107 SendDataPacket(i);
108 clock_.AdvanceTime(rtt_stats_.smoothed_rtt().Multiply(0.1));
109 }
110 // Expect the timer to not be set.
111 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout());
112 // The packet should not be lost without a nack.
113 unacked_packets_.RemoveFromInFlight(1);
114 VerifyLosses(1, nullptr, 0);
115 // The timer should still not be set.
116 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout());
117 clock_.AdvanceTime(rtt_stats_.smoothed_rtt().Multiply(0.25));
118 VerifyLosses(1, nullptr, 0);
119 clock_.AdvanceTime(rtt_stats_.smoothed_rtt());
120 VerifyLosses(1, nullptr, 0);
121
122 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout());
123 }
124
125 TEST_F(TimeLossAlgorithmTest, MultipleLossesAtOnce) {
126 const size_t kNumSentPackets = 10;
127 // Transmit 10 packets at once and then go forward an RTT.
128 for (size_t i = 1; i <= kNumSentPackets; ++i) {
129 SendDataPacket(i);
130 }
131 clock_.AdvanceTime(rtt_stats_.smoothed_rtt());
132 // Expect the timer to not be set.
133 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout());
134 // The packet should not be lost until 1.25 RTTs pass.
135 for (size_t i = 1; i < kNumSentPackets; ++i) {
136 unacked_packets_.NackPacket(i, 1);
137 }
138 unacked_packets_.RemoveFromInFlight(10);
139 VerifyLosses(10, nullptr, 0);
140 // Expect the timer to be set to 0.25 RTT's in the future.
141 EXPECT_EQ(rtt_stats_.smoothed_rtt().Multiply(0.25),
142 loss_algorithm_.GetLossTimeout().Subtract(clock_.Now()));
143 clock_.AdvanceTime(rtt_stats_.smoothed_rtt().Multiply(0.25));
144 QuicPacketSequenceNumber lost[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
145 VerifyLosses(10, lost, arraysize(lost));
146 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout());
147 }
148
149 } // namespace
150 } // namespace test
151 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/congestion_control/time_loss_algorithm.cc ('k') | net/quic/crypto/aead_base_decrypter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698