| OLD | NEW |
| 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 "net/base/net_errors.h" | 7 #include "net/base/net_errors.h" |
| 8 #include "net/quic/congestion_control/quic_receipt_metrics_collector.h" | 8 #include "net/quic/congestion_control/quic_receipt_metrics_collector.h" |
| 9 #include "net/quic/congestion_control/quic_send_scheduler.h" | 9 #include "net/quic/congestion_control/quic_send_scheduler.h" |
| 10 #include "net/quic/crypto/quic_decrypter.h" | 10 #include "net/quic/crypto/quic_decrypter.h" |
| 11 #include "net/quic/crypto/quic_encrypter.h" | 11 #include "net/quic/crypto/quic_encrypter.h" |
| 12 #include "net/quic/test_tools/mock_clock.h" | 12 #include "net/quic/test_tools/mock_clock.h" |
| 13 #include "net/quic/test_tools/quic_test_utils.h" | 13 #include "net/quic/test_tools/quic_test_utils.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 //DECLARE_int32(fake_packet_loss_percentage); | 17 //DECLARE_int32(fake_packet_loss_percentage); |
| 18 | 18 |
| 19 using base::StringPiece; |
| 19 using std::map; | 20 using std::map; |
| 20 using testing::_; | 21 using testing::_; |
| 21 using testing::ContainerEq; | 22 using testing::ContainerEq; |
| 22 using testing::Return; | 23 using testing::Return; |
| 24 using testing::StrictMock; |
| 23 | 25 |
| 24 namespace net { | 26 namespace net { |
| 25 | 27 |
| 26 // Peer to make public a number of otherwise private QuicConnection methods. | 28 // Peer to make public a number of otherwise private QuicConnection methods. |
| 27 class QuicConnectionPeer { | 29 class QuicConnectionPeer { |
| 28 public: | 30 public: |
| 29 static void SendAck(QuicConnection* connection) { | 31 static void SendAck(QuicConnection* connection) { |
| 30 connection->SendAck(); | 32 connection->SendAck(); |
| 31 } | 33 } |
| 32 | 34 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 private: | 182 private: |
| 181 DISALLOW_COPY_AND_ASSIGN(TestConnection); | 183 DISALLOW_COPY_AND_ASSIGN(TestConnection); |
| 182 }; | 184 }; |
| 183 | 185 |
| 184 class QuicConnectionTest : public ::testing::Test { | 186 class QuicConnectionTest : public ::testing::Test { |
| 185 protected: | 187 protected: |
| 186 QuicConnectionTest() | 188 QuicConnectionTest() |
| 187 : guid_(42), | 189 : guid_(42), |
| 188 framer_(QuicDecrypter::Create(kNULL), QuicEncrypter::Create(kNULL)), | 190 framer_(QuicDecrypter::Create(kNULL), QuicEncrypter::Create(kNULL)), |
| 189 creator_(guid_, &framer_), | 191 creator_(guid_, &framer_), |
| 190 scheduler_(new MockScheduler()), | 192 scheduler_(new StrictMock<MockScheduler>), |
| 191 helper_(new TestConnectionHelper(&clock_)), | 193 helper_(new TestConnectionHelper(&clock_)), |
| 192 connection_(guid_, IPEndPoint(), helper_), | 194 connection_(guid_, IPEndPoint(), helper_), |
| 193 frame1_(1, false, 0, data1), | 195 frame1_(1, false, 0, data1), |
| 194 frame2_(1, false, 3, data2), | 196 frame2_(1, false, 3, data2), |
| 195 accept_packet_(true) { | 197 accept_packet_(true) { |
| 196 connection_.set_visitor(&visitor_); | 198 connection_.set_visitor(&visitor_); |
| 197 connection_.SetScheduler(scheduler_); | 199 connection_.SetScheduler(scheduler_); |
| 198 EXPECT_CALL(*scheduler_, TimeUntilSend(_)).WillRepeatedly(Return( | 200 EXPECT_CALL(*scheduler_, TimeUntilSend(_)).WillRepeatedly(Return( |
| 199 QuicTime::Delta())); | 201 QuicTime::Delta())); |
| 200 } | 202 } |
| 201 | 203 |
| 202 QuicAckFrame* last_frame() { | 204 QuicAckFrame* last_frame() { |
| 203 return helper_->frame(); | 205 return helper_->frame(); |
| 204 } | 206 } |
| 205 | 207 |
| 206 QuicPacketHeader* last_header() { | 208 QuicPacketHeader* last_header() { |
| 207 return helper_->header(); | 209 return helper_->header(); |
| 208 } | 210 } |
| 209 | 211 |
| 210 void ProcessPacket(QuicPacketSequenceNumber number) { | 212 void ProcessPacket(QuicPacketSequenceNumber number) { |
| 211 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)) | 213 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)) |
| 212 .WillOnce(Return(accept_packet_)); | 214 .WillOnce(Return(accept_packet_)); |
| 215 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)); |
| 213 ProcessDataPacket(number, 0); | 216 ProcessDataPacket(number, 0); |
| 214 } | 217 } |
| 215 | 218 |
| 216 void ProcessFecProtectedPacket(QuicPacketSequenceNumber number, | 219 void ProcessFecProtectedPacket(QuicPacketSequenceNumber number, |
| 217 bool expect_revival) { | 220 bool expect_revival) { |
| 218 if (expect_revival) { | 221 if (expect_revival) { |
| 219 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).Times(2).WillRepeatedly( | 222 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).Times(2).WillRepeatedly( |
| 220 Return(accept_packet_)); | 223 Return(accept_packet_)); |
| 224 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)).Times(2); |
| 221 } else { | 225 } else { |
| 222 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillOnce( | 226 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillOnce( |
| 223 Return(accept_packet_)); | 227 Return(accept_packet_)); |
| 228 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)); |
| 224 } | 229 } |
| 225 ProcessDataPacket(number, 1); | 230 ProcessDataPacket(number, 1); |
| 226 } | 231 } |
| 227 | 232 |
| 228 void ProcessDataPacket(QuicPacketSequenceNumber number, | 233 void ProcessDataPacket(QuicPacketSequenceNumber number, |
| 229 QuicFecGroupNumber fec_group) { | 234 QuicFecGroupNumber fec_group) { |
| 230 scoped_ptr<QuicPacket> packet(ConstructDataPacket(number, fec_group)); | 235 scoped_ptr<QuicPacket> packet(ConstructDataPacket(number, fec_group)); |
| 231 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket(*packet)); | 236 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket(*packet)); |
| 232 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 237 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); |
| 233 } | 238 } |
| 234 | 239 |
| 235 // Sends an FEC packet that covers the packets that would have been sent. | 240 // Sends an FEC packet that covers the packets that would have been sent. |
| 236 void ProcessFecPacket(QuicPacketSequenceNumber number, | 241 void ProcessFecPacket(QuicPacketSequenceNumber number, |
| 237 QuicPacketSequenceNumber min_protected_packet, | 242 QuicPacketSequenceNumber min_protected_packet, |
| 238 bool expect_revival) { | 243 bool expect_revival) { |
| 239 if (expect_revival) { | 244 if (expect_revival) { |
| 240 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillOnce( | 245 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillOnce( |
| 241 Return(accept_packet_)); | 246 Return(accept_packet_)); |
| 247 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)); |
| 242 } | 248 } |
| 243 | 249 |
| 244 // Construct the decrypted data packet so we can compute the correct | 250 // Construct the decrypted data packet so we can compute the correct |
| 245 // redundancy. | 251 // redundancy. |
| 246 scoped_ptr<QuicPacket> data_packet(ConstructDataPacket(number, 1)); | 252 scoped_ptr<QuicPacket> data_packet(ConstructDataPacket(number, 1)); |
| 247 | 253 |
| 248 header_.guid = guid_; | 254 header_.guid = guid_; |
| 249 header_.packet_sequence_number = number; | 255 header_.packet_sequence_number = number; |
| 250 header_.flags = PACKET_FLAGS_FEC; | 256 header_.flags = PACKET_FLAGS_FEC; |
| 251 header_.fec_group = 1; | 257 header_.fec_group = 1; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 264 fec_data.redundancy = data_packet->FecProtectedData(); | 270 fec_data.redundancy = data_packet->FecProtectedData(); |
| 265 QuicPacket* fec_packet; | 271 QuicPacket* fec_packet; |
| 266 framer_.ConstructFecPacket(header_, fec_data, &fec_packet); | 272 framer_.ConstructFecPacket(header_, fec_data, &fec_packet); |
| 267 scoped_ptr<QuicEncryptedPacket> encrypted( | 273 scoped_ptr<QuicEncryptedPacket> encrypted( |
| 268 framer_.EncryptPacket(*fec_packet)); | 274 framer_.EncryptPacket(*fec_packet)); |
| 269 | 275 |
| 270 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 276 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); |
| 271 delete fec_packet; | 277 delete fec_packet; |
| 272 } | 278 } |
| 273 | 279 |
| 280 void SendStreamDataToPeer(QuicStreamId id, StringPiece data, |
| 281 QuicStreamOffset offset, bool fin, |
| 282 QuicPacketSequenceNumber* last_packet) { |
| 283 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)); |
| 284 connection_.SendStreamData(id, data, offset, fin, last_packet); |
| 285 } |
| 274 | 286 |
| 275 void SendAckPacket(QuicAckFrame* frame) { | 287 void SendAckPacketToPeer() { |
| 288 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)); |
| 289 connection_.SendAck(); |
| 290 } |
| 291 |
| 292 void ProcessAckPacket(QuicAckFrame* frame, bool expect_success = true) { |
| 293 if (expect_success) { |
| 294 EXPECT_CALL(*scheduler_, OnIncomingAckFrame(_)); |
| 295 } |
| 276 scoped_ptr<QuicPacket> packet(creator_.AckPacket(frame).second); | 296 scoped_ptr<QuicPacket> packet(creator_.AckPacket(frame).second); |
| 277 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket(*packet)); | 297 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket(*packet)); |
| 278 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 298 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); |
| 279 } | 299 } |
| 280 | 300 |
| 281 void SendAckPacket(QuicPacketSequenceNumber least_unacked) { | |
| 282 QuicAckFrame frame(0, QuicTime(), least_unacked); | |
| 283 SendAckPacket(&frame); | |
| 284 } | |
| 285 | |
| 286 bool IsMissing(QuicPacketSequenceNumber number) { | 301 bool IsMissing(QuicPacketSequenceNumber number) { |
| 287 return last_frame()->received_info.missing_packets.find(number) != | 302 return !last_frame()->received_info.ContainsAck(number); |
| 288 last_frame()->received_info.missing_packets.end(); | |
| 289 } | |
| 290 | |
| 291 size_t NonRetransmittingSize() { | |
| 292 return last_frame()->sent_info.non_retransmiting.size(); | |
| 293 } | |
| 294 | |
| 295 bool NonRetransmitting(QuicPacketSequenceNumber number) { | |
| 296 return last_frame()->sent_info.non_retransmiting.find(number) != | |
| 297 last_frame()->sent_info.non_retransmiting.end(); | |
| 298 } | 303 } |
| 299 | 304 |
| 300 QuicPacket* ConstructDataPacket(QuicPacketSequenceNumber number, | 305 QuicPacket* ConstructDataPacket(QuicPacketSequenceNumber number, |
| 301 QuicFecGroupNumber fec_group) { | 306 QuicFecGroupNumber fec_group) { |
| 302 header_.guid = guid_; | 307 header_.guid = guid_; |
| 303 header_.packet_sequence_number = number; | 308 header_.packet_sequence_number = number; |
| 304 header_.flags = PACKET_FLAGS_NONE; | 309 header_.flags = PACKET_FLAGS_NONE; |
| 305 header_.fec_group = fec_group; | 310 header_.fec_group = fec_group; |
| 306 | 311 |
| 307 QuicFrames frames; | 312 QuicFrames frames; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 327 QuicStreamFrame frame2_; | 332 QuicStreamFrame frame2_; |
| 328 bool accept_packet_; | 333 bool accept_packet_; |
| 329 | 334 |
| 330 private: | 335 private: |
| 331 DISALLOW_COPY_AND_ASSIGN(QuicConnectionTest); | 336 DISALLOW_COPY_AND_ASSIGN(QuicConnectionTest); |
| 332 }; | 337 }; |
| 333 | 338 |
| 334 TEST_F(QuicConnectionTest, PacketsInOrder) { | 339 TEST_F(QuicConnectionTest, PacketsInOrder) { |
| 335 ProcessPacket(1); | 340 ProcessPacket(1); |
| 336 EXPECT_EQ(1u, last_frame()->received_info.largest_received); | 341 EXPECT_EQ(1u, last_frame()->received_info.largest_received); |
| 337 EXPECT_EQ(0u, last_frame()->received_info.missing_packets.size()); | 342 EXPECT_EQ(1u, last_frame()->received_info.received_packet_times.size()); |
| 338 | 343 |
| 339 ProcessPacket(2); | 344 ProcessPacket(2); |
| 340 EXPECT_EQ(2u, last_frame()->received_info.largest_received); | 345 EXPECT_EQ(2u, last_frame()->received_info.largest_received); |
| 341 EXPECT_EQ(0u, last_frame()->received_info.missing_packets.size()); | 346 EXPECT_EQ(2u, last_frame()->received_info.received_packet_times.size()); |
| 342 | 347 |
| 343 ProcessPacket(3); | 348 ProcessPacket(3); |
| 344 EXPECT_EQ(3u, last_frame()->received_info.largest_received); | 349 EXPECT_EQ(3u, last_frame()->received_info.largest_received); |
| 345 EXPECT_EQ(0u, last_frame()->received_info.missing_packets.size()); | 350 EXPECT_EQ(3u, last_frame()->received_info.received_packet_times.size()); |
| 346 } | 351 } |
| 347 | 352 |
| 348 TEST_F(QuicConnectionTest, PacketsRejected) { | 353 TEST_F(QuicConnectionTest, PacketsRejected) { |
| 349 ProcessPacket(1); | 354 ProcessPacket(1); |
| 350 EXPECT_EQ(1u, last_frame()->received_info.largest_received); | 355 EXPECT_EQ(1u, last_frame()->received_info.largest_received); |
| 351 EXPECT_EQ(0u, last_frame()->received_info.missing_packets.size()); | 356 EXPECT_EQ(1u, last_frame()->received_info.received_packet_times.size()); |
| 352 | 357 |
| 353 accept_packet_ = false; | 358 accept_packet_ = false; |
| 354 ProcessPacket(2); | 359 ProcessPacket(2); |
| 355 // We should not have an ack for two. | 360 // We should not have an ack for two. |
| 356 EXPECT_EQ(1u, last_frame()->received_info.largest_received); | 361 EXPECT_EQ(1u, last_frame()->received_info.largest_received); |
| 357 EXPECT_EQ(0u, last_frame()->received_info.missing_packets.size()); | 362 EXPECT_EQ(1u, last_frame()->received_info.received_packet_times.size()); |
| 358 } | 363 } |
| 359 | 364 |
| 360 TEST_F(QuicConnectionTest, PacketsOutOfOrder) { | 365 TEST_F(QuicConnectionTest, PacketsOutOfOrder) { |
| 361 ProcessPacket(3); | 366 ProcessPacket(3); |
| 362 EXPECT_EQ(3u, last_frame()->received_info.largest_received); | 367 EXPECT_EQ(3u, last_frame()->received_info.largest_received); |
| 363 EXPECT_EQ(2u, last_frame()->received_info.missing_packets.size()); | 368 EXPECT_EQ(1u, last_frame()->received_info.received_packet_times.size()); |
| 364 EXPECT_TRUE(IsMissing(2)); | 369 EXPECT_TRUE(IsMissing(2)); |
| 365 EXPECT_TRUE(IsMissing(1)); | 370 EXPECT_TRUE(IsMissing(1)); |
| 366 | 371 |
| 367 ProcessPacket(2); | 372 ProcessPacket(2); |
| 368 EXPECT_EQ(3u, last_frame()->received_info.largest_received); | 373 EXPECT_EQ(3u, last_frame()->received_info.largest_received); |
| 369 EXPECT_EQ(1u, last_frame()->received_info.missing_packets.size()); | 374 EXPECT_EQ(2u, last_frame()->received_info.received_packet_times.size()); |
| 370 EXPECT_TRUE(IsMissing(1)); | 375 EXPECT_TRUE(IsMissing(1)); |
| 371 | 376 |
| 372 ProcessPacket(1); | 377 ProcessPacket(1); |
| 373 EXPECT_EQ(3u, last_frame()->received_info.largest_received); | 378 EXPECT_EQ(3u, last_frame()->received_info.largest_received); |
| 374 EXPECT_EQ(0u, last_frame()->received_info.missing_packets.size()); | 379 EXPECT_EQ(3u, last_frame()->received_info.received_packet_times.size()); |
| 375 } | 380 } |
| 376 | 381 |
| 377 TEST_F(QuicConnectionTest, DuplicatePacket) { | 382 TEST_F(QuicConnectionTest, DuplicatePacket) { |
| 378 ProcessPacket(3); | 383 ProcessPacket(3); |
| 379 EXPECT_EQ(3u, last_frame()->received_info.largest_received); | 384 EXPECT_EQ(3u, last_frame()->received_info.largest_received); |
| 380 EXPECT_EQ(2u, last_frame()->received_info.missing_packets.size()); | 385 EXPECT_EQ(1u, last_frame()->received_info.received_packet_times.size()); |
| 381 EXPECT_TRUE(IsMissing(2)); | 386 EXPECT_TRUE(IsMissing(2)); |
| 382 EXPECT_TRUE(IsMissing(1)); | 387 EXPECT_TRUE(IsMissing(1)); |
| 383 | 388 |
| 384 // Send packet 3 again, but do not set the expectation that | 389 // Send packet 3 again, but do not set the expectation that |
| 385 // the visitor OnPacket() will be called. | 390 // the visitor OnPacket() will be called. |
| 386 ProcessDataPacket(3, 0); | 391 ProcessDataPacket(3, 0); |
| 387 EXPECT_EQ(3u, last_frame()->received_info.largest_received); | 392 EXPECT_EQ(3u, last_frame()->received_info.largest_received); |
| 388 EXPECT_EQ(2u, last_frame()->received_info.missing_packets.size()); | 393 EXPECT_EQ(1u, last_frame()->received_info.received_packet_times.size()); |
| 389 EXPECT_TRUE(IsMissing(2)); | 394 EXPECT_TRUE(IsMissing(2)); |
| 390 EXPECT_TRUE(IsMissing(1)); | 395 EXPECT_TRUE(IsMissing(1)); |
| 391 } | 396 } |
| 392 | 397 |
| 393 TEST_F(QuicConnectionTest, LatePacketMarkedWillNotResend) { | 398 TEST_F(QuicConnectionTest, PacketsOutOfOrderWithAdditionsAndLeastAwaiting) { |
| 394 ProcessPacket(5); | |
| 395 // Now send non-resending information, that we're not going to resend 3. | |
| 396 // The far end should stop waiting for it. | |
| 397 QuicPacketSequenceNumber largest_received = 0; | |
| 398 QuicTime time_received; | |
| 399 QuicPacketSequenceNumber least_unacked = 1; | |
| 400 QuicAckFrame frame(largest_received, time_received, least_unacked); | |
| 401 frame.sent_info.non_retransmiting.insert(3); | |
| 402 SendAckPacket(&frame); | |
| 403 // Force an ack to be sent. | |
| 404 connection_.SendAck(); | |
| 405 EXPECT_EQ(5u, last_frame()->received_info.largest_received); | |
| 406 EXPECT_EQ(2u, last_frame()->received_info.missing_packets.size()); | |
| 407 EXPECT_TRUE(IsMissing(4)); | |
| 408 EXPECT_TRUE(IsMissing(2)); | |
| 409 | |
| 410 // Send packet 3 again, but do not set the expectation that | |
| 411 // the visitor OnPacket() will be called. | |
| 412 ProcessDataPacket(3, 0); | |
| 413 connection_.SendAck(); | |
| 414 EXPECT_EQ(5u, last_frame()->received_info.largest_received); | |
| 415 EXPECT_EQ(2u, last_frame()->received_info.missing_packets.size()); | |
| 416 EXPECT_TRUE(IsMissing(4)); | |
| 417 EXPECT_TRUE(IsMissing(2)); | |
| 418 } | |
| 419 | |
| 420 TEST_F(QuicConnectionTest, PacketsOutOfOrderWithAdditionsAndNonResend) { | |
| 421 ProcessPacket(3); | 399 ProcessPacket(3); |
| 422 EXPECT_EQ(3u, last_frame()->received_info.largest_received); | 400 EXPECT_EQ(3u, last_frame()->received_info.largest_received); |
| 423 EXPECT_EQ(2u, last_frame()->received_info.missing_packets.size()); | 401 EXPECT_EQ(1u, last_frame()->received_info.received_packet_times.size()); |
| 424 EXPECT_TRUE(IsMissing(2)); | 402 EXPECT_TRUE(IsMissing(2)); |
| 425 EXPECT_TRUE(IsMissing(1)); | 403 EXPECT_TRUE(IsMissing(1)); |
| 426 | 404 |
| 427 ProcessPacket(2); | 405 ProcessPacket(2); |
| 428 EXPECT_EQ(3u, last_frame()->received_info.largest_received); | 406 EXPECT_EQ(3u, last_frame()->received_info.largest_received); |
| 429 EXPECT_EQ(1u, last_frame()->received_info.missing_packets.size()); | 407 EXPECT_EQ(2u, last_frame()->received_info.received_packet_times.size()); |
| 430 EXPECT_TRUE(IsMissing(1)); | |
| 431 | |
| 432 ProcessPacket(6); | |
| 433 EXPECT_EQ(6u, last_frame()->received_info.largest_received); | |
| 434 EXPECT_EQ(3u, last_frame()->received_info.missing_packets.size()); | |
| 435 EXPECT_TRUE(IsMissing(1)); | |
| 436 EXPECT_TRUE(IsMissing(4)); | |
| 437 EXPECT_TRUE(IsMissing(5)); | |
| 438 | |
| 439 // Now send non-resending information, that we're not going to resend 4. | |
| 440 // The far end should stop waiting for it. | |
| 441 // In sending the ack, we also have sent packet 1, so we'll stop waiting for | |
| 442 // that as well. | |
| 443 QuicAckFrame frame(0, QuicTime(), 1); | |
| 444 frame.sent_info.non_retransmiting.insert(4); | |
| 445 SendAckPacket(&frame); | |
| 446 // Force an ack to be sent. | |
| 447 connection_.SendAck(); | |
| 448 EXPECT_EQ(1u, last_frame()->received_info.missing_packets.size()); | |
| 449 EXPECT_TRUE(IsMissing(5)); | |
| 450 } | |
| 451 | |
| 452 TEST_F(QuicConnectionTest, PacketsOutOfOrderWithAdditionsAndLeastAwaiting) { | |
| 453 ProcessPacket(3); | |
| 454 EXPECT_EQ(3u, last_frame()->received_info.largest_received); | |
| 455 EXPECT_EQ(2u, last_frame()->received_info.missing_packets.size()); | |
| 456 EXPECT_TRUE(IsMissing(2)); | |
| 457 EXPECT_TRUE(IsMissing(1)); | |
| 458 | |
| 459 ProcessPacket(2); | |
| 460 EXPECT_EQ(3u, last_frame()->received_info.largest_received); | |
| 461 EXPECT_EQ(1u, last_frame()->received_info.missing_packets.size()); | |
| 462 EXPECT_TRUE(IsMissing(1)); | 408 EXPECT_TRUE(IsMissing(1)); |
| 463 | 409 |
| 464 ProcessPacket(5); | 410 ProcessPacket(5); |
| 465 EXPECT_EQ(5u, last_frame()->received_info.largest_received); | 411 EXPECT_EQ(5u, last_frame()->received_info.largest_received); |
| 466 EXPECT_EQ(2u, last_frame()->received_info.missing_packets.size()); | 412 EXPECT_EQ(3u, last_frame()->received_info.received_packet_times.size()); |
| 467 EXPECT_TRUE(IsMissing(1)); | 413 EXPECT_TRUE(IsMissing(1)); |
| 468 EXPECT_TRUE(IsMissing(4)); | 414 EXPECT_TRUE(IsMissing(4)); |
| 469 | 415 |
| 470 // Pretend at this point the client has gotten acks for 2 and 3 and 1 is a | 416 // Pretend at this point the client has gotten acks for 2 and 3 and 1 is a |
| 471 // packet the peer will not retransmit. It indicates this by sending 'least | 417 // packet the peer will not retransmit. It indicates this by sending 'least |
| 472 // awaiting' is 4. The connection should then realize 1 will not be | 418 // awaiting' is 4. The connection should then realize 1 will not be |
| 473 // retransmitted, and will remove it from the missing list. | 419 // retransmitted, and will remove it from the missing list. |
| 474 QuicAckFrame frame(0, QuicTime(), 4); | 420 QuicAckFrame frame(0, QuicTime(), 4); |
| 475 SendAckPacket(&frame); | 421 ProcessAckPacket(&frame); |
| 476 // Force an ack to be sent. | 422 // Force an ack to be sent. |
| 477 connection_.SendAck(); | 423 SendAckPacketToPeer(); |
| 478 EXPECT_EQ(1u, last_frame()->received_info.missing_packets.size()); | 424 EXPECT_EQ(2u, last_frame()->received_info.received_packet_times.size()); |
| 479 EXPECT_TRUE(IsMissing(4)); | 425 EXPECT_TRUE(IsMissing(4)); |
| 480 } | 426 } |
| 481 | 427 |
| 482 TEST_F(QuicConnectionTest, RejectPacketTooFarOut) { | 428 TEST_F(QuicConnectionTest, RejectPacketTooFarOut) { |
| 483 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a | 429 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a |
| 484 // packet call to the visitor. | 430 // packet call to the visitor. |
| 485 ProcessDataPacket(6000, 0);; | 431 ProcessDataPacket(6000, 0); |
| 486 | 432 |
| 487 connection_.SendAck(); // Packet 2 | 433 SendAckPacketToPeer(); // Packet 2 |
| 488 EXPECT_EQ(0u, last_frame()->received_info.largest_received); | 434 EXPECT_EQ(0u, last_frame()->received_info.largest_received); |
| 489 } | 435 } |
| 490 | 436 |
| 491 TEST_F(QuicConnectionTest, LeastUnackedLower) { | 437 TEST_F(QuicConnectionTest, LeastUnackedLower) { |
| 492 connection_.SendStreamData(1, "foo", 0, false, NULL); | 438 SendStreamDataToPeer(1, "foo", 0, false, NULL); |
| 493 connection_.SendStreamData(1, "bar", 3, false, NULL); | 439 SendStreamDataToPeer(1, "bar", 3, false, NULL); |
| 494 connection_.SendStreamData(1, "eep", 6, false, NULL); | 440 SendStreamDataToPeer(1, "eep", 6, false, NULL); |
| 495 | 441 |
| 496 // Start out saying the least unacked is 2 | 442 // Start out saying the least unacked is 2 |
| 497 creator_.set_sequence_number(5); | 443 creator_.set_sequence_number(5); |
| 498 QuicAckFrame frame(0, QuicTime(), 2); | 444 QuicAckFrame frame(0, QuicTime(), 2); |
| 499 SendAckPacket(&frame); | 445 ProcessAckPacket(&frame); |
| 500 | 446 |
| 501 // Change it to 1, but lower the sequence number to fake out-of-order packets. | 447 // Change it to 1, but lower the sequence number to fake out-of-order packets. |
| 502 // This should be fine. | 448 // This should be fine. |
| 503 creator_.set_sequence_number(1); | 449 creator_.set_sequence_number(1); |
| 504 QuicAckFrame frame2(0, QuicTime(), 1); | 450 QuicAckFrame frame2(0, QuicTime(), 1); |
| 505 SendAckPacket(&frame2); | 451 // The scheduler will not process out of order acks. |
| 452 ProcessAckPacket(&frame2, false); |
| 506 | 453 |
| 507 // Now claim it's one, but set the ordering so it was sent "after" the first | 454 // Now claim it's one, but set the ordering so it was sent "after" the first |
| 508 // one. This should cause a connection error. | 455 // one. This should cause a connection error. |
| 509 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_ACK_DATA, false)); | 456 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_ACK_DATA, false)); |
| 457 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)); |
| 510 creator_.set_sequence_number(7); | 458 creator_.set_sequence_number(7); |
| 511 SendAckPacket(&frame2); | 459 ProcessAckPacket(&frame2, false); |
| 512 } | 460 } |
| 513 | 461 |
| 514 TEST_F(QuicConnectionTest, AckUnsentData) { | 462 TEST_F(QuicConnectionTest, AckUnsentData) { |
| 515 // Ack a packet which has not been sent. | 463 // Ack a packet which has not been sent. |
| 516 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_ACK_DATA, false)); | 464 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_ACK_DATA, false)); |
| 465 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)); |
| 517 QuicAckFrame frame(1, QuicTime(), 0); | 466 QuicAckFrame frame(1, QuicTime(), 0); |
| 518 SendAckPacket(&frame); | 467 ProcessAckPacket(&frame, false); |
| 519 } | 468 } |
| 520 | 469 |
| 521 TEST_F(QuicConnectionTest, AckAll) { | 470 TEST_F(QuicConnectionTest, AckAll) { |
| 522 ProcessPacket(1); | 471 ProcessPacket(1); |
| 523 | 472 |
| 524 creator_.set_sequence_number(1); | 473 creator_.set_sequence_number(1); |
| 525 QuicAckFrame frame1(1, QuicTime(), 1); | 474 QuicAckFrame frame1(1, QuicTime(), 1); |
| 526 SendAckPacket(&frame1); | 475 ProcessAckPacket(&frame1); |
| 527 | 476 |
| 528 // Send an ack with least_unacked == 0, which indicates that all packets | 477 // Send an ack with least_unacked == 0, which indicates that all packets |
| 529 // we have sent have been acked. | 478 // we have sent have been acked. |
| 530 QuicAckFrame frame2(1, QuicTime(), 0); | 479 QuicAckFrame frame2(1, QuicTime(), 0); |
| 531 SendAckPacket(&frame2); | 480 ProcessAckPacket(&frame2); |
| 532 } | 481 } |
| 533 | 482 |
| 534 // This test is meant to validate that we can't overwhelm the far end with a ton | 483 // This test is meant to validate that we can't overwhelm the far end with a ton |
| 535 // of missing packets. | 484 // of acks. |
| 536 // We will likely fix the protocol to allow more than 190 in flight, and the | 485 // We will likely fix the protocol to allow more than 190 in flight, and the |
| 537 // test will need to be adjusted accordingly. | 486 // test will need to be adjusted accordingly. |
| 538 TEST_F(QuicConnectionTest, TooManyMissing) { | 487 TEST_F(QuicConnectionTest, TooManyAcked) { |
| 539 connection_.SendStreamData(1, "foo", 0, false, NULL); | 488 SendStreamDataToPeer(1, "foo", 0, false, NULL); |
| 540 | 489 |
| 541 EXPECT_CALL(visitor_, ConnectionClose(QUIC_PACKET_TOO_LARGE, false)); | 490 EXPECT_CALL(visitor_, ConnectionClose(QUIC_PACKET_TOO_LARGE, false)); |
| 542 QuicAckFrame frame(1, QuicTime(), 0); | 491 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)); |
| 543 for (int i = 0; i < 5001; ++i) { | 492 QuicAckFrame frame(0, QuicTime(), 0); |
| 544 frame.received_info.missing_packets.insert(i); | 493 for (int i = 1; i < 5001; ++i) { |
| 494 frame.received_info.RecordAck(i, QuicTime::FromMilliseconds(i)); |
| 545 } | 495 } |
| 546 SendAckPacket(&frame); | 496 ProcessAckPacket(&frame, false); |
| 547 } | |
| 548 | |
| 549 // See comment for TooManyMissing above. | |
| 550 TEST_F(QuicConnectionTest, TooManyNonRetransmitting) { | |
| 551 connection_.SendStreamData(1, "foo", 0, false, NULL); | |
| 552 | |
| 553 EXPECT_CALL(visitor_, ConnectionClose(QUIC_PACKET_TOO_LARGE, false)); | |
| 554 QuicAckFrame frame(1, QuicTime(), 0); | |
| 555 for (int i = 0; i < 5001; ++i) { | |
| 556 frame.sent_info.non_retransmiting.insert(i); | |
| 557 } | |
| 558 SendAckPacket(&frame); | |
| 559 } | 497 } |
| 560 | 498 |
| 561 TEST_F(QuicConnectionTest, BasicSending) { | 499 TEST_F(QuicConnectionTest, BasicSending) { |
| 562 QuicPacketSequenceNumber last_packet; | 500 QuicPacketSequenceNumber last_packet; |
| 563 connection_.SendStreamData(1, "foo", 0, false, &last_packet); // Packet 1 | 501 SendStreamDataToPeer(1, "foo", 0, false, &last_packet); // Packet 1 |
| 564 EXPECT_EQ(1u, last_packet); | 502 EXPECT_EQ(1u, last_packet); |
| 565 connection_.SendAck(); // Packet 2 | 503 SendAckPacketToPeer(); // Packet 2 |
| 566 | 504 |
| 567 EXPECT_EQ(1u, last_frame()->sent_info.least_unacked); | 505 EXPECT_EQ(1u, last_frame()->sent_info.least_unacked); |
| 568 | 506 |
| 569 connection_.SendAck(); // Packet 3 | 507 SendAckPacketToPeer(); // Packet 3 |
| 570 EXPECT_EQ(1u, last_frame()->sent_info.least_unacked); | 508 EXPECT_EQ(1u, last_frame()->sent_info.least_unacked); |
| 571 EXPECT_EQ(1u, NonRetransmittingSize()); | |
| 572 EXPECT_TRUE(NonRetransmitting(2)); | |
| 573 | 509 |
| 574 connection_.SendStreamData(1, "bar", 3, false, &last_packet); // Packet 4 | 510 SendStreamDataToPeer(1u, "bar", 3, false, &last_packet); // Packet 4 |
| 575 EXPECT_EQ(4u, last_packet); | 511 EXPECT_EQ(4u, last_packet); |
| 576 connection_.SendAck(); // Packet 5 | 512 SendAckPacketToPeer(); // Packet 5 |
| 577 EXPECT_EQ(1u, last_frame()->sent_info.least_unacked); | 513 EXPECT_EQ(1u, last_frame()->sent_info.least_unacked); |
| 578 EXPECT_EQ(2u, NonRetransmittingSize()); | |
| 579 EXPECT_TRUE(NonRetransmitting(2)); | |
| 580 EXPECT_TRUE(NonRetransmitting(3)); | |
| 581 | 514 |
| 582 QuicConnectionVisitorInterface::AckedPackets expected_acks; | 515 QuicConnectionVisitorInterface::AckedPackets expected_acks; |
| 583 expected_acks.insert(1); | 516 expected_acks.insert(1); |
| 584 | 517 |
| 585 // Client acks up to packet 3 | 518 // Client acks up to packet 3 |
| 586 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); | 519 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); |
| 587 QuicAckFrame frame(3, QuicTime(), 0); | 520 QuicAckFrame frame(3, QuicTime(), 0); |
| 588 SendAckPacket(&frame); | 521 ProcessAckPacket(&frame); |
| 589 connection_.SendAck(); // Packet 6 | 522 SendAckPacketToPeer(); // Packet 6 |
| 590 | 523 |
| 591 // As soon as we've acked one, we skip ack packets 2 and 3 and note lack of | 524 // As soon as we've acked one, we skip ack packets 2 and 3 and note lack of |
| 592 // ack for 4. | 525 // ack for 4. |
| 593 EXPECT_EQ(4u, last_frame()->sent_info.least_unacked); | 526 EXPECT_EQ(4u, last_frame()->sent_info.least_unacked); |
| 594 EXPECT_EQ(1u, NonRetransmittingSize()); | |
| 595 EXPECT_TRUE(NonRetransmitting(5)); | |
| 596 | 527 |
| 597 expected_acks.clear(); | 528 expected_acks.clear(); |
| 598 expected_acks.insert(4); | 529 expected_acks.insert(4); |
| 599 | 530 |
| 600 // Client acks up to packet 4, the last packet | 531 // Client acks up to packet 4, the last packet |
| 601 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); | 532 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); |
| 602 QuicAckFrame frame2(6, QuicTime(), 0); | 533 QuicAckFrame frame2(6, QuicTime(), 0); |
| 603 SendAckPacket(&frame2); | 534 ProcessAckPacket(&frame2); |
| 604 connection_.SendAck(); // Packet 7 | 535 SendAckPacketToPeer(); // Packet 7 |
| 605 | 536 |
| 606 // The least packet awaiting ack should now be the special value of 0 | 537 // The least packet awaiting ack should now be the special value of 0 |
| 607 EXPECT_EQ(0u, last_frame()->sent_info.least_unacked); | 538 EXPECT_EQ(0u, last_frame()->sent_info.least_unacked); |
| 608 EXPECT_EQ(0u, NonRetransmittingSize()); | |
| 609 | 539 |
| 610 // If we force an ack, we shouldn't change our retransmit state. | 540 // If we force an ack, we shouldn't change our retransmit state. |
| 611 connection_.SendAck(); // Packet 8 | 541 SendAckPacketToPeer(); // Packet 8 |
| 612 EXPECT_EQ(0u, last_frame()->sent_info.least_unacked); | 542 EXPECT_EQ(0u, last_frame()->sent_info.least_unacked); |
| 613 EXPECT_EQ(0u, NonRetransmittingSize()); | |
| 614 | 543 |
| 615 // But if we send more data it should. | 544 // But if we send more data it should. |
| 616 connection_.SendStreamData(1, "eep", 6, false, &last_packet); // Packet 9 | 545 SendStreamDataToPeer(1, "eep", 6, false, &last_packet); // Packet 9 |
| 617 EXPECT_EQ(9u, last_packet); | 546 EXPECT_EQ(9u, last_packet); |
| 618 connection_.SendAck(); // Packet10 | 547 SendAckPacketToPeer(); // Packet10 |
| 619 EXPECT_EQ(9u, last_frame()->sent_info.least_unacked); | 548 EXPECT_EQ(9u, last_frame()->sent_info.least_unacked); |
| 620 } | 549 } |
| 621 | 550 |
| 622 // Test sending multiple acks from the connection to the session. | 551 // Test sending multiple acks from the connection to the session. |
| 623 TEST_F(QuicConnectionTest, MultipleAcks) { | 552 TEST_F(QuicConnectionTest, MultipleAcks) { |
| 624 QuicPacketSequenceNumber last_packet; | 553 QuicPacketSequenceNumber last_packet; |
| 625 connection_.SendStreamData(1, "foo", 0, false, &last_packet); // Packet 1 | 554 SendStreamDataToPeer(1u, "foo", 0, false, &last_packet); // Packet 1 |
| 626 EXPECT_EQ(1u, last_packet); | 555 EXPECT_EQ(1u, last_packet); |
| 627 connection_.SendStreamData(3, "foo", 0, false, &last_packet); // Packet 2 | 556 SendStreamDataToPeer(3u, "foo", 0, false, &last_packet); // Packet 2 |
| 628 EXPECT_EQ(2u, last_packet); | 557 EXPECT_EQ(2u, last_packet); |
| 629 connection_.SendAck(); // Packet 3 | 558 SendAckPacketToPeer(); // Packet 3 |
| 630 connection_.SendStreamData(5, "foo", 0, false, &last_packet); // Packet 4 | 559 SendStreamDataToPeer(5u, "foo", 0, false, &last_packet); // Packet 4 |
| 631 EXPECT_EQ(4u, last_packet); | 560 EXPECT_EQ(4u, last_packet); |
| 632 connection_.SendStreamData(1, "foo", 3, false, &last_packet); // Packet 5 | 561 SendStreamDataToPeer(1u, "foo", 3, false, &last_packet); // Packet 5 |
| 633 EXPECT_EQ(5u, last_packet); | 562 EXPECT_EQ(5u, last_packet); |
| 634 connection_.SendStreamData(3, "foo", 3, false, &last_packet); // Packet 6 | 563 SendStreamDataToPeer(3u, "foo", 3, false, &last_packet); // Packet 6 |
| 635 EXPECT_EQ(6u, last_packet); | 564 EXPECT_EQ(6u, last_packet); |
| 636 | 565 |
| 637 // Client will acks packets 1, [!2], 3, 4, 5 | 566 // Client will ack packets 1, [!2], 3, 4, 5 |
| 638 QuicAckFrame frame1(5, QuicTime(), 0); | 567 QuicAckFrame frame1(5, QuicTime(), 0); |
| 639 frame1.received_info.missing_packets.insert(2); | 568 frame1.received_info.received_packet_times.erase(2); |
| 640 | 569 |
| 641 // The connection should pass up acks for 1, 4, 5. 2 is not acked, and 3 was | 570 // The connection should pass up acks for 1, 4, 5. 2 is not acked, and 3 was |
| 642 // an ackframe so should not be passed up. | 571 // an ackframe so should not be passed up. |
| 643 QuicConnectionVisitorInterface::AckedPackets expected_acks; | 572 QuicConnectionVisitorInterface::AckedPackets expected_acks; |
| 644 expected_acks.insert(1); | 573 expected_acks.insert(1); |
| 645 expected_acks.insert(4); | 574 expected_acks.insert(4); |
| 646 expected_acks.insert(5); | 575 expected_acks.insert(5); |
| 647 | 576 |
| 648 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); | 577 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); |
| 649 SendAckPacket(&frame1); | 578 ProcessAckPacket(&frame1); |
| 650 | 579 |
| 651 // Now the client implicitly acks 2, and explicitly acks 6 | 580 // Now the client implicitly acks 2, and explicitly acks 6 |
| 652 QuicAckFrame frame2(6, QuicTime(), 0); | 581 QuicAckFrame frame2(6, QuicTime(), 0); |
| 653 expected_acks.clear(); | 582 expected_acks.clear(); |
| 654 // Both acks should be passed up. | 583 // Both acks should be passed up. |
| 655 expected_acks.insert(2); | 584 expected_acks.insert(2); |
| 656 expected_acks.insert(6); | 585 expected_acks.insert(6); |
| 657 | 586 |
| 658 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); | 587 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); |
| 659 SendAckPacket(&frame2); | 588 ProcessAckPacket(&frame2); |
| 660 } | 589 } |
| 661 | 590 |
| 662 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterFecPacket) { | 591 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterFecPacket) { |
| 663 // Don't send missing packet 1. | 592 // Don't send missing packet 1. |
| 664 ProcessFecPacket(2, 1, true); | 593 ProcessFecPacket(2, 1, true); |
| 665 } | 594 } |
| 666 | 595 |
| 667 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacketThenFecPacket) { | 596 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacketThenFecPacket) { |
| 668 ProcessFecProtectedPacket(1, false); | 597 ProcessFecProtectedPacket(1, false); |
| 669 // Don't send missing packet 2. | 598 // Don't send missing packet 2. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 693 } | 622 } |
| 694 | 623 |
| 695 TEST_F(QuicConnectionTest, TestResend) { | 624 TEST_F(QuicConnectionTest, TestResend) { |
| 696 // TODO(rch): make this work | 625 // TODO(rch): make this work |
| 697 // FLAGS_fake_packet_loss_percentage = 100; | 626 // FLAGS_fake_packet_loss_percentage = 100; |
| 698 const QuicTime::Delta kDefaultResendTime = | 627 const QuicTime::Delta kDefaultResendTime = |
| 699 QuicTime::Delta::FromMilliseconds(500); | 628 QuicTime::Delta::FromMilliseconds(500); |
| 700 | 629 |
| 701 QuicTime default_resend_time = clock_.Now().Add(kDefaultResendTime); | 630 QuicTime default_resend_time = clock_.Now().Add(kDefaultResendTime); |
| 702 | 631 |
| 703 connection_.SendStreamData(1, "foo", 0, false, NULL); | 632 SendStreamDataToPeer(1, "foo", 0, false, NULL); |
| 704 EXPECT_EQ(1u, last_header()->packet_sequence_number); | 633 EXPECT_EQ(1u, last_header()->packet_sequence_number); |
| 705 EXPECT_EQ(1u, helper_->resend_alarms().size()); | 634 EXPECT_EQ(1u, helper_->resend_alarms().size()); |
| 706 EXPECT_EQ(default_resend_time, | 635 EXPECT_EQ(default_resend_time, |
| 707 helper_->resend_alarms().find(1)->second); | 636 helper_->resend_alarms().find(1)->second); |
| 708 // Simulate the resend alarm firing | 637 // Simulate the resend alarm firing |
| 709 clock_.AdvanceTime(kDefaultResendTime); | 638 clock_.AdvanceTime(kDefaultResendTime); |
| 639 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)); |
| 710 connection_.MaybeResendPacket(1); | 640 connection_.MaybeResendPacket(1); |
| 711 EXPECT_EQ(2u, last_header()->packet_sequence_number); | 641 EXPECT_EQ(2u, last_header()->packet_sequence_number); |
| 712 } | 642 } |
| 713 | 643 |
| 714 // TODO(rch): Enable after we get non-blocking sockets. | 644 // TODO(rch): Enable after we get non-blocking sockets. |
| 715 TEST_F(QuicConnectionTest, DISABLED_TestQueued) { | 645 TEST_F(QuicConnectionTest, DISABLED_TestQueued) { |
| 716 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 646 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 717 helper_->set_blocked(true); | 647 helper_->set_blocked(true); |
| 718 connection_.SendStreamData(1, "foo", 0, false, NULL); | 648 SendStreamDataToPeer(1, "foo", 0, false, NULL); |
| 719 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 649 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 720 | 650 |
| 721 // Attempt to send all packets, but since we're actually still | 651 // Attempt to send all packets, but since we're actually still |
| 722 // blocked, they should all remain queued. | 652 // blocked, they should all remain queued. |
| 723 EXPECT_FALSE(connection_.OnCanWrite()); | 653 EXPECT_FALSE(connection_.OnCanWrite()); |
| 724 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 654 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 725 | 655 |
| 726 // Unblock the writes and actually send. | 656 // Unblock the writes and actually send. |
| 727 helper_->set_blocked(false); | 657 helper_->set_blocked(false); |
| 728 EXPECT_TRUE(connection_.OnCanWrite()); | 658 EXPECT_TRUE(connection_.OnCanWrite()); |
| 729 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 659 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 730 } | 660 } |
| 731 | 661 |
| 732 TEST_F(QuicConnectionTest, CloseFecGroup) { | 662 TEST_F(QuicConnectionTest, CloseFecGroup) { |
| 733 // Don't send missing packet 1 | 663 // Don't send missing packet 1 |
| 734 // Don't send missing packet 2 | 664 // Don't send missing packet 2 |
| 735 ProcessFecProtectedPacket(3, false); | 665 ProcessFecProtectedPacket(3, false); |
| 736 // Don't send missing FEC packet 3 | 666 // Don't send missing FEC packet 3 |
| 737 ASSERT_EQ(1u, connection_.NumFecGroups()); | 667 ASSERT_EQ(1u, connection_.NumFecGroups()); |
| 738 | 668 |
| 739 // Now send non-fec protected ack packet and close the group | 669 // Now send non-fec protected ack packet and close the group |
| 740 SendAckPacket(5); | 670 QuicAckFrame frame(0, QuicTime(), 5); |
| 671 ProcessAckPacket(&frame); |
| 741 ASSERT_EQ(0u, connection_.NumFecGroups()); | 672 ASSERT_EQ(0u, connection_.NumFecGroups()); |
| 742 } | 673 } |
| 743 | 674 |
| 744 TEST_F(QuicConnectionTest, NoCongestionInfo) { | 675 TEST_F(QuicConnectionTest, NoCongestionInfo) { |
| 745 TestCollector* collector(new TestCollector(NULL)); | 676 TestCollector* collector(new TestCollector(NULL)); |
| 746 connection_.SetCollector(collector); | 677 connection_.SetCollector(collector); |
| 747 connection_.SendAck(); | 678 SendAckPacketToPeer(); |
| 748 EXPECT_EQ(kNone, last_frame()->congestion_info.type); | 679 EXPECT_EQ(kNone, last_frame()->congestion_info.type); |
| 749 } | 680 } |
| 750 | 681 |
| 751 TEST_F(QuicConnectionTest, WithCongestionInfo) { | 682 TEST_F(QuicConnectionTest, WithCongestionInfo) { |
| 752 CongestionInfo info; | 683 CongestionInfo info; |
| 753 info.type = kFixRate; | 684 info.type = kFixRate; |
| 754 info.fix_rate.bitrate_in_bytes_per_second = 123; | 685 info.fix_rate.bitrate_in_bytes_per_second = 123; |
| 755 TestCollector* collector(new TestCollector(&info)); | 686 TestCollector* collector(new TestCollector(&info)); |
| 756 connection_.SetCollector(collector); | 687 connection_.SetCollector(collector); |
| 757 connection_.SendAck(); | 688 SendAckPacketToPeer(); |
| 758 EXPECT_EQ(kFixRate, last_frame()->congestion_info.type); | 689 EXPECT_EQ(kFixRate, last_frame()->congestion_info.type); |
| 759 EXPECT_EQ(info.fix_rate.bitrate_in_bytes_per_second, | 690 EXPECT_EQ(info.fix_rate.bitrate_in_bytes_per_second, |
| 760 last_frame()->congestion_info.fix_rate.bitrate_in_bytes_per_second); | 691 last_frame()->congestion_info.fix_rate.bitrate_in_bytes_per_second); |
| 761 } | 692 } |
| 762 | 693 |
| 763 TEST_F(QuicConnectionTest, UpdateCongestionInfo) { | 694 TEST_F(QuicConnectionTest, UpdateCongestionInfo) { |
| 764 TestCollector* collector(new TestCollector(NULL)); | 695 TestCollector* collector(new TestCollector(NULL)); |
| 765 connection_.SetCollector(collector); | 696 connection_.SetCollector(collector); |
| 766 connection_.SendAck(); | 697 SendAckPacketToPeer(); |
| 767 EXPECT_CALL(*collector, RecordIncomingPacket(_, _, _, _)); | 698 EXPECT_CALL(*collector, RecordIncomingPacket(_, _, _, _)); |
| 768 ProcessPacket(1); | 699 ProcessPacket(1); |
| 769 } | 700 } |
| 770 | 701 |
| 771 TEST_F(QuicConnectionTest, DontUpdateCongestionInfoForRevived) { | 702 TEST_F(QuicConnectionTest, DontUpdateCongestionInfoForRevived) { |
| 772 TestCollector* collector(new TestCollector(NULL)); | 703 TestCollector* collector(new TestCollector(NULL)); |
| 773 connection_.SetCollector(collector); | 704 connection_.SetCollector(collector); |
| 774 connection_.SendAck(); | 705 SendAckPacketToPeer(); |
| 775 // Process an FEC packet, and revive the missing data packet | 706 // Process an FEC packet, and revive the missing data packet |
| 776 // but only contact the collector once. | 707 // but only contact the collector once. |
| 777 EXPECT_CALL(*collector, RecordIncomingPacket(_, _, _, _)); | 708 EXPECT_CALL(*collector, RecordIncomingPacket(_, _, _, _)); |
| 778 ProcessFecPacket(2, 1, true); | 709 ProcessFecPacket(2, 1, true); |
| 779 } | 710 } |
| 780 | 711 |
| 781 TEST_F(QuicConnectionTest, InitialTimeout) { | 712 TEST_F(QuicConnectionTest, InitialTimeout) { |
| 782 EXPECT_TRUE(connection_.connected()); | 713 EXPECT_TRUE(connection_.connected()); |
| 783 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, false)); | 714 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, false)); |
| 715 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)); |
| 784 | 716 |
| 785 QuicTime default_timeout = clock_.Now().Add( | 717 QuicTime default_timeout = clock_.Now().Add( |
| 786 QuicTime::Delta::FromMicroseconds(kDefaultTimeoutUs)); | 718 QuicTime::Delta::FromMicroseconds(kDefaultTimeoutUs)); |
| 787 EXPECT_EQ(default_timeout, helper_->timeout_alarm()); | 719 EXPECT_EQ(default_timeout, helper_->timeout_alarm()); |
| 788 | 720 |
| 789 // Simulate the timeout alarm firing | 721 // Simulate the timeout alarm firing |
| 790 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(kDefaultTimeoutUs)); | 722 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(kDefaultTimeoutUs)); |
| 791 EXPECT_TRUE(connection_.CheckForTimeout()); | 723 EXPECT_TRUE(connection_.CheckForTimeout()); |
| 792 EXPECT_FALSE(connection_.connected()); | 724 EXPECT_FALSE(connection_.connected()); |
| 793 } | 725 } |
| 794 | 726 |
| 795 TEST_F(QuicConnectionTest, TimeoutAfterSend) { | 727 TEST_F(QuicConnectionTest, TimeoutAfterSend) { |
| 796 EXPECT_TRUE(connection_.connected()); | 728 EXPECT_TRUE(connection_.connected()); |
| 797 | 729 |
| 798 QuicTime default_timeout = clock_.Now().Add( | 730 QuicTime default_timeout = clock_.Now().Add( |
| 799 QuicTime::Delta::FromMicroseconds(kDefaultTimeoutUs)); | 731 QuicTime::Delta::FromMicroseconds(kDefaultTimeoutUs)); |
| 800 | 732 |
| 801 // When we send a packet, the timeout will change to 5000 + kDefaultTimeout. | 733 // When we send a packet, the timeout will change to 5000 + kDefaultTimeout. |
| 802 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); | 734 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); |
| 803 | 735 |
| 804 // Send an ack so we don't set the resend alarm. | 736 // Send an ack so we don't set the resend alarm. |
| 805 connection_.SendAck(); | 737 SendAckPacketToPeer(); |
| 806 EXPECT_EQ(default_timeout, helper_->timeout_alarm()); | 738 EXPECT_EQ(default_timeout, helper_->timeout_alarm()); |
| 807 | 739 |
| 808 // The original alarm will fire. We should not time out because we had a | 740 // The original alarm will fire. We should not time out because we had a |
| 809 // network event at t=5000. The alarm will reregister. | 741 // network event at t=5000. The alarm will reregister. |
| 810 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds( | 742 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds( |
| 811 kDefaultTimeoutUs - 5000)); | 743 kDefaultTimeoutUs - 5000)); |
| 812 EXPECT_EQ(default_timeout, clock_.Now()); | 744 EXPECT_EQ(default_timeout, clock_.Now()); |
| 813 EXPECT_FALSE(connection_.CheckForTimeout()); | 745 EXPECT_FALSE(connection_.CheckForTimeout()); |
| 814 EXPECT_TRUE(connection_.connected()); | 746 EXPECT_TRUE(connection_.connected()); |
| 815 EXPECT_EQ(default_timeout.Add(QuicTime::Delta::FromMilliseconds(5)), | 747 EXPECT_EQ(default_timeout.Add(QuicTime::Delta::FromMilliseconds(5)), |
| 816 helper_->timeout_alarm()); | 748 helper_->timeout_alarm()); |
| 817 | 749 |
| 818 // This time, we should time out. | 750 // This time, we should time out. |
| 819 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, false)); | 751 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, false)); |
| 752 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)); |
| 820 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); | 753 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); |
| 821 EXPECT_EQ(default_timeout.Add(QuicTime::Delta::FromMilliseconds(5)), | 754 EXPECT_EQ(default_timeout.Add(QuicTime::Delta::FromMilliseconds(5)), |
| 822 clock_.Now()); | 755 clock_.Now()); |
| 823 EXPECT_TRUE(connection_.CheckForTimeout()); | 756 EXPECT_TRUE(connection_.CheckForTimeout()); |
| 824 EXPECT_FALSE(connection_.connected()); | 757 EXPECT_FALSE(connection_.connected()); |
| 825 } | 758 } |
| 826 | 759 |
| 827 // TODO(ianswett): Add scheduler tests when resend is false. | 760 // TODO(ianswett): Add scheduler tests when resend is false. |
| 828 TEST_F(QuicConnectionTest, SendScheduler) { | 761 TEST_F(QuicConnectionTest, SendScheduler) { |
| 829 // Test that if we send a packet without delay, it is not queued. | 762 // Test that if we send a packet without delay, it is not queued. |
| 830 scoped_ptr<QuicPacket> packet(ConstructDataPacket(1, 0)); | 763 scoped_ptr<QuicPacket> packet(ConstructDataPacket(1, 0)); |
| 831 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).WillOnce(testing::Return( | 764 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).WillOnce(testing::Return( |
| 832 QuicTime::Delta())); | 765 QuicTime::Delta())); |
| 766 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)); |
| 833 connection_.SendPacket(1, packet.get(), true, false, false); | 767 connection_.SendPacket(1, packet.get(), true, false, false); |
| 834 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 768 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 835 } | 769 } |
| 836 | 770 |
| 837 TEST_F(QuicConnectionTest, SendSchedulerDelay) { | 771 TEST_F(QuicConnectionTest, SendSchedulerDelay) { |
| 838 // Test that if we send a packet with a delay, it ends up queued. | 772 // Test that if we send a packet with a delay, it ends up queued. |
| 839 scoped_ptr<QuicPacket> packet(ConstructDataPacket(1, 0)); | 773 scoped_ptr<QuicPacket> packet(ConstructDataPacket(1, 0)); |
| 840 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).WillOnce(testing::Return( | 774 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).WillOnce(testing::Return( |
| 841 QuicTime::Delta::FromMicroseconds(1))); | 775 QuicTime::Delta::FromMicroseconds(1))); |
| 842 EXPECT_CALL(*scheduler_, SentPacket(1, _, _)).Times(0); | 776 EXPECT_CALL(*scheduler_, SentPacket(1, _, _)).Times(0); |
| 843 connection_.SendPacket(1, packet.get(), true, false, false); | 777 connection_.SendPacket(1, packet.get(), true, false, false); |
| 844 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 778 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 845 } | 779 } |
| 846 | 780 |
| 847 TEST_F(QuicConnectionTest, SendSchedulerForce) { | 781 TEST_F(QuicConnectionTest, SendSchedulerForce) { |
| 848 // Test that if we force send a packet, it is not queued. | 782 // Test that if we force send a packet, it is not queued. |
| 849 scoped_ptr<QuicPacket> packet(ConstructDataPacket(1, 0)); | 783 scoped_ptr<QuicPacket> packet(ConstructDataPacket(1, 0)); |
| 850 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).Times(0); | 784 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).Times(0); |
| 785 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)); |
| 851 connection_.SendPacket(1, packet.get(), true, true, false); | 786 connection_.SendPacket(1, packet.get(), true, true, false); |
| 852 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 787 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 853 } | 788 } |
| 854 | 789 |
| 855 // TODO(rch): Enable after we get non-blocking sockets. | 790 // TODO(rch): Enable after we get non-blocking sockets. |
| 856 TEST_F(QuicConnectionTest, DISABLED_SendSchedulerEAGAIN) { | 791 TEST_F(QuicConnectionTest, DISABLED_SendSchedulerEAGAIN) { |
| 857 scoped_ptr<QuicPacket> packet(ConstructDataPacket(1, 0)); | 792 scoped_ptr<QuicPacket> packet(ConstructDataPacket(1, 0)); |
| 858 helper_->set_blocked(true); | 793 helper_->set_blocked(true); |
| 859 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).WillOnce(testing::Return( | 794 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).WillOnce(testing::Return( |
| 860 QuicTime::Delta())); | 795 QuicTime::Delta())); |
| 861 EXPECT_CALL(*scheduler_, SentPacket(1, _, _)).Times(0); | 796 EXPECT_CALL(*scheduler_, SentPacket(1, _, _)).Times(0); |
| 862 connection_.SendPacket(1, packet.get(), true, false, false); | 797 connection_.SendPacket(1, packet.get(), true, false, false); |
| 863 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 798 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 864 } | 799 } |
| 865 | 800 |
| 866 TEST_F(QuicConnectionTest, SendSchedulerDelayThenSend) { | 801 TEST_F(QuicConnectionTest, SendSchedulerDelayThenSend) { |
| 867 // Test that if we send a packet with a delay, it ends up queued. | 802 // Test that if we send a packet with a delay, it ends up queued. |
| 868 scoped_ptr<QuicPacket> packet(ConstructDataPacket(1, 0)); | 803 scoped_ptr<QuicPacket> packet(ConstructDataPacket(1, 0)); |
| 869 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).WillOnce(testing::Return( | 804 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).WillOnce(testing::Return( |
| 870 QuicTime::Delta::FromMicroseconds(1))); | 805 QuicTime::Delta::FromMicroseconds(1))); |
| 871 connection_.SendPacket(1, packet.get(), true, false, false); | 806 connection_.SendPacket(1, packet.get(), true, false, false); |
| 872 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 807 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 873 | 808 |
| 874 // Advance the clock to fire the alarm, and configure the scheduler | 809 // Advance the clock to fire the alarm, and configure the scheduler |
| 875 // to permit the packet to be sent. | 810 // to permit the packet to be sent. |
| 876 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).WillOnce(testing::Return( | 811 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).WillOnce(testing::Return( |
| 877 QuicTime::Delta())); | 812 QuicTime::Delta())); |
| 878 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1)); | 813 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1)); |
| 814 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)); |
| 879 connection_.OnCanWrite(); | 815 connection_.OnCanWrite(); |
| 880 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 816 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 881 } | 817 } |
| 882 | 818 |
| 883 TEST_F(QuicConnectionTest, SendSchedulerDelayThenRetransmit) { | 819 TEST_F(QuicConnectionTest, SendSchedulerDelayThenRetransmit) { |
| 884 // Test that if we send a retransmit with a delay, it ends up queued. | 820 // Test that if we send a retransmit with a delay, it ends up queued. |
| 885 scoped_ptr<QuicPacket> packet(ConstructDataPacket(1, 0)); | 821 scoped_ptr<QuicPacket> packet(ConstructDataPacket(1, 0)); |
| 886 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).WillOnce(testing::Return( | 822 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).WillOnce(testing::Return( |
| 887 QuicTime::Delta::FromMicroseconds(1))); | 823 QuicTime::Delta::FromMicroseconds(1))); |
| 888 connection_.SendPacket(1, packet.get(), true, false, true); | 824 connection_.SendPacket(1, packet.get(), true, false, true); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 915 TEST_F(QuicConnectionTest, SendSchedulerDelayThenAckAndSend) { | 851 TEST_F(QuicConnectionTest, SendSchedulerDelayThenAckAndSend) { |
| 916 scoped_ptr<QuicPacket> packet(ConstructDataPacket(1, 0)); | 852 scoped_ptr<QuicPacket> packet(ConstructDataPacket(1, 0)); |
| 917 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).WillOnce(testing::Return( | 853 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).WillOnce(testing::Return( |
| 918 QuicTime::Delta::FromMicroseconds(10))); | 854 QuicTime::Delta::FromMicroseconds(10))); |
| 919 connection_.SendPacket(1, packet.get(), true, false, false); | 855 connection_.SendPacket(1, packet.get(), true, false, false); |
| 920 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 856 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 921 | 857 |
| 922 // Now send non-retransmitting information, that we're not going to resend 3. | 858 // Now send non-retransmitting information, that we're not going to resend 3. |
| 923 // The far end should stop waiting for it. | 859 // The far end should stop waiting for it. |
| 924 QuicAckFrame frame(0, QuicTime(), 1); | 860 QuicAckFrame frame(0, QuicTime(), 1); |
| 925 frame.sent_info.non_retransmiting.insert(3); | |
| 926 EXPECT_CALL(*scheduler_, OnIncomingAckFrame(testing::_)); | |
| 927 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).WillRepeatedly(testing::Return( | 861 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).WillRepeatedly(testing::Return( |
| 928 QuicTime::Delta())); | 862 QuicTime::Delta())); |
| 929 SendAckPacket(&frame); | 863 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)); |
| 864 ProcessAckPacket(&frame); |
| 930 | 865 |
| 931 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 866 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 932 // Ensure alarm is not set | 867 // Ensure alarm is not set |
| 933 EXPECT_FALSE(helper_->IsSendAlarmSet()); | 868 EXPECT_FALSE(helper_->IsSendAlarmSet()); |
| 934 } | 869 } |
| 935 | 870 |
| 936 TEST_F(QuicConnectionTest, SendSchedulerDelayThenAckAndHold) { | 871 TEST_F(QuicConnectionTest, SendSchedulerDelayThenAckAndHold) { |
| 937 scoped_ptr<QuicPacket> packet(ConstructDataPacket(1, 0)); | 872 scoped_ptr<QuicPacket> packet(ConstructDataPacket(1, 0)); |
| 938 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).WillOnce(testing::Return( | 873 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).WillOnce(testing::Return( |
| 939 QuicTime::Delta::FromMicroseconds(10))); | 874 QuicTime::Delta::FromMicroseconds(10))); |
| 940 connection_.SendPacket(1, packet.get(), true, false, false); | 875 connection_.SendPacket(1, packet.get(), true, false, false); |
| 941 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 876 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 942 | 877 |
| 943 // Now send non-resending information, that we're not going to resend 3. | 878 // Now send non-resending information, that we're not going to resend 3. |
| 944 // The far end should stop waiting for it. | 879 // The far end should stop waiting for it. |
| 945 QuicAckFrame frame(0, QuicTime(), 1); | 880 QuicAckFrame frame(0, QuicTime(), 1); |
| 946 frame.sent_info.non_retransmiting.insert(3); | |
| 947 EXPECT_CALL(*scheduler_, OnIncomingAckFrame(testing::_)); | |
| 948 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).WillOnce(testing::Return( | 881 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).WillOnce(testing::Return( |
| 949 QuicTime::Delta::FromMicroseconds(1))); | 882 QuicTime::Delta::FromMicroseconds(1))); |
| 950 SendAckPacket(&frame); | 883 ProcessAckPacket(&frame); |
| 951 | 884 |
| 952 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 885 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 953 } | 886 } |
| 954 | 887 |
| 955 TEST_F(QuicConnectionTest, SendSchedulerDelayThenOnCanWrite) { | 888 TEST_F(QuicConnectionTest, SendSchedulerDelayThenOnCanWrite) { |
| 956 scoped_ptr<QuicPacket> packet(ConstructDataPacket(1, 0)); | 889 scoped_ptr<QuicPacket> packet(ConstructDataPacket(1, 0)); |
| 957 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).WillOnce(testing::Return( | 890 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).WillOnce(testing::Return( |
| 958 QuicTime::Delta::FromMicroseconds(10))); | 891 QuicTime::Delta::FromMicroseconds(10))); |
| 959 connection_.SendPacket(1, packet.get(), true, false, false); | 892 connection_.SendPacket(1, packet.get(), true, false, false); |
| 960 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 893 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 961 | 894 |
| 962 // OnCanWrite should not send the packet (because of the delay) | 895 // OnCanWrite should not send the packet (because of the delay) |
| 963 // but should still return true. | 896 // but should still return true. |
| 964 EXPECT_TRUE(connection_.OnCanWrite()); | 897 EXPECT_TRUE(connection_.OnCanWrite()); |
| 965 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 898 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 966 } | 899 } |
| 967 | 900 |
| 968 } // namespace | 901 } // namespace |
| 969 } // namespace test | 902 } // namespace test |
| 970 } // namespace net | 903 } // namespace net |
| OLD | NEW |