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

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

Issue 23597045: Land Recent QUIC changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged QuicPriority to RequestPriority changes Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_connection.cc ('k') | net/quic/quic_connection_logger.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/quic/quic_connection_helper.h" 5 #include "net/quic/quic_connection_helper.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "net/base/net_errors.h" 9 #include "net/base/net_errors.h"
10 #include "net/quic/crypto/quic_decrypter.h" 10 #include "net/quic/crypto/quic_decrypter.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 runner_ = new TestTaskRunner(&clock_); 118 runner_ = new TestTaskRunner(&clock_);
119 helper_ = new QuicConnectionHelper(runner_.get(), &clock_, 119 helper_ = new QuicConnectionHelper(runner_.get(), &clock_,
120 &random_generator_, socket_.get()); 120 &random_generator_, socket_.get());
121 send_algorithm_ = new testing::StrictMock<MockSendAlgorithm>(); 121 send_algorithm_ = new testing::StrictMock<MockSendAlgorithm>();
122 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _, _)). 122 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _, _)).
123 WillRepeatedly(testing::Return(QuicTime::Delta::Zero())); 123 WillRepeatedly(testing::Return(QuicTime::Delta::Zero()));
124 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillRepeatedly( 124 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillRepeatedly(
125 testing::Return(QuicBandwidth::FromKBitsPerSecond(100))); 125 testing::Return(QuicBandwidth::FromKBitsPerSecond(100)));
126 EXPECT_CALL(*send_algorithm_, SmoothedRtt()).WillRepeatedly( 126 EXPECT_CALL(*send_algorithm_, SmoothedRtt()).WillRepeatedly(
127 testing::Return(QuicTime::Delta::FromMilliseconds(100))); 127 testing::Return(QuicTime::Delta::FromMilliseconds(100)));
128 ON_CALL(*send_algorithm_, SentPacket(_, _, _, _, _))
129 .WillByDefault(testing::Return(true));
128 connection_.reset(new TestConnection(guid_, IPEndPoint(), helper_)); 130 connection_.reset(new TestConnection(guid_, IPEndPoint(), helper_));
129 connection_->set_visitor(&visitor_); 131 connection_->set_visitor(&visitor_);
130 connection_->SetSendAlgorithm(send_algorithm_); 132 connection_->SetSendAlgorithm(send_algorithm_);
131 } 133 }
132 134
133 // Returns a newly created packet to send kData on stream 1. 135 // Returns a newly created packet to send kData on stream 1.
134 QuicEncryptedPacket* ConstructDataPacket( 136 QuicEncryptedPacket* ConstructDataPacket(
135 QuicPacketSequenceNumber sequence_number) { 137 QuicPacketSequenceNumber sequence_number) {
136 InitializeHeader(sequence_number); 138 InitializeHeader(sequence_number);
137 139
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 AddWrite(SYNCHRONOUS, ConstructDataPacket(2)); 310 AddWrite(SYNCHRONOUS, ConstructDataPacket(2));
309 Initialize(); 311 Initialize();
310 312
311 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly( 313 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly(
312 testing::Return(QuicTime::Delta::Zero())); 314 testing::Return(QuicTime::Delta::Zero()));
313 315
314 QuicTime::Delta kDefaultRetransmissionTime = 316 QuicTime::Delta kDefaultRetransmissionTime =
315 QuicTime::Delta::FromMilliseconds(500); 317 QuicTime::Delta::FromMilliseconds(500);
316 QuicTime start = clock_.ApproximateNow(); 318 QuicTime start = clock_.ApproximateNow();
317 319
318 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION)); 320 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION, _));
319 EXPECT_CALL(*send_algorithm_, AbandoningPacket(1, _)); 321 EXPECT_CALL(*send_algorithm_, AbandoningPacket(1, _));
320 322
321 // Send a packet. 323 // Send a packet.
322 connection_->SendStreamData(1, kData, 0, false); 324 struct iovec iov = {const_cast<char*>(kData),
323 EXPECT_CALL(*send_algorithm_, SentPacket(_, 2, _, IS_RETRANSMISSION)); 325 static_cast<size_t>(strlen(kData))};
326 connection_->SendvStreamData(1, &iov, 1, 0, false);
327 EXPECT_CALL(*send_algorithm_, SentPacket(_, 2, _, IS_RETRANSMISSION, _));
324 // Since no ack was received, the retransmission alarm will fire and 328 // Since no ack was received, the retransmission alarm will fire and
325 // retransmit it. 329 // retransmit it.
326 runner_->RunNextTask(); 330 runner_->RunNextTask();
327 331
328 EXPECT_EQ(kDefaultRetransmissionTime, 332 EXPECT_EQ(kDefaultRetransmissionTime,
329 clock_.ApproximateNow().Subtract(start)); 333 clock_.ApproximateNow().Subtract(start));
330 EXPECT_TRUE(AtEof()); 334 EXPECT_TRUE(AtEof());
331 } 335 }
332 336
333 TEST_F(QuicConnectionHelperTest, TestMultipleRetransmission) { 337 TEST_F(QuicConnectionHelperTest, TestMultipleRetransmission) {
334 AddWrite(SYNCHRONOUS, ConstructDataPacket(1)); 338 AddWrite(SYNCHRONOUS, ConstructDataPacket(1));
335 AddWrite(SYNCHRONOUS, ConstructDataPacket(2)); 339 AddWrite(SYNCHRONOUS, ConstructDataPacket(2));
336 AddWrite(SYNCHRONOUS, ConstructDataPacket(3)); 340 AddWrite(SYNCHRONOUS, ConstructDataPacket(3));
337 Initialize(); 341 Initialize();
338 342
339 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly( 343 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly(
340 testing::Return(QuicTime::Delta::Zero())); 344 testing::Return(QuicTime::Delta::Zero()));
341 345
342 QuicTime::Delta kDefaultRetransmissionTime = 346 QuicTime::Delta kDefaultRetransmissionTime =
343 QuicTime::Delta::FromMilliseconds(500); 347 QuicTime::Delta::FromMilliseconds(500);
344 QuicTime start = clock_.ApproximateNow(); 348 QuicTime start = clock_.ApproximateNow();
345 349
346 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION)); 350 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION, _));
347 EXPECT_CALL(*send_algorithm_, AbandoningPacket(1, _)); 351 EXPECT_CALL(*send_algorithm_, AbandoningPacket(1, _));
352
348 // Send a packet. 353 // Send a packet.
349 connection_->SendStreamData(1, kData, 0, false); 354 struct iovec iov = {const_cast<char*>(kData),
350 EXPECT_CALL(*send_algorithm_, SentPacket(_, 2, _, IS_RETRANSMISSION)); 355 static_cast<size_t>(strlen(kData))};
356 connection_->SendvStreamData(1, &iov, 1, 0, false);
357 EXPECT_CALL(*send_algorithm_, SentPacket(_, 2, _, IS_RETRANSMISSION, _));
351 // Since no ack was received, the retransmission alarm will fire and 358 // Since no ack was received, the retransmission alarm will fire and
352 // retransmit it. 359 // retransmit it.
353 runner_->RunNextTask(); 360 runner_->RunNextTask();
354 361
355 EXPECT_EQ(kDefaultRetransmissionTime, 362 EXPECT_EQ(kDefaultRetransmissionTime,
356 clock_.ApproximateNow().Subtract(start)); 363 clock_.ApproximateNow().Subtract(start));
357 364
358 // Since no ack was received, the retransmission alarm will fire and 365 // Since no ack was received, the retransmission alarm will fire and
359 // retransmit it. 366 // retransmit it.
360 EXPECT_CALL(*send_algorithm_, SentPacket(_, 3, _, IS_RETRANSMISSION)); 367 EXPECT_CALL(*send_algorithm_, SentPacket(_, 3, _, IS_RETRANSMISSION, _));
361 EXPECT_CALL(*send_algorithm_, AbandoningPacket(2, _)); 368 EXPECT_CALL(*send_algorithm_, AbandoningPacket(2, _));
362 runner_->RunNextTask(); 369 runner_->RunNextTask();
363 370
364 EXPECT_EQ(kDefaultRetransmissionTime.Add(kDefaultRetransmissionTime), 371 EXPECT_EQ(kDefaultRetransmissionTime.Add(kDefaultRetransmissionTime),
365 clock_.ApproximateNow().Subtract(start)); 372 clock_.ApproximateNow().Subtract(start));
366 373
367 EXPECT_TRUE(AtEof()); 374 EXPECT_TRUE(AtEof());
368 } 375 }
369 376
370 TEST_F(QuicConnectionHelperTest, InitialTimeout) { 377 TEST_F(QuicConnectionHelperTest, InitialTimeout) {
371 AddWrite(SYNCHRONOUS, ConstructClosePacket(1, 0)); 378 AddWrite(SYNCHRONOUS, ConstructClosePacket(1, 0));
372 Initialize(); 379 Initialize();
373 380
374 // Verify that a single task was posted. 381 // Verify that a single task was posted.
375 ASSERT_EQ(1u, runner_->GetPostedTasks().size()); 382 ASSERT_EQ(1u, runner_->GetPostedTasks().size());
376 EXPECT_EQ(base::TimeDelta::FromSeconds(kDefaultInitialTimeoutSecs), 383 EXPECT_EQ(base::TimeDelta::FromSeconds(kDefaultInitialTimeoutSecs),
377 runner_->GetPostedTasks().front().delay); 384 runner_->GetPostedTasks().front().delay);
378 385
379 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION)); 386 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION, _));
380 // After we run the next task, we should close the connection. 387 // After we run the next task, we should close the connection.
381 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, false)); 388 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, false));
382 389
383 runner_->RunNextTask(); 390 runner_->RunNextTask();
384 EXPECT_EQ(QuicTime::Zero().Add(QuicTime::Delta::FromSeconds( 391 EXPECT_EQ(QuicTime::Zero().Add(QuicTime::Delta::FromSeconds(
385 kDefaultInitialTimeoutSecs)), 392 kDefaultInitialTimeoutSecs)),
386 clock_.ApproximateNow()); 393 clock_.ApproximateNow());
387 EXPECT_FALSE(connection_->connected()); 394 EXPECT_FALSE(connection_->connected());
388 EXPECT_TRUE(AtEof()); 395 EXPECT_TRUE(AtEof());
389 } 396 }
(...skipping 26 matching lines...) Expand all
416 AddWrite(SYNCHRONOUS, ConstructClosePacket(2, 1)); 423 AddWrite(SYNCHRONOUS, ConstructClosePacket(2, 1));
417 Initialize(); 424 Initialize();
418 425
419 EXPECT_TRUE(connection_->connected()); 426 EXPECT_TRUE(connection_->connected());
420 QuicTime start = clock_.ApproximateNow(); 427 QuicTime start = clock_.ApproximateNow();
421 428
422 // When we send a packet, the timeout will change to 5000 + 429 // When we send a packet, the timeout will change to 5000 +
423 // kDefaultInitialTimeoutSecs. 430 // kDefaultInitialTimeoutSecs.
424 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(5000)); 431 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(5000));
425 EXPECT_EQ(5000u, clock_.ApproximateNow().Subtract(start).ToMicroseconds()); 432 EXPECT_EQ(5000u, clock_.ApproximateNow().Subtract(start).ToMicroseconds());
426 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION)); 433 EXPECT_CALL(*send_algorithm_,
434 SentPacket(_, 1, _, NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA));
427 435
428 // Send an ack so we don't set the retransmission alarm. 436 // Send an ack so we don't set the retransmission alarm.
429 connection_->SendAck(); 437 connection_->SendAck();
430 438
431 // The original alarm will fire. We should not time out because we had a 439 // The original alarm will fire. We should not time out because we had a
432 // network event at t=5000. The alarm will reregister. 440 // network event at t=5000. The alarm will reregister.
433 runner_->RunNextTask(); 441 runner_->RunNextTask();
434 442
435 EXPECT_EQ(QuicTime::Zero().Add(QuicTime::Delta::FromSeconds( 443 EXPECT_EQ(QuicTime::Zero().Add(QuicTime::Delta::FromSeconds(
436 kDefaultInitialTimeoutSecs)), 444 kDefaultInitialTimeoutSecs)),
437 clock_.ApproximateNow()); 445 clock_.ApproximateNow());
438 EXPECT_TRUE(connection_->connected()); 446 EXPECT_TRUE(connection_->connected());
439 447
440 // This time, we should time out. 448 // This time, we should time out.
441 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, !kFromPeer)); 449 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, !kFromPeer));
442 EXPECT_CALL(*send_algorithm_, SentPacket(_, 2, _, NOT_RETRANSMISSION)); 450 EXPECT_CALL(*send_algorithm_,
451 SentPacket(_, 2, _, NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA));
443 runner_->RunNextTask(); 452 runner_->RunNextTask();
444 EXPECT_EQ(kDefaultInitialTimeoutSecs * 1000000 + 5000, 453 EXPECT_EQ(kDefaultInitialTimeoutSecs * 1000000 + 5000,
445 clock_.ApproximateNow().Subtract( 454 clock_.ApproximateNow().Subtract(
446 QuicTime::Zero()).ToMicroseconds()); 455 QuicTime::Zero()).ToMicroseconds());
447 EXPECT_FALSE(connection_->connected()); 456 EXPECT_FALSE(connection_->connected());
448 EXPECT_TRUE(AtEof()); 457 EXPECT_TRUE(AtEof());
449 } 458 }
450 459
451 TEST_F(QuicConnectionHelperTest, SendSchedulerDelayThenSend) { 460 TEST_F(QuicConnectionHelperTest, SendSchedulerDelayThenSend) {
452 AddWrite(SYNCHRONOUS, ConstructDataPacket(1)); 461 AddWrite(SYNCHRONOUS, ConstructDataPacket(1));
453 Initialize(); 462 Initialize();
454 463
455 // Test that if we send a packet with a delay, it ends up queued. 464 // Test that if we send a packet with a delay, it ends up queued.
456 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly( 465 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly(
457 testing::Return(QuicTime::Delta::Zero())); 466 testing::Return(QuicTime::Delta::Zero()));
458 EXPECT_CALL( 467 EXPECT_CALL(
459 *send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( 468 *send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce(
460 testing::Return(QuicTime::Delta::FromMicroseconds(1))); 469 testing::Return(QuicTime::Delta::FromMicroseconds(1)));
461 470
462 QuicPacket* packet = ConstructRawDataPacket(1); 471 QuicPacket* packet = ConstructRawDataPacket(1);
463 connection_->SendOrQueuePacket( 472 connection_->SendOrQueuePacket(ENCRYPTION_NONE, 1, packet, 0,
464 ENCRYPTION_NONE, 1, packet, 0, HAS_RETRANSMITTABLE_DATA); 473 HAS_RETRANSMITTABLE_DATA);
465 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION)); 474 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION,
475 _));
466 EXPECT_EQ(1u, connection_->NumQueuedPackets()); 476 EXPECT_EQ(1u, connection_->NumQueuedPackets());
467 477
468 // Advance the clock to fire the alarm, and configure the scheduler 478 // Advance the clock to fire the alarm, and configure the scheduler
469 // to permit the packet to be sent. 479 // to permit the packet to be sent.
470 EXPECT_CALL(*send_algorithm_, 480 EXPECT_CALL(*send_algorithm_,
471 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillRepeatedly( 481 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillRepeatedly(
472 testing::Return(QuicTime::Delta::Zero())); 482 testing::Return(QuicTime::Delta::Zero()));
473 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(testing::Return(true)); 483 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(testing::Return(true));
474 runner_->RunNextTask(); 484 runner_->RunNextTask();
475 EXPECT_EQ(0u, connection_->NumQueuedPackets()); 485 EXPECT_EQ(0u, connection_->NumQueuedPackets());
476 EXPECT_TRUE(AtEof()); 486 EXPECT_TRUE(AtEof());
477 } 487 }
478 488
479 } // namespace test 489 } // namespace test
480 } // namespace net 490 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection.cc ('k') | net/quic/quic_connection_logger.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698