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

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

Issue 1531543004: Fix a bug protected by gfe2_reloadable_flag_quic_respect_send_alarm where acks would not be sent im… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@110021608
Patch Set: Created 5 years 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_flags.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 <ostream> 7 #include <ostream>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 1365 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 1376 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
1377 ProcessAckPacket(&frame); 1377 ProcessAckPacket(&frame);
1378 EXPECT_EQ(num_packets, manager_->largest_observed()); 1378 EXPECT_EQ(num_packets, manager_->largest_observed());
1379 } 1379 }
1380 1380
1381 TEST_P(QuicConnectionTest, AckReceiptCausesAckSendBadEntropy) { 1381 TEST_P(QuicConnectionTest, AckReceiptCausesAckSendBadEntropy) {
1382 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1382 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1383 1383
1384 ProcessPacket(1); 1384 ProcessPacket(1);
1385 // Delay sending, then queue up an ack. 1385 // Delay sending, then queue up an ack.
1386 EXPECT_CALL(*send_algorithm_, 1386 if (!FLAGS_quic_respect_send_alarm2) {
1387 TimeUntilSend(_, _, _)).WillOnce( 1387 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _))
1388 testing::Return(QuicTime::Delta::FromMicroseconds(1))); 1388 .WillOnce(testing::Return(QuicTime::Delta::FromMicroseconds(1)));
1389 }
1389 QuicConnectionPeer::SendAck(&connection_); 1390 QuicConnectionPeer::SendAck(&connection_);
1390 1391
1391 // Process an ack with a least unacked of the received ack. 1392 // Process an ack with a least unacked of the received ack.
1392 // This causes an ack to be sent when TimeUntilSend returns 0. 1393 // This causes an ack to be sent when TimeUntilSend returns 0.
1393 EXPECT_CALL(*send_algorithm_, 1394 EXPECT_CALL(*send_algorithm_,
1394 TimeUntilSend(_, _, _)).WillRepeatedly( 1395 TimeUntilSend(_, _, _)).WillRepeatedly(
1395 testing::Return(QuicTime::Delta::Zero())); 1396 testing::Return(QuicTime::Delta::Zero()));
1396 // Skip a packet and then record an ack. 1397 // Skip a packet and then record an ack.
1397 QuicAckFrame frame = InitAckFrame(0); 1398 QuicAckFrame frame = InitAckFrame(0);
1398 ProcessAckPacket(3, &frame); 1399 ProcessAckPacket(3, &frame);
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after
2212 // Simulate the retransmission alarm firing. FEC packet is no longer 2213 // Simulate the retransmission alarm firing. FEC packet is no longer
2213 // outstanding. 2214 // outstanding.
2214 clock_.AdvanceTime(rto_time.Subtract(clock_.Now())); 2215 clock_.AdvanceTime(rto_time.Subtract(clock_.Now()));
2215 connection_.GetRetransmissionAlarm()->Fire(); 2216 connection_.GetRetransmissionAlarm()->Fire();
2216 2217
2217 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 2218 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2218 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_)); 2219 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
2219 } 2220 }
2220 2221
2221 TEST_P(QuicConnectionTest, FramePacking) { 2222 TEST_P(QuicConnectionTest, FramePacking) {
2222 CongestionBlockWrites();
2223
2224 // Send an ack and two stream frames in 1 packet by queueing them. 2223 // Send an ack and two stream frames in 1 packet by queueing them.
2225 connection_.SendAck(); 2224 {
2226 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( 2225 QuicConnection::ScopedPacketBundler bundler(&connection_,
2227 IgnoreResult(InvokeWithoutArgs(&connection_, 2226 QuicConnection::SEND_ACK);
2228 &TestConnection::SendStreamData3)), 2227 connection_.SendStreamData3();
2229 IgnoreResult(InvokeWithoutArgs(&connection_, 2228 connection_.SendStreamData5();
2230 &TestConnection::SendStreamData5)))); 2229 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2231 2230 }
2232 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2233 CongestionUnblockWrites();
2234 connection_.GetSendAlarm()->Fire();
2235 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2231 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2236 EXPECT_FALSE(connection_.HasQueuedData()); 2232 EXPECT_FALSE(connection_.HasQueuedData());
2237 2233
2238 // Parse the last packet and ensure it's an ack and two stream frames from 2234 // Parse the last packet and ensure it's an ack and two stream frames from
2239 // two different streams. 2235 // two different streams.
2240 EXPECT_EQ(4u, writer_->frame_count()); 2236 EXPECT_EQ(4u, writer_->frame_count());
2241 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); 2237 EXPECT_FALSE(writer_->stop_waiting_frames().empty());
2242 EXPECT_FALSE(writer_->ack_frames().empty()); 2238 EXPECT_FALSE(writer_->ack_frames().empty());
2243 ASSERT_EQ(2u, writer_->stream_frames().size()); 2239 ASSERT_EQ(2u, writer_->stream_frames().size());
2244 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0]->stream_id); 2240 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0]->stream_id);
2245 EXPECT_EQ(kClientDataStreamId2, writer_->stream_frames()[1]->stream_id); 2241 EXPECT_EQ(kClientDataStreamId2, writer_->stream_frames()[1]->stream_id);
2246 } 2242 }
2247 2243
2248 TEST_P(QuicConnectionTest, FramePackingNonCryptoThenCrypto) { 2244 TEST_P(QuicConnectionTest, FramePackingNonCryptoThenCrypto) {
2249 CongestionBlockWrites();
2250
2251 // Send an ack and two stream frames (one non-crypto, then one crypto) in 2 2245 // Send an ack and two stream frames (one non-crypto, then one crypto) in 2
2252 // packets by queueing them. 2246 // packets by queueing them.
2253 connection_.SendAck(); 2247 {
2254 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( 2248 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
2255 IgnoreResult(InvokeWithoutArgs(&connection_, 2249 QuicConnection::ScopedPacketBundler bundler(&connection_,
2256 &TestConnection::SendStreamData3)), 2250 QuicConnection::SEND_ACK);
2257 IgnoreResult(InvokeWithoutArgs(&connection_, 2251 connection_.SendStreamData3();
2258 &TestConnection::SendCryptoStreamData)))); 2252 connection_.SendCryptoStreamData();
2259 2253 }
2260 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
2261 CongestionUnblockWrites();
2262 connection_.GetSendAlarm()->Fire();
2263 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2254 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2264 EXPECT_FALSE(connection_.HasQueuedData()); 2255 EXPECT_FALSE(connection_.HasQueuedData());
2265 2256
2266 // Parse the last packet and ensure it's the crypto stream frame. 2257 // Parse the last packet and ensure it's the crypto stream frame.
2267 EXPECT_EQ(1u, writer_->frame_count()); 2258 EXPECT_EQ(1u, writer_->frame_count());
2268 ASSERT_EQ(1u, writer_->stream_frames().size()); 2259 ASSERT_EQ(1u, writer_->stream_frames().size());
2269 EXPECT_EQ(kCryptoStreamId, writer_->stream_frames()[0]->stream_id); 2260 EXPECT_EQ(kCryptoStreamId, writer_->stream_frames()[0]->stream_id);
2270 } 2261 }
2271 2262
2272 TEST_P(QuicConnectionTest, FramePackingCryptoThenNonCrypto) { 2263 TEST_P(QuicConnectionTest, FramePackingCryptoThenNonCrypto) {
2273 CongestionBlockWrites();
2274
2275 // Send an ack and two stream frames (one crypto, then one non-crypto) in 2 2264 // Send an ack and two stream frames (one crypto, then one non-crypto) in 2
2276 // packets by queueing them. 2265 // packets by queueing them.
2277 connection_.SendAck(); 2266 {
2278 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( 2267 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
2279 IgnoreResult(InvokeWithoutArgs(&connection_, 2268 QuicConnection::ScopedPacketBundler bundler(&connection_,
2280 &TestConnection::SendCryptoStreamData)), 2269 QuicConnection::SEND_ACK);
2281 IgnoreResult(InvokeWithoutArgs(&connection_, 2270 connection_.SendCryptoStreamData();
2282 &TestConnection::SendStreamData3)))); 2271 connection_.SendStreamData3();
2283 2272 }
2284 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
2285 CongestionUnblockWrites();
2286 connection_.GetSendAlarm()->Fire();
2287 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2273 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2288 EXPECT_FALSE(connection_.HasQueuedData()); 2274 EXPECT_FALSE(connection_.HasQueuedData());
2289 2275
2290 // Parse the last packet and ensure it's the stream frame from stream 3. 2276 // Parse the last packet and ensure it's the stream frame from stream 3.
2291 EXPECT_EQ(1u, writer_->frame_count()); 2277 EXPECT_EQ(1u, writer_->frame_count());
2292 ASSERT_EQ(1u, writer_->stream_frames().size()); 2278 ASSERT_EQ(1u, writer_->stream_frames().size());
2293 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0]->stream_id); 2279 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0]->stream_id);
2294 } 2280 }
2295 2281
2296 TEST_P(QuicConnectionTest, FramePackingFEC) { 2282 TEST_P(QuicConnectionTest, FramePackingFEC) {
2297 EXPECT_TRUE(QuicPacketCreatorPeer::IsFecEnabled(creator_)); 2283 EXPECT_TRUE(QuicPacketCreatorPeer::IsFecEnabled(creator_));
2298 2284
2299 CongestionBlockWrites();
2300
2301 // Queue an ack and two stream frames. Ack gets flushed when FEC is turned on 2285 // Queue an ack and two stream frames. Ack gets flushed when FEC is turned on
2302 // for sending protected data; two stream frames are packed in 1 packet. 2286 // for sending protected data; two stream frames are packed in 1 packet.
2303 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( 2287 {
2304 IgnoreResult(InvokeWithoutArgs( 2288 QuicConnection::ScopedPacketBundler bundler(&connection_,
2305 &connection_, &TestConnection::SendStreamData3WithFec)), 2289 QuicConnection::SEND_ACK);
2306 IgnoreResult(InvokeWithoutArgs( 2290 connection_.SendStreamData3WithFec();
2307 &connection_, &TestConnection::SendStreamData5WithFec)))); 2291 connection_.SendStreamData5WithFec();
2308 connection_.SendAck(); 2292 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2309 2293 }
2310 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
2311 CongestionUnblockWrites();
2312 connection_.GetSendAlarm()->Fire();
2313 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2294 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2314 EXPECT_FALSE(connection_.HasQueuedData()); 2295 EXPECT_FALSE(connection_.HasQueuedData());
2315 2296
2316 // Parse the last packet and ensure it's in an fec group. 2297 // Parse the last packet and ensure it's in an fec group.
2317 EXPECT_EQ(2u, writer_->header().fec_group); 2298 EXPECT_EQ(2u, writer_->header().fec_group);
2318 EXPECT_EQ(2u, writer_->frame_count()); 2299 EXPECT_EQ(2u, writer_->frame_count());
2319 2300
2320 // FEC alarm should be set. 2301 // FEC alarm should be set.
2321 EXPECT_TRUE(connection_.GetFecAlarm()->IsSet()); 2302 EXPECT_TRUE(connection_.GetFecAlarm()->IsSet());
2322 } 2303 }
(...skipping 3148 matching lines...) Expand 10 before | Expand all | Expand 10 after
5471 TEST_P(QuicConnectionTest, DoNotSendGoAwayTwice) { 5452 TEST_P(QuicConnectionTest, DoNotSendGoAwayTwice) {
5472 EXPECT_FALSE(connection_.goaway_sent()); 5453 EXPECT_FALSE(connection_.goaway_sent());
5473 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 5454 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
5474 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); 5455 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away.");
5475 EXPECT_TRUE(connection_.goaway_sent()); 5456 EXPECT_TRUE(connection_.goaway_sent());
5476 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); 5457 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0);
5477 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); 5458 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away.");
5478 } 5459 }
5479 5460
5480 TEST_P(QuicConnectionTest, ReevaluateTimeUntilSendOnAck) { 5461 TEST_P(QuicConnectionTest, ReevaluateTimeUntilSendOnAck) {
5481 ValueRestore<bool> old_flag(&FLAGS_quic_respect_send_alarm, true); 5462 ValueRestore<bool> old_flag(&FLAGS_quic_respect_send_alarm2, true);
5482 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 5463 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
5483 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, !kFin, 5464 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, !kFin,
5484 nullptr); 5465 nullptr);
5485 5466
5486 // Evaluate CanWrite, and have it return a non-Zero value. 5467 // Evaluate CanWrite, and have it return a non-Zero value.
5487 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _)) 5468 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _))
5488 .WillRepeatedly(Return(QuicTime::Delta::FromMilliseconds(1))); 5469 .WillRepeatedly(Return(QuicTime::Delta::FromMilliseconds(1)));
5489 connection_.OnCanWrite(); 5470 connection_.OnCanWrite();
5490 EXPECT_TRUE(connection_.GetSendAlarm()->IsSet()); 5471 EXPECT_TRUE(connection_.GetSendAlarm()->IsSet());
5491 EXPECT_EQ(clock_.Now().Add(QuicTime::Delta::FromMilliseconds(1)), 5472 EXPECT_EQ(clock_.Now().Add(QuicTime::Delta::FromMilliseconds(1)),
(...skipping 12 matching lines...) Expand all
5504 .WillRepeatedly(Return(QuicTime::Delta::FromMilliseconds(2))); 5485 .WillRepeatedly(Return(QuicTime::Delta::FromMilliseconds(2)));
5505 ProcessAckPacket(&ack); 5486 ProcessAckPacket(&ack);
5506 EXPECT_EQ(1u, writer_->frame_count()); 5487 EXPECT_EQ(1u, writer_->frame_count());
5507 EXPECT_EQ(1u, writer_->stream_frames().size()); 5488 EXPECT_EQ(1u, writer_->stream_frames().size());
5508 EXPECT_TRUE(connection_.GetSendAlarm()->IsSet()); 5489 EXPECT_TRUE(connection_.GetSendAlarm()->IsSet());
5509 EXPECT_EQ(clock_.Now().Add(QuicTime::Delta::FromMilliseconds(2)), 5490 EXPECT_EQ(clock_.Now().Add(QuicTime::Delta::FromMilliseconds(2)),
5510 connection_.GetSendAlarm()->deadline()); 5491 connection_.GetSendAlarm()->deadline());
5511 writer_->Reset(); 5492 writer_->Reset();
5512 } 5493 }
5513 5494
5495 TEST_P(QuicConnectionTest, SendAcksImmediately) {
5496 FLAGS_quic_respect_send_alarm2 = true;
5497 CongestionBlockWrites();
5498 SendAckPacketToPeer();
5499 }
5500
5514 TEST_P(QuicConnectionTest, SendingUnencryptedStreamDataFails) { 5501 TEST_P(QuicConnectionTest, SendingUnencryptedStreamDataFails) {
5515 FLAGS_quic_never_write_unencrypted_data = true; 5502 FLAGS_quic_never_write_unencrypted_data = true;
5516 EXPECT_CALL(visitor_, 5503 EXPECT_CALL(visitor_,
5517 OnConnectionClosed(QUIC_UNENCRYPTED_STREAM_DATA, false)); 5504 OnConnectionClosed(QUIC_UNENCRYPTED_STREAM_DATA, false));
5518 EXPECT_DFATAL(connection_.SendStreamDataWithString(3, "", 0, kFin, nullptr), 5505 EXPECT_DFATAL(connection_.SendStreamDataWithString(3, "", 0, kFin, nullptr),
5519 "Cannot send stream data without encryption."); 5506 "Cannot send stream data without encryption.");
5520 EXPECT_FALSE(connection_.connected()); 5507 EXPECT_FALSE(connection_.connected());
5521 } 5508 }
5522 5509
5523 } // namespace 5510 } // namespace
5524 } // namespace test 5511 } // namespace test
5525 } // namespace net 5512 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection.cc ('k') | net/quic/quic_flags.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698