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

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

Issue 605163004: Land Recent QUIC Changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Final_0925
Patch Set: Created 6 years, 2 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
« no previous file with comments | « net/quic/quic_connection_logger.cc ('k') | net/quic/quic_crypto_client_stream_test.cc » ('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 2632 matching lines...) Expand 10 before | Expand all | Expand 10 after
2643 TEST_P(QuicConnectionTest, DontUpdateQuicCongestionFeedbackFrameForRevived) { 2643 TEST_P(QuicConnectionTest, DontUpdateQuicCongestionFeedbackFrameForRevived) {
2644 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2644 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2645 SendAckPacketToPeer(); 2645 SendAckPacketToPeer();
2646 // Process an FEC packet, and revive the missing data packet 2646 // Process an FEC packet, and revive the missing data packet
2647 // but only contact the receive_algorithm once. 2647 // but only contact the receive_algorithm once.
2648 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _)); 2648 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _));
2649 ProcessFecPacket(2, 1, true, !kEntropyFlag, NULL); 2649 ProcessFecPacket(2, 1, true, !kEntropyFlag, NULL);
2650 } 2650 }
2651 2651
2652 TEST_P(QuicConnectionTest, InitialTimeout) { 2652 TEST_P(QuicConnectionTest, InitialTimeout) {
2653 if (!FLAGS_quic_unified_timeouts) {
2654 EXPECT_TRUE(connection_.connected());
2655 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_CONNECTION_TIMED_OUT, false));
2656 EXPECT_CALL(*send_algorithm_,
2657 OnPacketSent(_, _, _, _, _)).Times(AnyNumber());
2658
2659 QuicTime default_timeout = clock_.ApproximateNow().Add(
2660 QuicTime::Delta::FromSeconds(kDefaultIdleTimeoutSecs));
2661 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
2662
2663 // Simulate the timeout alarm firing.
2664 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(kDefaultIdleTimeoutSecs));
2665 connection_.GetTimeoutAlarm()->Fire();
2666
2667 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
2668 EXPECT_FALSE(connection_.connected());
2669
2670 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
2671 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet());
2672 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet());
2673 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2674 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet());
2675 return;
2676 }
2653 EXPECT_TRUE(connection_.connected()); 2677 EXPECT_TRUE(connection_.connected());
2654 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_CONNECTION_TIMED_OUT, false));
2655 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber()); 2678 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber());
2679 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
2656 2680
2681 // SetFromConfig sets the initial timeouts before negotiation.
2682 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
2683 QuicConfig config;
2684 config.SetDefaults();
2685 connection_.SetFromConfig(config);
2686 // Subtract a second from the idle timeout on the client side.
2657 QuicTime default_timeout = clock_.ApproximateNow().Add( 2687 QuicTime default_timeout = clock_.ApproximateNow().Add(
2658 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)); 2688 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1));
2659 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); 2689 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
2660 2690
2691 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_CONNECTION_TIMED_OUT, false));
2661 // Simulate the timeout alarm firing. 2692 // Simulate the timeout alarm firing.
2662 clock_.AdvanceTime( 2693 clock_.AdvanceTime(
2663 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)); 2694 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1));
2664 connection_.GetTimeoutAlarm()->Fire(); 2695 connection_.GetTimeoutAlarm()->Fire();
2665 2696
2666 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 2697 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
2667 EXPECT_FALSE(connection_.connected()); 2698 EXPECT_FALSE(connection_.connected());
2668 2699
2669 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 2700 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
2670 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); 2701 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet());
2671 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet()); 2702 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet());
2672 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 2703 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2673 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet()); 2704 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet());
2674 } 2705 }
2675 2706
2676 TEST_P(QuicConnectionTest, OverallTimeout) { 2707 TEST_P(QuicConnectionTest, OverallTimeout) {
2677 connection_.SetOverallConnectionTimeout( 2708 // Use a shorter overall connection timeout than idle timeout for this test.
2678 QuicTime::Delta::FromSeconds(kDefaultMaxTimeForCryptoHandshakeSecs)); 2709 const QuicTime::Delta timeout = QuicTime::Delta::FromSeconds(5);
2710 connection_.SetNetworkTimeouts(timeout, timeout);
2679 EXPECT_TRUE(connection_.connected()); 2711 EXPECT_TRUE(connection_.connected());
2680 EXPECT_CALL(visitor_,
2681 OnConnectionClosed(QUIC_CONNECTION_OVERALL_TIMED_OUT, false));
2682 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber()); 2712 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber());
2683 2713
2684 QuicTime overall_timeout = clock_.ApproximateNow().Add( 2714 QuicTime overall_timeout = clock_.ApproximateNow().Add(timeout).Subtract(
2685 QuicTime::Delta::FromSeconds(kDefaultMaxTimeForCryptoHandshakeSecs)); 2715 QuicTime::Delta::FromSeconds(1));
2686 EXPECT_EQ(overall_timeout, connection_.GetTimeoutAlarm()->deadline()); 2716 EXPECT_EQ(overall_timeout, connection_.GetTimeoutAlarm()->deadline());
2717 EXPECT_TRUE(connection_.connected());
2687 2718
2688 EXPECT_TRUE(connection_.connected()); 2719 // Send and ack new data 3 seconds later to lengthen the idle timeout.
2689 SendStreamDataToPeer(1, "GET /", 0, kFin, NULL); 2720 SendStreamDataToPeer(1, "GET /", 0, kFin, NULL);
2690 2721 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(3));
2691 clock_.AdvanceTime(
2692 QuicTime::Delta::FromSeconds(2 * kDefaultInitialTimeoutSecs));
2693
2694 // Process an ack and see that the connection still times out.
2695 QuicAckFrame frame = InitAckFrame(1); 2722 QuicAckFrame frame = InitAckFrame(1);
2696 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2723 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2697 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 2724 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
2698 ProcessAckPacket(&frame); 2725 ProcessAckPacket(&frame);
2699 2726
2727 // Fire early to verify it wouldn't timeout yet.
2728 connection_.GetTimeoutAlarm()->Fire();
2729 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet());
2730 EXPECT_TRUE(connection_.connected());
2731
2732 clock_.AdvanceTime(timeout.Subtract(QuicTime::Delta::FromSeconds(2)));
2733
2734 EXPECT_CALL(visitor_,
2735 OnConnectionClosed(QUIC_CONNECTION_OVERALL_TIMED_OUT, false));
2700 // Simulate the timeout alarm firing. 2736 // Simulate the timeout alarm firing.
2701 connection_.GetTimeoutAlarm()->Fire(); 2737 connection_.GetTimeoutAlarm()->Fire();
2702 2738
2703 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 2739 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
2704 EXPECT_FALSE(connection_.connected()); 2740 EXPECT_FALSE(connection_.connected());
2705 2741
2706 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 2742 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
2707 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); 2743 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet());
2708 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet()); 2744 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet());
2709 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 2745 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
2752 writer_->Reset(); 2788 writer_->Reset();
2753 2789
2754 EXPECT_CALL(visitor_, HasOpenDataStreams()).WillRepeatedly(Return(false)); 2790 EXPECT_CALL(visitor_, HasOpenDataStreams()).WillRepeatedly(Return(false));
2755 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); 2791 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5));
2756 SendAckPacketToPeer(); 2792 SendAckPacketToPeer();
2757 2793
2758 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); 2794 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet());
2759 } 2795 }
2760 2796
2761 TEST_P(QuicConnectionTest, TimeoutAfterSend) { 2797 TEST_P(QuicConnectionTest, TimeoutAfterSend) {
2798 if (!FLAGS_quic_unified_timeouts) {
2799 EXPECT_TRUE(connection_.connected());
2800
2801 QuicTime default_timeout = clock_.ApproximateNow().Add(
2802 QuicTime::Delta::FromSeconds(kDefaultIdleTimeoutSecs));
2803
2804 // When we send a packet, the timeout will change to 5000 +
2805 // kDefaultInitialTimeoutSecs.
2806 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5));
2807
2808 // Send an ack so we don't set the retransmission alarm.
2809 SendAckPacketToPeer();
2810 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
2811
2812 // The original alarm will fire. We should not time out because we had a
2813 // network event at t=5000. The alarm will reregister.
2814 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(
2815 kDefaultIdleTimeoutSecs * 1000000 - 5000));
2816 EXPECT_EQ(default_timeout, clock_.ApproximateNow());
2817 connection_.GetTimeoutAlarm()->Fire();
2818 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet());
2819 EXPECT_TRUE(connection_.connected());
2820 EXPECT_EQ(default_timeout.Add(QuicTime::Delta::FromMilliseconds(5)),
2821 connection_.GetTimeoutAlarm()->deadline());
2822
2823 // This time, we should time out.
2824 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_CONNECTION_TIMED_OUT, false));
2825 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
2826 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5));
2827 EXPECT_EQ(default_timeout.Add(QuicTime::Delta::FromMilliseconds(5)),
2828 clock_.ApproximateNow());
2829 connection_.GetTimeoutAlarm()->Fire();
2830 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
2831 EXPECT_FALSE(connection_.connected());
2832 return;
2833 }
2762 EXPECT_TRUE(connection_.connected()); 2834 EXPECT_TRUE(connection_.connected());
2835 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
2836 QuicConfig config;
2837 config.SetDefaults();
2838 connection_.SetFromConfig(config);
2763 2839
2764 QuicTime default_timeout = clock_.ApproximateNow().Add( 2840 const QuicTime::Delta initial_idle_timeout =
2765 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)); 2841 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1);
2842 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5);
2843 QuicTime default_timeout = clock_.ApproximateNow().Add(initial_idle_timeout);
2766 2844
2767 // When we send a packet, the timeout will change to 5000 + 2845 // When we send a packet, the timeout will change to 5ms +
2768 // kDefaultInitialTimeoutSecs. 2846 // kInitialIdleTimeoutSecs.
2769 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); 2847 clock_.AdvanceTime(five_ms);
2770 2848
2771 // Send an ack so we don't set the retransmission alarm. 2849 // Send an ack so we don't set the retransmission alarm.
2772 SendAckPacketToPeer(); 2850 SendAckPacketToPeer();
2773 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); 2851 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
2774 2852
2775 // The original alarm will fire. We should not time out because we had a 2853 // The original alarm will fire. We should not time out because we had a
2776 // network event at t=5000. The alarm will reregister. 2854 // network event at t=5ms. The alarm will reregister.
2777 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds( 2855 clock_.AdvanceTime(initial_idle_timeout.Subtract(five_ms));
2778 kDefaultInitialTimeoutSecs * 1000000 - 5000));
2779 EXPECT_EQ(default_timeout, clock_.ApproximateNow()); 2856 EXPECT_EQ(default_timeout, clock_.ApproximateNow());
2780 connection_.GetTimeoutAlarm()->Fire(); 2857 connection_.GetTimeoutAlarm()->Fire();
2781 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet()); 2858 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet());
2782 EXPECT_TRUE(connection_.connected()); 2859 EXPECT_TRUE(connection_.connected());
2783 EXPECT_EQ(default_timeout.Add(QuicTime::Delta::FromMilliseconds(5)), 2860 EXPECT_EQ(default_timeout.Add(five_ms),
2784 connection_.GetTimeoutAlarm()->deadline()); 2861 connection_.GetTimeoutAlarm()->deadline());
2785 2862
2786 // This time, we should time out. 2863 // This time, we should time out.
2787 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_CONNECTION_TIMED_OUT, false)); 2864 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_CONNECTION_TIMED_OUT, false));
2788 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 2865 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
2789 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); 2866 clock_.AdvanceTime(five_ms);
2790 EXPECT_EQ(default_timeout.Add(QuicTime::Delta::FromMilliseconds(5)), 2867 EXPECT_EQ(default_timeout.Add(five_ms), clock_.ApproximateNow());
2791 clock_.ApproximateNow());
2792 connection_.GetTimeoutAlarm()->Fire(); 2868 connection_.GetTimeoutAlarm()->Fire();
2793 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 2869 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
2794 EXPECT_FALSE(connection_.connected()); 2870 EXPECT_FALSE(connection_.connected());
2795 } 2871 }
2796 2872
2797 TEST_P(QuicConnectionTest, SendScheduler) { 2873 TEST_P(QuicConnectionTest, SendScheduler) {
2798 // Test that if we send a packet without delay, it is not queued. 2874 // Test that if we send a packet without delay, it is not queued.
2799 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); 2875 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag);
2800 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 2876 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
2801 connection_.SendPacket( 2877 connection_.SendPacket(
(...skipping 1035 matching lines...) Expand 10 before | Expand all | Expand 10 after
3837 visitor->OnCongestionWindowChange(1000 * kDefaultTCPMSS); 3913 visitor->OnCongestionWindowChange(1000 * kDefaultTCPMSS);
3838 EXPECT_LT(max_packets_per_fec_group, creator->max_packets_per_fec_group()); 3914 EXPECT_LT(max_packets_per_fec_group, creator->max_packets_per_fec_group());
3839 } 3915 }
3840 3916
3841 class MockQuicConnectionDebugVisitor 3917 class MockQuicConnectionDebugVisitor
3842 : public QuicConnectionDebugVisitor { 3918 : public QuicConnectionDebugVisitor {
3843 public: 3919 public:
3844 MOCK_METHOD1(OnFrameAddedToPacket, 3920 MOCK_METHOD1(OnFrameAddedToPacket,
3845 void(const QuicFrame&)); 3921 void(const QuicFrame&));
3846 3922
3847 MOCK_METHOD5(OnPacketSent, 3923 MOCK_METHOD6(OnPacketSent,
3848 void(QuicPacketSequenceNumber, 3924 void(QuicPacketSequenceNumber,
3925 QuicPacketSequenceNumber,
3849 EncryptionLevel, 3926 EncryptionLevel,
3850 TransmissionType, 3927 TransmissionType,
3851 const QuicEncryptedPacket&, 3928 const QuicEncryptedPacket&,
3852 WriteResult)); 3929 WriteResult));
3853 3930
3854 MOCK_METHOD2(OnPacketRetransmitted,
3855 void(QuicPacketSequenceNumber,
3856 QuicPacketSequenceNumber));
3857
3858 MOCK_METHOD3(OnPacketReceived, 3931 MOCK_METHOD3(OnPacketReceived,
3859 void(const IPEndPoint&, 3932 void(const IPEndPoint&,
3860 const IPEndPoint&, 3933 const IPEndPoint&,
3861 const QuicEncryptedPacket&)); 3934 const QuicEncryptedPacket&));
3862 3935
3863 MOCK_METHOD1(OnProtocolVersionMismatch, 3936 MOCK_METHOD1(OnProtocolVersionMismatch,
3864 void(QuicVersion)); 3937 void(QuicVersion));
3865 3938
3866 MOCK_METHOD1(OnPacketHeader, 3939 MOCK_METHOD1(OnPacketHeader,
3867 void(const QuicPacketHeader& header)); 3940 void(const QuicPacketHeader& header));
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
3932 QuicBlockedFrame blocked; 4005 QuicBlockedFrame blocked;
3933 blocked.stream_id = 3; 4006 blocked.stream_id = 3;
3934 EXPECT_CALL(visitor_, OnBlockedFrames(_)); 4007 EXPECT_CALL(visitor_, OnBlockedFrames(_));
3935 ProcessFramePacket(QuicFrame(&blocked)); 4008 ProcessFramePacket(QuicFrame(&blocked));
3936 EXPECT_TRUE(ack_alarm->IsSet()); 4009 EXPECT_TRUE(ack_alarm->IsSet());
3937 } 4010 }
3938 4011
3939 } // namespace 4012 } // namespace
3940 } // namespace test 4013 } // namespace test
3941 } // namespace net 4014 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection_logger.cc ('k') | net/quic/quic_crypto_client_stream_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698