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

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

Issue 497553004: Landing Recent QUIC Changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase with TOT Created 6 years, 4 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
« no previous file with comments | « net/quic/quic_connection.cc ('k') | net/quic/quic_crypto_server_stream.h » ('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 (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 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 EXPECT_CALL(*receive_algorithm_, 642 EXPECT_CALL(*receive_algorithm_,
643 RecordIncomingPacket(_, _, _)).Times(AnyNumber()); 643 RecordIncomingPacket(_, _, _)).Times(AnyNumber());
644 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 644 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
645 .Times(AnyNumber()); 645 .Times(AnyNumber());
646 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly( 646 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly(
647 Return(QuicTime::Delta::Zero())); 647 Return(QuicTime::Delta::Zero()));
648 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( 648 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly(
649 Return(kMaxPacketSize)); 649 Return(kMaxPacketSize));
650 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 650 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
651 .WillByDefault(Return(true)); 651 .WillByDefault(Return(true));
652 EXPECT_CALL(*send_algorithm_, HasReliableBandwidthEstimate())
653 .Times(AnyNumber());
654 EXPECT_CALL(*send_algorithm_, BandwidthEstimate())
655 .Times(AnyNumber())
656 .WillRepeatedly(Return(QuicBandwidth::Zero()));
657 EXPECT_CALL(*send_algorithm_, InSlowStart()).Times(AnyNumber());
658 EXPECT_CALL(*send_algorithm_, InRecovery()).Times(AnyNumber());
652 EXPECT_CALL(visitor_, WillingAndAbleToWrite()).Times(AnyNumber()); 659 EXPECT_CALL(visitor_, WillingAndAbleToWrite()).Times(AnyNumber());
653 EXPECT_CALL(visitor_, HasPendingHandshake()).Times(AnyNumber()); 660 EXPECT_CALL(visitor_, HasPendingHandshake()).Times(AnyNumber());
654 EXPECT_CALL(visitor_, OnCanWrite()).Times(AnyNumber()); 661 EXPECT_CALL(visitor_, OnCanWrite()).Times(AnyNumber());
655 EXPECT_CALL(visitor_, HasOpenDataStreams()).WillRepeatedly(Return(false)); 662 EXPECT_CALL(visitor_, HasOpenDataStreams()).WillRepeatedly(Return(false));
663 EXPECT_CALL(visitor_, OnCongestionWindowChange(_)).Times(AnyNumber());
656 664
657 EXPECT_CALL(*loss_algorithm_, GetLossTimeout()) 665 EXPECT_CALL(*loss_algorithm_, GetLossTimeout())
658 .WillRepeatedly(Return(QuicTime::Zero())); 666 .WillRepeatedly(Return(QuicTime::Zero()));
659 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 667 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
660 .WillRepeatedly(Return(SequenceNumberSet())); 668 .WillRepeatedly(Return(SequenceNumberSet()));
661 } 669 }
662 670
663 QuicVersion version() { 671 QuicVersion version() {
664 return GetParam(); 672 return GetParam();
665 } 673 }
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
1118 lost_packets.insert(i * 2); 1126 lost_packets.insert(i * 2);
1119 } 1127 }
1120 } 1128 }
1121 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 1129 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
1122 .WillOnce(Return(lost_packets)); 1130 .WillOnce(Return(lost_packets));
1123 EXPECT_CALL(entropy_calculator_, 1131 EXPECT_CALL(entropy_calculator_,
1124 EntropyHash(511)).WillOnce(testing::Return(0)); 1132 EntropyHash(511)).WillOnce(testing::Return(0));
1125 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 1133 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
1126 ProcessAckPacket(&frame); 1134 ProcessAckPacket(&frame);
1127 1135
1128 QuicReceivedPacketManager* received_packet_manager = 1136 const QuicSentPacketManager& sent_packet_manager =
1129 QuicConnectionPeer::GetReceivedPacketManager(&connection_); 1137 connection_.sent_packet_manager();
1130 // A truncated ack will not have the true largest observed. 1138 // A truncated ack will not have the true largest observed.
1131 EXPECT_GT(num_packets, 1139 EXPECT_GT(num_packets, sent_packet_manager.largest_observed());
1132 received_packet_manager->peer_largest_observed_packet());
1133 1140
1134 AckPacket(192, &frame); 1141 AckPacket(192, &frame);
1135 1142
1136 // Removing one missing packet allows us to ack 192 and one more range, but 1143 // Removing one missing packet allows us to ack 192 and one more range, but
1137 // 192 has already been declared lost, so it doesn't register as an ack. 1144 // 192 has already been declared lost, so it doesn't register as an ack.
1138 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 1145 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
1139 .WillOnce(Return(SequenceNumberSet())); 1146 .WillOnce(Return(SequenceNumberSet()));
1140 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 1147 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
1141 ProcessAckPacket(&frame); 1148 ProcessAckPacket(&frame);
1142 EXPECT_EQ(num_packets, 1149 EXPECT_EQ(num_packets, sent_packet_manager.largest_observed());
1143 received_packet_manager->peer_largest_observed_packet());
1144 } 1150 }
1145 1151
1146 TEST_P(QuicConnectionTest, AckReceiptCausesAckSendBadEntropy) { 1152 TEST_P(QuicConnectionTest, AckReceiptCausesAckSendBadEntropy) {
1147 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1153 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1148 1154
1149 ProcessPacket(1); 1155 ProcessPacket(1);
1150 // Delay sending, then queue up an ack. 1156 // Delay sending, then queue up an ack.
1151 EXPECT_CALL(*send_algorithm_, 1157 EXPECT_CALL(*send_algorithm_,
1152 TimeUntilSend(_, _, _)).WillOnce( 1158 TimeUntilSend(_, _, _)).WillOnce(
1153 testing::Return(QuicTime::Delta::FromMicroseconds(1))); 1159 testing::Return(QuicTime::Delta::FromMicroseconds(1)));
(...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after
1925 // Retransmit already retransmitted packets event though the sequence number 1931 // Retransmit already retransmitted packets event though the sequence number
1926 // greater than the largest observed. 1932 // greater than the largest observed.
1927 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(10); 1933 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(10);
1928 connection_.GetRetransmissionAlarm()->Fire(); 1934 connection_.GetRetransmissionAlarm()->Fire();
1929 connection_.OnCanWrite(); 1935 connection_.OnCanWrite();
1930 } 1936 }
1931 1937
1932 TEST_P(QuicConnectionTest, WriteBlockedThenSent) { 1938 TEST_P(QuicConnectionTest, WriteBlockedThenSent) {
1933 BlockOnNextWrite(); 1939 BlockOnNextWrite();
1934 writer_->set_is_write_blocked_data_buffered(true); 1940 writer_->set_is_write_blocked_data_buffered(true);
1941 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
1935 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); 1942 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL);
1936 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 1943 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
1937 1944
1938 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 1945 writer_->SetWritable();
1939 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); 1946 connection_.OnCanWrite();
1940 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 1947 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
1941 } 1948 }
1942 1949
1943 TEST_P(QuicConnectionTest, WriteBlockedAckedThenSent) {
1944 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1945 BlockOnNextWrite();
1946 writer_->set_is_write_blocked_data_buffered(true);
1947 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL);
1948 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
1949
1950 // Ack the sent packet before the callback returns, which happens in
1951 // rare circumstances with write blocked sockets.
1952 QuicAckFrame ack = InitAckFrame(1);
1953 ProcessAckPacket(&ack);
1954
1955 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0);
1956 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0));
1957 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
1958 }
1959
1960 TEST_P(QuicConnectionTest, RetransmitWriteBlockedAckedOriginalThenSent) { 1950 TEST_P(QuicConnectionTest, RetransmitWriteBlockedAckedOriginalThenSent) {
1961 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1951 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1962 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); 1952 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL);
1963 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 1953 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
1964 1954
1965 BlockOnNextWrite(); 1955 BlockOnNextWrite();
1966 writer_->set_is_write_blocked_data_buffered(true); 1956 writer_->set_is_write_blocked_data_buffered(true);
1967 // Simulate the retransmission alarm firing. 1957 // Simulate the retransmission alarm firing.
1968 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(_)); 1958 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(_));
1969 clock_.AdvanceTime(DefaultRetransmissionTime()); 1959 clock_.AdvanceTime(DefaultRetransmissionTime());
1970 connection_.GetRetransmissionAlarm()->Fire(); 1960 connection_.GetRetransmissionAlarm()->Fire();
1971 1961
1972 // Ack the sent packet before the callback returns, which happens in 1962 // Ack the sent packet before the callback returns, which happens in
1973 // rare circumstances with write blocked sockets. 1963 // rare circumstances with write blocked sockets.
1974 QuicAckFrame ack = InitAckFrame(1); 1964 QuicAckFrame ack = InitAckFrame(1);
1975 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 1965 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
1976 EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout()); 1966 EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout());
1977 ProcessAckPacket(&ack); 1967 ProcessAckPacket(&ack);
1978 1968
1979 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); 1969 writer_->SetWritable();
1970 connection_.OnCanWrite();
1980 // There is now a pending packet, but with no retransmittable frames. 1971 // There is now a pending packet, but with no retransmittable frames.
1981 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 1972 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
1982 EXPECT_FALSE(connection_.sent_packet_manager().HasRetransmittableFrames(2)); 1973 EXPECT_FALSE(connection_.sent_packet_manager().HasRetransmittableFrames(2));
1983 } 1974 }
1984 1975
1985 TEST_P(QuicConnectionTest, AlarmsWhenWriteBlocked) { 1976 TEST_P(QuicConnectionTest, AlarmsWhenWriteBlocked) {
1986 // Block the connection. 1977 // Block the connection.
1987 BlockOnNextWrite(); 1978 BlockOnNextWrite();
1988 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); 1979 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL);
1989 EXPECT_EQ(1u, writer_->packets_write_attempts()); 1980 EXPECT_EQ(1u, writer_->packets_write_attempts());
(...skipping 1973 matching lines...) Expand 10 before | Expand all | Expand 10 after
3963 QuicBlockedFrame blocked; 3954 QuicBlockedFrame blocked;
3964 blocked.stream_id = 3; 3955 blocked.stream_id = 3;
3965 EXPECT_CALL(visitor_, OnBlockedFrames(_)); 3956 EXPECT_CALL(visitor_, OnBlockedFrames(_));
3966 ProcessFramePacket(QuicFrame(&blocked)); 3957 ProcessFramePacket(QuicFrame(&blocked));
3967 EXPECT_TRUE(ack_alarm->IsSet()); 3958 EXPECT_TRUE(ack_alarm->IsSet());
3968 } 3959 }
3969 3960
3970 } // namespace 3961 } // namespace
3971 } // namespace test 3962 } // namespace test
3972 } // namespace net 3963 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection.cc ('k') | net/quic/quic_crypto_server_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698