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

Side by Side Diff: net/quic/quic_connection_test.cc

Issue 180783003: QUIC test cleanup to always use MockLossAlgorithm in QuicConnectionTest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "net/quic/quic_connection.h" 5 #include "net/quic/quic_connection.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 DISALLOW_COPY_AND_ASSIGN(TestConnection); 538 DISALLOW_COPY_AND_ASSIGN(TestConnection);
539 }; 539 };
540 540
541 class QuicConnectionTest : public ::testing::TestWithParam<QuicVersion> { 541 class QuicConnectionTest : public ::testing::TestWithParam<QuicVersion> {
542 protected: 542 protected:
543 QuicConnectionTest() 543 QuicConnectionTest()
544 : guid_(42), 544 : guid_(42),
545 framer_(SupportedVersions(version()), QuicTime::Zero(), false), 545 framer_(SupportedVersions(version()), QuicTime::Zero(), false),
546 creator_(guid_, &framer_, &random_generator_, false), 546 creator_(guid_, &framer_, &random_generator_, false),
547 send_algorithm_(new StrictMock<MockSendAlgorithm>), 547 send_algorithm_(new StrictMock<MockSendAlgorithm>),
548 loss_algorithm_(NULL), 548 loss_algorithm_(new MockLossAlgorithm()),
549 helper_(new TestConnectionHelper(&clock_, &random_generator_)), 549 helper_(new TestConnectionHelper(&clock_, &random_generator_)),
550 writer_(new TestPacketWriter(version())), 550 writer_(new TestPacketWriter(version())),
551 connection_(guid_, IPEndPoint(), helper_.get(), writer_.get(), 551 connection_(guid_, IPEndPoint(), helper_.get(), writer_.get(),
552 false, version()), 552 false, version()),
553 frame1_(1, false, 0, MakeIOVector(data1)), 553 frame1_(1, false, 0, MakeIOVector(data1)),
554 frame2_(1, false, 3, MakeIOVector(data2)), 554 frame2_(1, false, 3, MakeIOVector(data2)),
555 accept_packet_(true) { 555 accept_packet_(true) {
556 connection_.set_visitor(&visitor_); 556 connection_.set_visitor(&visitor_);
557 connection_.SetSendAlgorithm(send_algorithm_); 557 connection_.SetSendAlgorithm(send_algorithm_);
558 connection_.SetLossAlgorithm(loss_algorithm_);
558 framer_.set_received_entropy_calculator(&entropy_calculator_); 559 framer_.set_received_entropy_calculator(&entropy_calculator_);
559 // Simplify tests by not sending feedback unless specifically configured. 560 // Simplify tests by not sending feedback unless specifically configured.
560 SetFeedback(NULL); 561 SetFeedback(NULL);
561 EXPECT_CALL( 562 EXPECT_CALL(
562 *send_algorithm_, TimeUntilSend(_, _, _, _)).WillRepeatedly(Return( 563 *send_algorithm_, TimeUntilSend(_, _, _, _)).WillRepeatedly(Return(
563 QuicTime::Delta::Zero())); 564 QuicTime::Delta::Zero()));
564 EXPECT_CALL(*receive_algorithm_, 565 EXPECT_CALL(*receive_algorithm_,
565 RecordIncomingPacket(_, _, _)).Times(AnyNumber()); 566 RecordIncomingPacket(_, _, _)).Times(AnyNumber());
566 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 567 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
567 .Times(AnyNumber()); 568 .Times(AnyNumber());
568 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly( 569 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly(
569 Return(QuicTime::Delta::Zero())); 570 Return(QuicTime::Delta::Zero()));
570 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillRepeatedly(Return( 571 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillRepeatedly(Return(
571 QuicBandwidth::FromKBitsPerSecond(100))); 572 QuicBandwidth::FromKBitsPerSecond(100)));
572 EXPECT_CALL(*send_algorithm_, SmoothedRtt()).WillRepeatedly(Return( 573 EXPECT_CALL(*send_algorithm_, SmoothedRtt()).WillRepeatedly(Return(
573 QuicTime::Delta::FromMilliseconds(100))); 574 QuicTime::Delta::FromMilliseconds(100)));
574 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 575 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
575 .WillByDefault(Return(true)); 576 .WillByDefault(Return(true));
576 EXPECT_CALL(visitor_, HasPendingWrites()).Times(AnyNumber()); 577 EXPECT_CALL(visitor_, HasPendingWrites()).Times(AnyNumber());
577 EXPECT_CALL(visitor_, HasPendingHandshake()).Times(AnyNumber()); 578 EXPECT_CALL(visitor_, HasPendingHandshake()).Times(AnyNumber());
578 EXPECT_CALL(visitor_, OnCanWrite()).Times(AnyNumber()); 579 EXPECT_CALL(visitor_, OnCanWrite()).Times(AnyNumber());
579 }
580 580
581 void SetUpMockLossAlgorithm() {
582 loss_algorithm_ = new MockLossAlgorithm();
583 connection_.SetLossAlgorithm(loss_algorithm_);
584 EXPECT_CALL(*loss_algorithm_, GetLossTimeout()) 581 EXPECT_CALL(*loss_algorithm_, GetLossTimeout())
585 .WillRepeatedly(Return(QuicTime::Zero())); 582 .WillRepeatedly(Return(QuicTime::Zero()));
586 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 583 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
587 .WillRepeatedly(Return(SequenceNumberSet())); 584 .WillRepeatedly(Return(SequenceNumberSet()));
588 } 585 }
589 586
590 QuicVersion version() { 587 QuicVersion version() {
591 return GetParam(); 588 return GetParam();
592 } 589 }
593 590
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 } 1045 }
1049 1046
1050 TEST_P(QuicConnectionTest, TruncatedAck) { 1047 TEST_P(QuicConnectionTest, TruncatedAck) {
1051 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1048 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1052 QuicPacketSequenceNumber num_packets = 256 * 2 + 1; 1049 QuicPacketSequenceNumber num_packets = 256 * 2 + 1;
1053 for (QuicPacketSequenceNumber i = 0; i < num_packets; ++i) { 1050 for (QuicPacketSequenceNumber i = 0; i < num_packets; ++i) {
1054 SendStreamDataToPeer(3, "foo", i * 3, !kFin, NULL); 1051 SendStreamDataToPeer(3, "foo", i * 3, !kFin, NULL);
1055 } 1052 }
1056 1053
1057 QuicAckFrame frame = InitAckFrame(num_packets, 1); 1054 QuicAckFrame frame = InitAckFrame(num_packets, 1);
1055 SequenceNumberSet lost_packets;
1058 // Create an ack with 256 nacks, none adjacent to one another. 1056 // Create an ack with 256 nacks, none adjacent to one another.
1059 for (QuicPacketSequenceNumber i = 1; i <= 256; ++i) { 1057 for (QuicPacketSequenceNumber i = 1; i <= 256; ++i) {
1060 NackPacket(i * 2, &frame); 1058 NackPacket(i * 2, &frame);
1059 if (i < 256) { // Last packet is nacked, but not lost.
1060 lost_packets.insert(i * 2);
1061 }
1061 } 1062 }
1063 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
1064 .WillOnce(Return(lost_packets));
1062 EXPECT_CALL(entropy_calculator_, 1065 EXPECT_CALL(entropy_calculator_,
1063 EntropyHash(511)).WillOnce(testing::Return(0)); 1066 EntropyHash(511)).WillOnce(testing::Return(0));
1064 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); 1067 EXPECT_CALL(*send_algorithm_, UpdateRtt(_));
1065 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(256); 1068 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(256);
1066 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(255); 1069 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(255);
1067 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(255); 1070 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(255);
1068 ProcessAckPacket(&frame); 1071 ProcessAckPacket(&frame);
1069 1072
1070 QuicReceivedPacketManager* received_packet_manager = 1073 QuicReceivedPacketManager* received_packet_manager =
1071 QuicConnectionPeer::GetReceivedPacketManager(&connection_); 1074 QuicConnectionPeer::GetReceivedPacketManager(&connection_);
1072 // A truncated ack will not have the true largest observed. 1075 // A truncated ack will not have the true largest observed.
1073 EXPECT_GT(num_packets, 1076 EXPECT_GT(num_packets,
1074 received_packet_manager->peer_largest_observed_packet()); 1077 received_packet_manager->peer_largest_observed_packet());
1075 1078
1076 AckPacket(192, &frame); 1079 AckPacket(192, &frame);
1077 1080
1078 // Removing one missing packet allows us to ack 192 and one more range, but 1081 // Removing one missing packet allows us to ack 192 and one more range, but
1079 // 192 has already been declared lost, so it doesn't register as an ack. 1082 // 192 has already been declared lost, so it doesn't register as an ack.
1083 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
1084 .WillOnce(Return(SequenceNumberSet()));
1080 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); 1085 EXPECT_CALL(*send_algorithm_, UpdateRtt(_));
1081 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(1); 1086 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(1);
1082 ProcessAckPacket(&frame); 1087 ProcessAckPacket(&frame);
1083 EXPECT_EQ(num_packets, 1088 EXPECT_EQ(num_packets,
1084 received_packet_manager->peer_largest_observed_packet()); 1089 received_packet_manager->peer_largest_observed_packet());
1085 } 1090 }
1086 1091
1087 TEST_P(QuicConnectionTest, AckReceiptCausesAckSendBadEntropy) { 1092 TEST_P(QuicConnectionTest, AckReceiptCausesAckSendBadEntropy) {
1088 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1093 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1089 1094
(...skipping 29 matching lines...) Expand all
1119 ProcessPacket(1); 1124 ProcessPacket(1);
1120 // Should ack immediately, since this fills the last hole. 1125 // Should ack immediately, since this fills the last hole.
1121 EXPECT_EQ(3u, writer_->packets_write_attempts()); 1126 EXPECT_EQ(3u, writer_->packets_write_attempts());
1122 1127
1123 ProcessPacket(4); 1128 ProcessPacket(4);
1124 // Should not cause an ack. 1129 // Should not cause an ack.
1125 EXPECT_EQ(3u, writer_->packets_write_attempts()); 1130 EXPECT_EQ(3u, writer_->packets_write_attempts());
1126 } 1131 }
1127 1132
1128 TEST_P(QuicConnectionTest, AckReceiptCausesAckSend) { 1133 TEST_P(QuicConnectionTest, AckReceiptCausesAckSend) {
1129 SetUpMockLossAlgorithm();
1130 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1134 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1131 1135
1132 QuicPacketSequenceNumber original; 1136 QuicPacketSequenceNumber original;
1133 QuicByteCount packet_size; 1137 QuicByteCount packet_size;
1134 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) 1138 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _))
1135 .WillOnce(DoAll(SaveArg<1>(&original), SaveArg<2>(&packet_size), 1139 .WillOnce(DoAll(SaveArg<1>(&original), SaveArg<2>(&packet_size),
1136 Return(true))); 1140 Return(true)));
1137 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); 1141 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL);
1138 QuicAckFrame frame = InitAckFrame(original, 1); 1142 QuicAckFrame frame = InitAckFrame(original, 1);
1139 NackPacket(original, &frame); 1143 NackPacket(original, &frame);
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
1544 // Advance the time so not all the FEC packets are abandoned. 1548 // Advance the time so not all the FEC packets are abandoned.
1545 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); 1549 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1));
1546 connection_.SendStreamDataWithString(3, "foo", 6, !kFin, NULL); 1550 connection_.SendStreamDataWithString(3, "foo", 6, !kFin, NULL);
1547 1551
1548 QuicAckFrame ack_fec = InitAckFrame(5, 1); 1552 QuicAckFrame ack_fec = InitAckFrame(5, 1);
1549 // Ack all data packets, but no fec packets. 1553 // Ack all data packets, but no fec packets.
1550 NackPacket(2, &ack_fec); 1554 NackPacket(2, &ack_fec);
1551 NackPacket(4, &ack_fec); 1555 NackPacket(4, &ack_fec);
1552 1556
1553 // Lose the first FEC packet and ack the three data packets. 1557 // Lose the first FEC packet and ack the three data packets.
1558 SequenceNumberSet lost_packets;
1559 lost_packets.insert(2);
1560 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
1561 .WillOnce(Return(lost_packets));
1554 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); 1562 EXPECT_CALL(*send_algorithm_, UpdateRtt(_));
1555 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(3); 1563 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(3);
1556 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(2, _)); 1564 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(2, _));
1557 EXPECT_CALL(*send_algorithm_, OnPacketLost(2, _)); 1565 EXPECT_CALL(*send_algorithm_, OnPacketLost(2, _));
1558 ProcessAckPacket(&ack_fec); 1566 ProcessAckPacket(&ack_fec);
1559 1567
1560 clock_.AdvanceTime(DefaultRetransmissionTime().Subtract( 1568 clock_.AdvanceTime(DefaultRetransmissionTime().Subtract(
1561 QuicTime::Delta::FromMilliseconds(1))); 1569 QuicTime::Delta::FromMilliseconds(1)));
1562 1570
1563 // Abandon all packets 1571 // Abandon all packets
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1809 1817
1810 // Parse the last packet and ensure it's the two stream frames from 1818 // Parse the last packet and ensure it's the two stream frames from
1811 // two different streams. 1819 // two different streams.
1812 EXPECT_EQ(2u, writer_->frame_count()); 1820 EXPECT_EQ(2u, writer_->frame_count());
1813 EXPECT_EQ(2u, writer_->stream_frames()->size()); 1821 EXPECT_EQ(2u, writer_->stream_frames()->size());
1814 EXPECT_EQ(kStreamId3, (*writer_->stream_frames())[0].stream_id); 1822 EXPECT_EQ(kStreamId3, (*writer_->stream_frames())[0].stream_id);
1815 EXPECT_EQ(kStreamId5, (*writer_->stream_frames())[1].stream_id); 1823 EXPECT_EQ(kStreamId5, (*writer_->stream_frames())[1].stream_id);
1816 } 1824 }
1817 1825
1818 TEST_P(QuicConnectionTest, RetransmitOnNack) { 1826 TEST_P(QuicConnectionTest, RetransmitOnNack) {
1819 SetUpMockLossAlgorithm();
1820 QuicPacketSequenceNumber last_packet; 1827 QuicPacketSequenceNumber last_packet;
1821 QuicByteCount second_packet_size; 1828 QuicByteCount second_packet_size;
1822 SendStreamDataToPeer(3, "foo", 0, !kFin, &last_packet); // Packet 1 1829 SendStreamDataToPeer(3, "foo", 0, !kFin, &last_packet); // Packet 1
1823 second_packet_size = 1830 second_packet_size =
1824 SendStreamDataToPeer(3, "foos", 3, !kFin, &last_packet); // Packet 2 1831 SendStreamDataToPeer(3, "foos", 3, !kFin, &last_packet); // Packet 2
1825 SendStreamDataToPeer(3, "fooos", 7, !kFin, &last_packet); // Packet 3 1832 SendStreamDataToPeer(3, "fooos", 7, !kFin, &last_packet); // Packet 3
1826 1833
1827 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1834 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1828 1835
1829 // Don't lose a packet on an ack, and nothing is retransmitted. 1836 // Don't lose a packet on an ack, and nothing is retransmitted.
(...skipping 13 matching lines...) Expand all
1843 EXPECT_CALL(*send_algorithm_, OnPacketAcked(3, _)); 1850 EXPECT_CALL(*send_algorithm_, OnPacketAcked(3, _));
1844 EXPECT_CALL(*send_algorithm_, OnPacketLost(2, _)).Times(1); 1851 EXPECT_CALL(*send_algorithm_, OnPacketLost(2, _)).Times(1);
1845 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(2, _)).Times(1); 1852 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(2, _)).Times(1);
1846 EXPECT_CALL(*send_algorithm_, 1853 EXPECT_CALL(*send_algorithm_,
1847 OnPacketSent(_, _, second_packet_size - kQuicVersionSize, 1854 OnPacketSent(_, _, second_packet_size - kQuicVersionSize,
1848 NACK_RETRANSMISSION, _)).Times(1); 1855 NACK_RETRANSMISSION, _)).Times(1);
1849 ProcessAckPacket(&nack_two); 1856 ProcessAckPacket(&nack_two);
1850 } 1857 }
1851 1858
1852 TEST_P(QuicConnectionTest, DiscardRetransmit) { 1859 TEST_P(QuicConnectionTest, DiscardRetransmit) {
1853 SetUpMockLossAlgorithm();
1854 QuicPacketSequenceNumber last_packet; 1860 QuicPacketSequenceNumber last_packet;
1855 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 1861 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1
1856 SendStreamDataToPeer(1, "foos", 3, !kFin, &last_packet); // Packet 2 1862 SendStreamDataToPeer(1, "foos", 3, !kFin, &last_packet); // Packet 2
1857 SendStreamDataToPeer(1, "fooos", 7, !kFin, &last_packet); // Packet 3 1863 SendStreamDataToPeer(1, "fooos", 7, !kFin, &last_packet); // Packet 3
1858 1864
1859 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1865 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1860 1866
1861 // Instigate a loss with an ack. 1867 // Instigate a loss with an ack.
1862 QuicAckFrame nack_two = InitAckFrame(3, 0); 1868 QuicAckFrame nack_two = InitAckFrame(3, 0);
1863 NackPacket(2, &nack_two); 1869 NackPacket(2, &nack_two);
(...skipping 23 matching lines...) Expand all
1887 EXPECT_CALL(*send_algorithm_, 1893 EXPECT_CALL(*send_algorithm_,
1888 OnPacketSent(_, _, _, _, _)).Times(0); 1894 OnPacketSent(_, _, _, _, _)).Times(0);
1889 1895
1890 writer_->SetWritable(); 1896 writer_->SetWritable();
1891 connection_.OnCanWrite(); 1897 connection_.OnCanWrite();
1892 1898
1893 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1899 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1894 } 1900 }
1895 1901
1896 TEST_P(QuicConnectionTest, RetransmitNackedLargestObserved) { 1902 TEST_P(QuicConnectionTest, RetransmitNackedLargestObserved) {
1897 SetUpMockLossAlgorithm();
1898 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1903 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1899 QuicPacketSequenceNumber largest_observed; 1904 QuicPacketSequenceNumber largest_observed;
1900 QuicByteCount packet_size; 1905 QuicByteCount packet_size;
1901 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) 1906 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _))
1902 .WillOnce(DoAll(SaveArg<1>(&largest_observed), SaveArg<2>(&packet_size), 1907 .WillOnce(DoAll(SaveArg<1>(&largest_observed), SaveArg<2>(&packet_size),
1903 Return(true))); 1908 Return(true)));
1904 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); 1909 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL);
1905 1910
1906 QuicAckFrame frame = InitAckFrame(1, largest_observed); 1911 QuicAckFrame frame = InitAckFrame(1, largest_observed);
1907 NackPacket(largest_observed, &frame); 1912 NackPacket(largest_observed, &frame);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
2007 // attempt to write. 2012 // attempt to write.
2008 connection_.GetResumeWritesAlarm()->Set(clock_.ApproximateNow()); 2013 connection_.GetResumeWritesAlarm()->Set(clock_.ApproximateNow());
2009 connection_.GetSendAlarm()->Set(clock_.ApproximateNow()); 2014 connection_.GetSendAlarm()->Set(clock_.ApproximateNow());
2010 connection_.GetResumeWritesAlarm()->Fire(); 2015 connection_.GetResumeWritesAlarm()->Fire();
2011 connection_.GetSendAlarm()->Fire(); 2016 connection_.GetSendAlarm()->Fire();
2012 EXPECT_TRUE(writer_->IsWriteBlocked()); 2017 EXPECT_TRUE(writer_->IsWriteBlocked());
2013 EXPECT_EQ(1u, writer_->packets_write_attempts()); 2018 EXPECT_EQ(1u, writer_->packets_write_attempts());
2014 } 2019 }
2015 2020
2016 TEST_P(QuicConnectionTest, NoLimitPacketsPerNack) { 2021 TEST_P(QuicConnectionTest, NoLimitPacketsPerNack) {
2017 SetUpMockLossAlgorithm();
2018 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2022 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2019 int offset = 0; 2023 int offset = 0;
2020 // Send packets 1 to 15. 2024 // Send packets 1 to 15.
2021 for (int i = 0; i < 15; ++i) { 2025 for (int i = 0; i < 15; ++i) {
2022 SendStreamDataToPeer(1, "foo", offset, !kFin, NULL); 2026 SendStreamDataToPeer(1, "foo", offset, !kFin, NULL);
2023 offset += 3; 2027 offset += 3;
2024 } 2028 }
2025 2029
2026 // Ack 15, nack 1-14. 2030 // Ack 15, nack 1-14.
2027 SequenceNumberSet lost_packets; 2031 SequenceNumberSet lost_packets;
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
2388 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, RTO_RETRANSMISSION, _)) 2392 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, RTO_RETRANSMISSION, _))
2389 .WillOnce(DoAll(SaveArg<1>(&rto_sequence_number), Return(true))); 2393 .WillOnce(DoAll(SaveArg<1>(&rto_sequence_number), Return(true)));
2390 connection_.GetRetransmissionAlarm()->Fire(); 2394 connection_.GetRetransmissionAlarm()->Fire();
2391 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission( 2395 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission(
2392 &connection_, original_sequence_number)); 2396 &connection_, original_sequence_number));
2393 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( 2397 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission(
2394 &connection_, rto_sequence_number)); 2398 &connection_, rto_sequence_number));
2395 EXPECT_TRUE(QuicConnectionPeer::IsRetransmission( 2399 EXPECT_TRUE(QuicConnectionPeer::IsRetransmission(
2396 &connection_, rto_sequence_number)); 2400 &connection_, rto_sequence_number));
2397 // Once by explicit nack. 2401 // Once by explicit nack.
2398 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)).Times(3); 2402 SequenceNumberSet lost_packets;
2399 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(1); 2403 lost_packets.insert(rto_sequence_number);
2404 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
2405 .WillOnce(Return(lost_packets));
2406 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)).Times(1);
2407 EXPECT_CALL(*send_algorithm_, OnPacketLost(rto_sequence_number, _)).Times(1);
2400 EXPECT_CALL(*send_algorithm_, 2408 EXPECT_CALL(*send_algorithm_,
2401 OnPacketAbandoned(rto_sequence_number, _)).Times(1); 2409 OnPacketAbandoned(rto_sequence_number, _)).Times(1);
2402 QuicPacketSequenceNumber nack_sequence_number = 0; 2410 QuicPacketSequenceNumber nack_sequence_number = 0;
2403 // Ack packets might generate some other packets, which are not 2411 // Ack packets might generate some other packets, which are not
2404 // retransmissions. (More ack packets). 2412 // retransmissions. (More ack packets).
2405 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) 2413 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _))
2406 .Times(AnyNumber()); 2414 .Times(AnyNumber());
2407 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NACK_RETRANSMISSION, _)) 2415 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NACK_RETRANSMISSION, _))
2408 .WillOnce(DoAll(SaveArg<1>(&nack_sequence_number), Return(true))); 2416 .WillOnce(DoAll(SaveArg<1>(&nack_sequence_number), Return(true)));
2409 QuicAckFrame ack = InitAckFrame(rto_sequence_number, 0); 2417 QuicAckFrame ack = InitAckFrame(rto_sequence_number, 0);
2410 // Ack the retransmitted packet. 2418 // Nack the retransmitted packet.
2411 NackPacket(original_sequence_number, &ack); 2419 NackPacket(original_sequence_number, &ack);
2412 NackPacket(rto_sequence_number, &ack); 2420 NackPacket(rto_sequence_number, &ack);
2413 for (int i = 0; i < 3; i++) { 2421 ProcessAckPacket(&ack);
2414 ProcessAckPacket(&ack); 2422
2415 }
2416 ASSERT_NE(0u, nack_sequence_number); 2423 ASSERT_NE(0u, nack_sequence_number);
2417 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission( 2424 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission(
2418 &connection_, rto_sequence_number)); 2425 &connection_, rto_sequence_number));
2419 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( 2426 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission(
2420 &connection_, nack_sequence_number)); 2427 &connection_, nack_sequence_number));
2421 EXPECT_TRUE(QuicConnectionPeer::IsRetransmission( 2428 EXPECT_TRUE(QuicConnectionPeer::IsRetransmission(
2422 &connection_, nack_sequence_number)); 2429 &connection_, nack_sequence_number));
2423 } 2430 }
2424 2431
2425 TEST_P(QuicConnectionTest, SetRTOAfterWritingToSocket) { 2432 TEST_P(QuicConnectionTest, SetRTOAfterWritingToSocket) {
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
2896 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2903 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2897 ProcessPacket(1); 2904 ProcessPacket(1);
2898 connection_.SendStreamDataWithString(kCryptoStreamId, "foo", 0, !kFin, NULL); 2905 connection_.SendStreamDataWithString(kCryptoStreamId, "foo", 0, !kFin, NULL);
2899 // Check that ack is not bundled with outgoing data. 2906 // Check that ack is not bundled with outgoing data.
2900 EXPECT_EQ(1u, writer_->frame_count()); 2907 EXPECT_EQ(1u, writer_->frame_count());
2901 EXPECT_FALSE(writer_->ack()); 2908 EXPECT_FALSE(writer_->ack());
2902 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); 2909 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
2903 } 2910 }
2904 2911
2905 TEST_P(QuicConnectionTest, BundleAckWithDataOnIncomingAck) { 2912 TEST_P(QuicConnectionTest, BundleAckWithDataOnIncomingAck) {
2906 SetUpMockLossAlgorithm();
2907 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2913 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2908 connection_.SendStreamDataWithString(kStreamId3, "foo", 0, !kFin, NULL); 2914 connection_.SendStreamDataWithString(kStreamId3, "foo", 0, !kFin, NULL);
2909 connection_.SendStreamDataWithString(kStreamId3, "foo", 3, !kFin, NULL); 2915 connection_.SendStreamDataWithString(kStreamId3, "foo", 3, !kFin, NULL);
2910 // Ack the second packet, which will retransmit the first packet. 2916 // Ack the second packet, which will retransmit the first packet.
2911 QuicAckFrame ack = InitAckFrame(2, 0); 2917 QuicAckFrame ack = InitAckFrame(2, 0);
2912 NackPacket(1, &ack); 2918 NackPacket(1, &ack);
2913 SequenceNumberSet lost_packets; 2919 SequenceNumberSet lost_packets;
2914 lost_packets.insert(1); 2920 lost_packets.insert(1);
2915 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 2921 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
2916 .WillOnce(Return(lost_packets)); 2922 .WillOnce(Return(lost_packets));
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
3390 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(1); 3396 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(1);
3391 3397
3392 // Retransmit due to RTO. 3398 // Retransmit due to RTO.
3393 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10)); 3399 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10));
3394 connection_.GetRetransmissionAlarm()->Fire(); 3400 connection_.GetRetransmissionAlarm()->Fire();
3395 3401
3396 // Retransmit due to explicit nacks. 3402 // Retransmit due to explicit nacks.
3397 QuicAckFrame nack_three = InitAckFrame(4, 0); 3403 QuicAckFrame nack_three = InitAckFrame(4, 0);
3398 NackPacket(3, &nack_three); 3404 NackPacket(3, &nack_three);
3399 NackPacket(1, &nack_three); 3405 NackPacket(1, &nack_three);
3400 QuicFrame frame(&nack_three); 3406 SequenceNumberSet lost_packets;
3407 lost_packets.insert(1);
3408 lost_packets.insert(3);
3409 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
3410 .WillOnce(Return(lost_packets));
3401 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); 3411 EXPECT_CALL(*send_algorithm_, UpdateRtt(_));
3402 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(1); 3412 EXPECT_CALL(*send_algorithm_, OnPacketAcked(4, _)).Times(1);
3403 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(1); 3413 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(2);
3404 EXPECT_CALL(visitor_, OnCanWrite()).Times(4); 3414 EXPECT_CALL(visitor_, OnCanWrite()).Times(2);
3405 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3415 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3406 3416 ProcessAckPacket(&nack_three);
3407 ProcessFramePacket(frame);
3408 ProcessFramePacket(frame);
3409 ProcessFramePacket(frame);
3410 3417
3411 EXPECT_CALL(*send_algorithm_, SmoothedRtt()).WillOnce( 3418 EXPECT_CALL(*send_algorithm_, SmoothedRtt()).WillOnce(
3412 Return(QuicTime::Delta::Zero())); 3419 Return(QuicTime::Delta::Zero()));
3413 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillOnce( 3420 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillOnce(
3414 Return(QuicBandwidth::Zero())); 3421 Return(QuicBandwidth::Zero()));
3415 3422
3416 const QuicConnectionStats& stats = connection_.GetStats(); 3423 const QuicConnectionStats& stats = connection_.GetStats();
3417 EXPECT_EQ(3 * first_packet_size + 2 * second_packet_size - kQuicVersionSize, 3424 EXPECT_EQ(3 * first_packet_size + 2 * second_packet_size - kQuicVersionSize,
3418 stats.bytes_sent); 3425 stats.bytes_sent);
3419 EXPECT_EQ(5u, stats.packets_sent); 3426 EXPECT_EQ(5u, stats.packets_sent);
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
3603 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); 3610 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get());
3604 3611
3605 // Process an ACK from the server which should trigger the callback. 3612 // Process an ACK from the server which should trigger the callback.
3606 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); 3613 EXPECT_CALL(*send_algorithm_, UpdateRtt(_));
3607 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(1); 3614 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(1);
3608 QuicAckFrame frame = InitAckFrame(1, 0); 3615 QuicAckFrame frame = InitAckFrame(1, 0);
3609 ProcessAckPacket(&frame); 3616 ProcessAckPacket(&frame);
3610 } 3617 }
3611 3618
3612 TEST_P(QuicConnectionTest, AckNotifierFailToTriggerCallback) { 3619 TEST_P(QuicConnectionTest, AckNotifierFailToTriggerCallback) {
3613 SetUpMockLossAlgorithm();
3614 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3620 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3615 3621
3616 // Create a delegate which we don't expect to be called. 3622 // Create a delegate which we don't expect to be called.
3617 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); 3623 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate);
3618 EXPECT_CALL(*delegate, OnAckNotification()).Times(0); 3624 EXPECT_CALL(*delegate, OnAckNotification()).Times(0);
3619 3625
3620 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); 3626 EXPECT_CALL(*send_algorithm_, UpdateRtt(_));
3621 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(2); 3627 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(2);
3622 3628
3623 // Send some data, which will register the delegate to be notified. This will 3629 // Send some data, which will register the delegate to be notified. This will
(...skipping 11 matching lines...) Expand all
3635 SequenceNumberSet lost_packets; 3641 SequenceNumberSet lost_packets;
3636 lost_packets.insert(1); 3642 lost_packets.insert(1);
3637 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 3643 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
3638 .WillOnce(Return(lost_packets)); 3644 .WillOnce(Return(lost_packets));
3639 EXPECT_CALL(*send_algorithm_, OnPacketLost(1, _)); 3645 EXPECT_CALL(*send_algorithm_, OnPacketLost(1, _));
3640 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(1, _)); 3646 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(1, _));
3641 ProcessAckPacket(&frame); 3647 ProcessAckPacket(&frame);
3642 } 3648 }
3643 3649
3644 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) { 3650 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) {
3645 SetUpMockLossAlgorithm();
3646 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3651 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3647 3652
3648 // Create a delegate which we expect to be called. 3653 // Create a delegate which we expect to be called.
3649 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); 3654 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate);
3650 EXPECT_CALL(*delegate, OnAckNotification()).Times(1); 3655 EXPECT_CALL(*delegate, OnAckNotification()).Times(1);
3651 3656
3652 // Send four packets, and register to be notified on ACK of packet 2. 3657 // Send four packets, and register to be notified on ACK of packet 2.
3653 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); 3658 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL);
3654 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, delegate.get()); 3659 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, delegate.get());
3655 connection_.SendStreamDataWithString(3, "baz", 0, !kFin, NULL); 3660 connection_.SendStreamDataWithString(3, "baz", 0, !kFin, NULL);
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
3825 QuicBlockedFrame blocked; 3830 QuicBlockedFrame blocked;
3826 blocked.stream_id = 3; 3831 blocked.stream_id = 3;
3827 EXPECT_CALL(visitor_, OnBlockedFrames(_)); 3832 EXPECT_CALL(visitor_, OnBlockedFrames(_));
3828 ProcessFramePacket(QuicFrame(&blocked)); 3833 ProcessFramePacket(QuicFrame(&blocked));
3829 EXPECT_TRUE(ack_alarm->IsSet()); 3834 EXPECT_TRUE(ack_alarm->IsSet());
3830 } 3835 }
3831 3836
3832 } // namespace 3837 } // namespace
3833 } // namespace test 3838 } // namespace test
3834 } // namespace net 3839 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698