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

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: Rebase 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
« no previous file with comments | « net/quic/quic_connection.cc ('k') | net/quic/quic_protocol.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/quic/quic_connection.h" 5 #include "net/quic/quic_connection.h"
6 6
7 #include "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 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 QuicPacketCreatorPeer::SetIsServer( 513 QuicPacketCreatorPeer::SetIsServer(
514 QuicConnectionPeer::GetPacketCreator(this), is_server); 514 QuicConnectionPeer::GetPacketCreator(this), is_server);
515 QuicConnectionPeer::SetIsServer(this, is_server); 515 QuicConnectionPeer::SetIsServer(this, is_server);
516 } 516 }
517 517
518 TestConnectionHelper::TestAlarm* GetAckAlarm() { 518 TestConnectionHelper::TestAlarm* GetAckAlarm() {
519 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( 519 return reinterpret_cast<TestConnectionHelper::TestAlarm*>(
520 QuicConnectionPeer::GetAckAlarm(this)); 520 QuicConnectionPeer::GetAckAlarm(this));
521 } 521 }
522 522
523 TestConnectionHelper::TestAlarm* GetPingAlarm() {
524 return reinterpret_cast<TestConnectionHelper::TestAlarm*>(
525 QuicConnectionPeer::GetPingAlarm(this));
526 }
527
528 TestConnectionHelper::TestAlarm* GetResumeWritesAlarm() {
529 return reinterpret_cast<TestConnectionHelper::TestAlarm*>(
530 QuicConnectionPeer::GetResumeWritesAlarm(this));
531 }
532
523 TestConnectionHelper::TestAlarm* GetRetransmissionAlarm() { 533 TestConnectionHelper::TestAlarm* GetRetransmissionAlarm() {
524 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( 534 return reinterpret_cast<TestConnectionHelper::TestAlarm*>(
525 QuicConnectionPeer::GetRetransmissionAlarm(this)); 535 QuicConnectionPeer::GetRetransmissionAlarm(this));
526 } 536 }
527 537
528 TestConnectionHelper::TestAlarm* GetSendAlarm() { 538 TestConnectionHelper::TestAlarm* GetSendAlarm() {
529 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( 539 return reinterpret_cast<TestConnectionHelper::TestAlarm*>(
530 QuicConnectionPeer::GetSendAlarm(this)); 540 QuicConnectionPeer::GetSendAlarm(this));
531 } 541 }
532 542
533 TestConnectionHelper::TestAlarm* GetResumeWritesAlarm() {
534 return reinterpret_cast<TestConnectionHelper::TestAlarm*>(
535 QuicConnectionPeer::GetResumeWritesAlarm(this));
536 }
537
538 TestConnectionHelper::TestAlarm* GetTimeoutAlarm() { 543 TestConnectionHelper::TestAlarm* GetTimeoutAlarm() {
539 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( 544 return reinterpret_cast<TestConnectionHelper::TestAlarm*>(
540 QuicConnectionPeer::GetTimeoutAlarm(this)); 545 QuicConnectionPeer::GetTimeoutAlarm(this));
541 } 546 }
542 547
543 using QuicConnection::SelectMutualVersion; 548 using QuicConnection::SelectMutualVersion;
544 549
545 private: 550 private:
546 TestPacketWriter* writer_; 551 TestPacketWriter* writer_;
547 552
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 .Times(AnyNumber()); 604 .Times(AnyNumber());
600 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly( 605 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly(
601 Return(QuicTime::Delta::Zero())); 606 Return(QuicTime::Delta::Zero()));
602 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( 607 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly(
603 Return(kMaxPacketSize)); 608 Return(kMaxPacketSize));
604 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)) 609 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _))
605 .WillByDefault(Return(true)); 610 .WillByDefault(Return(true));
606 EXPECT_CALL(visitor_, HasPendingWrites()).Times(AnyNumber()); 611 EXPECT_CALL(visitor_, HasPendingWrites()).Times(AnyNumber());
607 EXPECT_CALL(visitor_, HasPendingHandshake()).Times(AnyNumber()); 612 EXPECT_CALL(visitor_, HasPendingHandshake()).Times(AnyNumber());
608 EXPECT_CALL(visitor_, OnCanWrite()).Times(AnyNumber()); 613 EXPECT_CALL(visitor_, OnCanWrite()).Times(AnyNumber());
614 EXPECT_CALL(visitor_, HasOpenDataStreams()).WillRepeatedly(Return(false));
609 615
610 EXPECT_CALL(*loss_algorithm_, GetLossTimeout()) 616 EXPECT_CALL(*loss_algorithm_, GetLossTimeout())
611 .WillRepeatedly(Return(QuicTime::Zero())); 617 .WillRepeatedly(Return(QuicTime::Zero()));
612 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 618 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
613 .WillRepeatedly(Return(SequenceNumberSet())); 619 .WillRepeatedly(Return(SequenceNumberSet()));
614 } 620 }
615 621
616 QuicVersion version() { 622 QuicVersion version() {
617 return GetParam(); 623 return GetParam();
618 } 624 }
(...skipping 2017 matching lines...) Expand 10 before | Expand all | Expand 10 after
2636 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); 2642 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
2637 2643
2638 // Simulate the timeout alarm firing. 2644 // Simulate the timeout alarm firing.
2639 clock_.AdvanceTime( 2645 clock_.AdvanceTime(
2640 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)); 2646 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs));
2641 connection_.GetTimeoutAlarm()->Fire(); 2647 connection_.GetTimeoutAlarm()->Fire();
2642 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 2648 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
2643 EXPECT_FALSE(connection_.connected()); 2649 EXPECT_FALSE(connection_.connected());
2644 2650
2645 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 2651 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
2652 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet());
2646 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet()); 2653 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet());
2647 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 2654 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2648 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet()); 2655 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet());
2649 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 2656 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
2650 } 2657 }
2651 2658
2659 TEST_P(QuicConnectionTest, PingAfterSend) {
2660 EXPECT_TRUE(connection_.connected());
2661 EXPECT_CALL(visitor_, HasOpenDataStreams()).WillRepeatedly(Return(true));
2662 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet());
2663
2664 // Advance to 5ms, and send a packet to the peer, which will set
2665 // the ping alarm.
2666 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5));
2667 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2668 SendStreamDataToPeer(1, "GET /", 0, kFin, NULL);
2669 EXPECT_TRUE(connection_.GetPingAlarm()->IsSet());
2670 EXPECT_EQ(clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(15)),
2671 connection_.GetPingAlarm()->deadline());
2672
2673 // Now recevie and ACK of the previous packet, which will move the
2674 // ping alarm forward.
2675 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5));
2676 QuicAckFrame frame = InitAckFrame(1, 0);
2677 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2678 EXPECT_CALL(*send_algorithm_, UpdateRtt(_));
2679 EXPECT_CALL(*send_algorithm_, OnPacketAcked(1, _));
2680 ProcessAckPacket(&frame);
2681 EXPECT_TRUE(connection_.GetPingAlarm()->IsSet());
2682 EXPECT_EQ(clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(15)),
2683 connection_.GetPingAlarm()->deadline());
2684
2685 writer_->Reset();
2686 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(15));
2687 connection_.GetPingAlarm()->Fire();
2688 EXPECT_EQ(1u, writer_->frame_count());
2689 ASSERT_EQ(1u, writer_->stream_frames().size());
2690 EXPECT_EQ(kCryptoStreamId, writer_->stream_frames()[0].stream_id);
2691 EXPECT_EQ(0u, writer_->stream_frames()[0].offset);
2692 writer_->Reset();
2693
2694 EXPECT_CALL(visitor_, HasOpenDataStreams()).WillRepeatedly(Return(false));
2695 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5));
2696 SendAckPacketToPeer();
2697
2698 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet());
2699 }
2700
2652 TEST_P(QuicConnectionTest, TimeoutAfterSend) { 2701 TEST_P(QuicConnectionTest, TimeoutAfterSend) {
2653 EXPECT_TRUE(connection_.connected()); 2702 EXPECT_TRUE(connection_.connected());
2654 2703
2655 QuicTime default_timeout = clock_.ApproximateNow().Add( 2704 QuicTime default_timeout = clock_.ApproximateNow().Add(
2656 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)); 2705 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs));
2657 2706
2658 // When we send a packet, the timeout will change to 5000 + 2707 // When we send a packet, the timeout will change to 5000 +
2659 // kDefaultInitialTimeoutSecs. 2708 // kDefaultInitialTimeoutSecs.
2660 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); 2709 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5));
2661 2710
(...skipping 1357 matching lines...) Expand 10 before | Expand all | Expand 10 after
4019 TestConnection connection(connection_id_, IPEndPoint(), helper_.get(), 4068 TestConnection connection(connection_id_, IPEndPoint(), helper_.get(),
4020 writer_.get(), true, version(), 4069 writer_.get(), true, version(),
4021 kSmallerFlowControlWindow); 4070 kSmallerFlowControlWindow);
4022 EXPECT_EQ(kDefaultFlowControlSendWindow, 4071 EXPECT_EQ(kDefaultFlowControlSendWindow,
4023 connection.max_flow_control_receive_window_bytes()); 4072 connection.max_flow_control_receive_window_bytes());
4024 } 4073 }
4025 4074
4026 } // namespace 4075 } // namespace
4027 } // namespace test 4076 } // namespace test
4028 } // namespace net 4077 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection.cc ('k') | net/quic/quic_protocol.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698