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