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

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

Issue 243533003: Sent QUIC "PING" frames when a stream is open and the connection (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix comments Created 6 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/quic/quic_connection.h" 5 #include "net/quic/quic_connection.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 QuicPacketCreatorPeer::SetIsServer( 503 QuicPacketCreatorPeer::SetIsServer(
504 QuicConnectionPeer::GetPacketCreator(this), is_server); 504 QuicConnectionPeer::GetPacketCreator(this), is_server);
505 QuicConnectionPeer::SetIsServer(this, is_server); 505 QuicConnectionPeer::SetIsServer(this, is_server);
506 } 506 }
507 507
508 TestConnectionHelper::TestAlarm* GetAckAlarm() { 508 TestConnectionHelper::TestAlarm* GetAckAlarm() {
509 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( 509 return reinterpret_cast<TestConnectionHelper::TestAlarm*>(
510 QuicConnectionPeer::GetAckAlarm(this)); 510 QuicConnectionPeer::GetAckAlarm(this));
511 } 511 }
512 512
513 TestConnectionHelper::TestAlarm* GetPingAlarm() {
514 return reinterpret_cast<TestConnectionHelper::TestAlarm*>(
515 QuicConnectionPeer::GetPingAlarm(this));
516 }
517
518 TestConnectionHelper::TestAlarm* GetResumeWritesAlarm() {
519 return reinterpret_cast<TestConnectionHelper::TestAlarm*>(
520 QuicConnectionPeer::GetResumeWritesAlarm(this));
521 }
522
513 TestConnectionHelper::TestAlarm* GetRetransmissionAlarm() { 523 TestConnectionHelper::TestAlarm* GetRetransmissionAlarm() {
514 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( 524 return reinterpret_cast<TestConnectionHelper::TestAlarm*>(
515 QuicConnectionPeer::GetRetransmissionAlarm(this)); 525 QuicConnectionPeer::GetRetransmissionAlarm(this));
516 } 526 }
517 527
518 TestConnectionHelper::TestAlarm* GetSendAlarm() { 528 TestConnectionHelper::TestAlarm* GetSendAlarm() {
519 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( 529 return reinterpret_cast<TestConnectionHelper::TestAlarm*>(
520 QuicConnectionPeer::GetSendAlarm(this)); 530 QuicConnectionPeer::GetSendAlarm(this));
521 } 531 }
522 532
523 TestConnectionHelper::TestAlarm* GetResumeWritesAlarm() {
524 return reinterpret_cast<TestConnectionHelper::TestAlarm*>(
525 QuicConnectionPeer::GetResumeWritesAlarm(this));
526 }
527
528 TestConnectionHelper::TestAlarm* GetTimeoutAlarm() { 533 TestConnectionHelper::TestAlarm* GetTimeoutAlarm() {
529 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( 534 return reinterpret_cast<TestConnectionHelper::TestAlarm*>(
530 QuicConnectionPeer::GetTimeoutAlarm(this)); 535 QuicConnectionPeer::GetTimeoutAlarm(this));
531 } 536 }
532 537
533 using QuicConnection::SelectMutualVersion; 538 using QuicConnection::SelectMutualVersion;
534 539
535 private: 540 private:
536 TestPacketWriter* writer_; 541 TestPacketWriter* writer_;
537 542
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 .Times(AnyNumber()); 574 .Times(AnyNumber());
570 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly( 575 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly(
571 Return(QuicTime::Delta::Zero())); 576 Return(QuicTime::Delta::Zero()));
572 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( 577 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly(
573 Return(kMaxPacketSize)); 578 Return(kMaxPacketSize));
574 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)) 579 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _))
575 .WillByDefault(Return(true)); 580 .WillByDefault(Return(true));
576 EXPECT_CALL(visitor_, HasPendingWrites()).Times(AnyNumber()); 581 EXPECT_CALL(visitor_, HasPendingWrites()).Times(AnyNumber());
577 EXPECT_CALL(visitor_, HasPendingHandshake()).Times(AnyNumber()); 582 EXPECT_CALL(visitor_, HasPendingHandshake()).Times(AnyNumber());
578 EXPECT_CALL(visitor_, OnCanWrite()).Times(AnyNumber()); 583 EXPECT_CALL(visitor_, OnCanWrite()).Times(AnyNumber());
584 EXPECT_CALL(visitor_, HasOpenStreams()).WillRepeatedly(Return(false));
579 585
580 EXPECT_CALL(*loss_algorithm_, GetLossTimeout()) 586 EXPECT_CALL(*loss_algorithm_, GetLossTimeout())
581 .WillRepeatedly(Return(QuicTime::Zero())); 587 .WillRepeatedly(Return(QuicTime::Zero()));
582 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 588 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
583 .WillRepeatedly(Return(SequenceNumberSet())); 589 .WillRepeatedly(Return(SequenceNumberSet()));
584 } 590 }
585 591
586 QuicVersion version() { 592 QuicVersion version() {
587 return GetParam(); 593 return GetParam();
588 } 594 }
(...skipping 1980 matching lines...) Expand 10 before | Expand all | Expand 10 after
2569 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); 2575 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
2570 2576
2571 // Simulate the timeout alarm firing. 2577 // Simulate the timeout alarm firing.
2572 clock_.AdvanceTime( 2578 clock_.AdvanceTime(
2573 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)); 2579 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs));
2574 connection_.GetTimeoutAlarm()->Fire(); 2580 connection_.GetTimeoutAlarm()->Fire();
2575 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 2581 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
2576 EXPECT_FALSE(connection_.connected()); 2582 EXPECT_FALSE(connection_.connected());
2577 2583
2578 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 2584 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
2585 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet());
2579 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet()); 2586 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet());
2580 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 2587 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2581 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet()); 2588 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet());
2582 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 2589 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
2583 } 2590 }
2584 2591
2592 TEST_P(QuicConnectionTest, PingAfterSend) {
2593 EXPECT_TRUE(connection_.connected());
2594 EXPECT_CALL(visitor_, HasOpenStreams()).WillRepeatedly(Return(true));
2595 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet());
2596
2597 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5));
2598 // Send an ack so we don't set the retransmission alarm.
2599 SendAckPacketToPeer();
2600 QuicTime ping_timeout = clock_.ApproximateNow().Add(
2601 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs / 2));
2602 EXPECT_EQ(ping_timeout, connection_.GetPingAlarm()->deadline());
2603
2604 writer_->Reset();
2605 EXPECT_CALL(*send_algorithm_,
2606 TimeUntilSend(_, _)).WillRepeatedly(
2607 testing::Return(QuicTime::Delta::Zero()));
2608 connection_.GetPingAlarm()->Fire();
2609 EXPECT_EQ(1u, writer_->frame_count());
2610 EXPECT_EQ(1u, writer_->stream_frames()->size());
2611 EXPECT_EQ(kCryptoStreamId, (*writer_->stream_frames())[0].stream_id);
2612 EXPECT_EQ(0u, (*writer_->stream_frames())[0].offset);
2613 writer_->Reset();
2614
2615 EXPECT_CALL(visitor_, HasOpenStreams()).WillRepeatedly(Return(false));
2616 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5));
2617 SendAckPacketToPeer();
2618
2619 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet());
2620 }
2621
2585 TEST_P(QuicConnectionTest, TimeoutAfterSend) { 2622 TEST_P(QuicConnectionTest, TimeoutAfterSend) {
2586 EXPECT_TRUE(connection_.connected()); 2623 EXPECT_TRUE(connection_.connected());
2587 2624
2588 QuicTime default_timeout = clock_.ApproximateNow().Add( 2625 QuicTime default_timeout = clock_.ApproximateNow().Add(
2589 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)); 2626 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs));
2590 2627
2591 // When we send a packet, the timeout will change to 5000 + 2628 // When we send a packet, the timeout will change to 5000 +
2592 // kDefaultInitialTimeoutSecs. 2629 // kDefaultInitialTimeoutSecs.
2593 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); 2630 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5));
2594 2631
(...skipping 1356 matching lines...) Expand 10 before | Expand all | Expand 10 after
3951 TestConnection connection(connection_id_, IPEndPoint(), helper_.get(), 3988 TestConnection connection(connection_id_, IPEndPoint(), helper_.get(),
3952 writer_.get(), true, version(), 3989 writer_.get(), true, version(),
3953 kSmallerFlowControlWindow); 3990 kSmallerFlowControlWindow);
3954 EXPECT_EQ(kDefaultFlowControlSendWindow, 3991 EXPECT_EQ(kDefaultFlowControlSendWindow,
3955 connection.max_flow_control_receive_window_bytes()); 3992 connection.max_flow_control_receive_window_bytes());
3956 } 3993 }
3957 3994
3958 } // namespace 3995 } // namespace
3959 } // namespace test 3996 } // namespace test
3960 } // namespace net 3997 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698