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

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

Issue 2130103002: Landing Recent QUIC changes until 2016-07-02 02:45 UTC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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.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 <errno.h> 7 #include <errno.h>
8 #include <memory> 8 #include <memory>
9 #include <ostream> 9 #include <ostream>
10 #include <utility> 10 #include <utility>
(...skipping 2457 matching lines...) Expand 10 before | Expand all | Expand 10 after
2468 2468
2469 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr); 2469 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr);
2470 EXPECT_EQ(1u, stop_waiting()->least_unacked); 2470 EXPECT_EQ(1u, stop_waiting()->least_unacked);
2471 QuicTime retransmission_time = 2471 QuicTime retransmission_time =
2472 connection_.GetRetransmissionAlarm()->deadline(); 2472 connection_.GetRetransmissionAlarm()->deadline();
2473 EXPECT_NE(QuicTime::Zero(), retransmission_time); 2473 EXPECT_NE(QuicTime::Zero(), retransmission_time);
2474 2474
2475 EXPECT_EQ(1u, writer_->header().packet_number); 2475 EXPECT_EQ(1u, writer_->header().packet_number);
2476 // Simulate the retransmission alarm firing and sending a tlp, 2476 // Simulate the retransmission alarm firing and sending a tlp,
2477 // so send algorithm's OnRetransmissionTimeout is not called. 2477 // so send algorithm's OnRetransmissionTimeout is not called.
2478 clock_.AdvanceTime(retransmission_time.Subtract(clock_.Now())); 2478 clock_.AdvanceTime(retransmission_time - clock_.Now());
2479 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _)); 2479 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _));
2480 connection_.GetRetransmissionAlarm()->Fire(); 2480 connection_.GetRetransmissionAlarm()->Fire();
2481 EXPECT_EQ(2u, writer_->header().packet_number); 2481 EXPECT_EQ(2u, writer_->header().packet_number);
2482 // We do not raise the high water mark yet. 2482 // We do not raise the high water mark yet.
2483 EXPECT_EQ(1u, stop_waiting()->least_unacked); 2483 EXPECT_EQ(1u, stop_waiting()->least_unacked);
2484 } 2484 }
2485 2485
2486 TEST_P(QuicConnectionTest, RTO) { 2486 TEST_P(QuicConnectionTest, RTO) {
2487 connection_.DisableTailLossProbe(); 2487 connection_.DisableTailLossProbe();
2488 2488
2489 QuicTime default_retransmission_time = 2489 QuicTime default_retransmission_time =
2490 clock_.ApproximateNow().Add(DefaultRetransmissionTime()); 2490 clock_.ApproximateNow() + DefaultRetransmissionTime();
2491 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr); 2491 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr);
2492 EXPECT_EQ(1u, stop_waiting()->least_unacked); 2492 EXPECT_EQ(1u, stop_waiting()->least_unacked);
2493 2493
2494 EXPECT_EQ(1u, writer_->header().packet_number); 2494 EXPECT_EQ(1u, writer_->header().packet_number);
2495 EXPECT_EQ(default_retransmission_time, 2495 EXPECT_EQ(default_retransmission_time,
2496 connection_.GetRetransmissionAlarm()->deadline()); 2496 connection_.GetRetransmissionAlarm()->deadline());
2497 // Simulate the retransmission alarm firing. 2497 // Simulate the retransmission alarm firing.
2498 clock_.AdvanceTime(DefaultRetransmissionTime()); 2498 clock_.AdvanceTime(DefaultRetransmissionTime());
2499 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _)); 2499 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _));
2500 connection_.GetRetransmissionAlarm()->Fire(); 2500 connection_.GetRetransmissionAlarm()->Fire();
2501 EXPECT_EQ(2u, writer_->header().packet_number); 2501 EXPECT_EQ(2u, writer_->header().packet_number);
2502 // We do not raise the high water mark yet. 2502 // We do not raise the high water mark yet.
2503 EXPECT_EQ(1u, stop_waiting()->least_unacked); 2503 EXPECT_EQ(1u, stop_waiting()->least_unacked);
2504 } 2504 }
2505 2505
2506 TEST_P(QuicConnectionTest, RTOWithSameEncryptionLevel) { 2506 TEST_P(QuicConnectionTest, RTOWithSameEncryptionLevel) {
2507 connection_.DisableTailLossProbe(); 2507 connection_.DisableTailLossProbe();
2508 2508
2509 QuicTime default_retransmission_time = 2509 QuicTime default_retransmission_time =
2510 clock_.ApproximateNow().Add(DefaultRetransmissionTime()); 2510 clock_.ApproximateNow() + DefaultRetransmissionTime();
2511 use_tagging_decrypter(); 2511 use_tagging_decrypter();
2512 2512
2513 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at 2513 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at
2514 // the end of the packet. We can test this to check which encrypter was used. 2514 // the end of the packet. We can test this to check which encrypter was used.
2515 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); 2515 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01));
2516 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr); 2516 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr);
2517 EXPECT_EQ(0x01010101u, writer_->final_bytes_of_last_packet()); 2517 EXPECT_EQ(0x01010101u, writer_->final_bytes_of_last_packet());
2518 2518
2519 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); 2519 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02));
2520 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); 2520 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
2776 2776
2777 TEST_P(QuicConnectionTest, DelayRTOWithAckReceipt) { 2777 TEST_P(QuicConnectionTest, DelayRTOWithAckReceipt) {
2778 connection_.DisableTailLossProbe(); 2778 connection_.DisableTailLossProbe();
2779 2779
2780 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2780 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2781 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); 2781 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
2782 connection_.SendStreamDataWithString(2, "foo", 0, !kFin, nullptr); 2782 connection_.SendStreamDataWithString(2, "foo", 0, !kFin, nullptr);
2783 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, nullptr); 2783 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, nullptr);
2784 QuicAlarm* retransmission_alarm = connection_.GetRetransmissionAlarm(); 2784 QuicAlarm* retransmission_alarm = connection_.GetRetransmissionAlarm();
2785 EXPECT_TRUE(retransmission_alarm->IsSet()); 2785 EXPECT_TRUE(retransmission_alarm->IsSet());
2786 EXPECT_EQ(clock_.Now().Add(DefaultRetransmissionTime()), 2786 EXPECT_EQ(clock_.Now() + DefaultRetransmissionTime(),
2787 retransmission_alarm->deadline()); 2787 retransmission_alarm->deadline());
2788 2788
2789 // Advance the time right before the RTO, then receive an ack for the first 2789 // Advance the time right before the RTO, then receive an ack for the first
2790 // packet to delay the RTO. 2790 // packet to delay the RTO.
2791 clock_.AdvanceTime(DefaultRetransmissionTime()); 2791 clock_.AdvanceTime(DefaultRetransmissionTime());
2792 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 2792 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
2793 QuicAckFrame ack = InitAckFrame(1); 2793 QuicAckFrame ack = InitAckFrame(1);
2794 ProcessAckPacket(&ack); 2794 ProcessAckPacket(&ack);
2795 EXPECT_TRUE(retransmission_alarm->IsSet()); 2795 EXPECT_TRUE(retransmission_alarm->IsSet());
2796 EXPECT_GT(retransmission_alarm->deadline(), clock_.Now()); 2796 EXPECT_GT(retransmission_alarm->deadline(), clock_.Now());
2797 2797
2798 // Move forward past the original RTO and ensure the RTO is still pending. 2798 // Move forward past the original RTO and ensure the RTO is still pending.
2799 clock_.AdvanceTime(DefaultRetransmissionTime().Multiply(2)); 2799 clock_.AdvanceTime(2 * DefaultRetransmissionTime());
2800 2800
2801 // Ensure the second packet gets retransmitted when it finally fires. 2801 // Ensure the second packet gets retransmitted when it finally fires.
2802 EXPECT_TRUE(retransmission_alarm->IsSet()); 2802 EXPECT_TRUE(retransmission_alarm->IsSet());
2803 EXPECT_LT(retransmission_alarm->deadline(), clock_.ApproximateNow()); 2803 EXPECT_LT(retransmission_alarm->deadline(), clock_.ApproximateNow());
2804 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 2804 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
2805 // Manually cancel the alarm to simulate a real test. 2805 // Manually cancel the alarm to simulate a real test.
2806 connection_.GetRetransmissionAlarm()->Fire(); 2806 connection_.GetRetransmissionAlarm()->Fire();
2807 2807
2808 // The new retransmitted packet number should set the RTO to a larger value 2808 // The new retransmitted packet number should set the RTO to a larger value
2809 // than previously. 2809 // than previously.
(...skipping 21 matching lines...) Expand all
2831 TEST_P(QuicConnectionTest, InitialTimeout) { 2831 TEST_P(QuicConnectionTest, InitialTimeout) {
2832 EXPECT_TRUE(connection_.connected()); 2832 EXPECT_TRUE(connection_.connected());
2833 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber()); 2833 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber());
2834 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 2834 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
2835 2835
2836 // SetFromConfig sets the initial timeouts before negotiation. 2836 // SetFromConfig sets the initial timeouts before negotiation.
2837 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); 2837 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
2838 QuicConfig config; 2838 QuicConfig config;
2839 connection_.SetFromConfig(config); 2839 connection_.SetFromConfig(config);
2840 // Subtract a second from the idle timeout on the client side. 2840 // Subtract a second from the idle timeout on the client side.
2841 QuicTime default_timeout = clock_.ApproximateNow().Add( 2841 QuicTime default_timeout =
2842 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1)); 2842 clock_.ApproximateNow() +
2843 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1);
2843 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); 2844 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
2844 2845
2845 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_NETWORK_IDLE_TIMEOUT, _, 2846 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_NETWORK_IDLE_TIMEOUT, _,
2846 ConnectionCloseSource::FROM_SELF)); 2847 ConnectionCloseSource::FROM_SELF));
2847 // Simulate the timeout alarm firing. 2848 // Simulate the timeout alarm firing.
2848 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1)); 2849 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1));
2849 connection_.GetTimeoutAlarm()->Fire(); 2850 connection_.GetTimeoutAlarm()->Fire();
2850 2851
2851 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 2852 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
2852 EXPECT_FALSE(connection_.connected()); 2853 EXPECT_FALSE(connection_.connected());
2853 2854
2854 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 2855 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
2855 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); 2856 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet());
2856 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet()); 2857 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet());
2857 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 2858 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2858 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet()); 2859 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet());
2859 EXPECT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet()); 2860 EXPECT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet());
2860 } 2861 }
2861 2862
2862 TEST_P(QuicConnectionTest, HandshakeTimeout) { 2863 TEST_P(QuicConnectionTest, HandshakeTimeout) {
2863 // Use a shorter handshake timeout than idle timeout for this test. 2864 // Use a shorter handshake timeout than idle timeout for this test.
2864 const QuicTime::Delta timeout = QuicTime::Delta::FromSeconds(5); 2865 const QuicTime::Delta timeout = QuicTime::Delta::FromSeconds(5);
2865 connection_.SetNetworkTimeouts(timeout, timeout); 2866 connection_.SetNetworkTimeouts(timeout, timeout);
2866 EXPECT_TRUE(connection_.connected()); 2867 EXPECT_TRUE(connection_.connected());
2867 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber()); 2868 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber());
2868 2869
2869 QuicTime handshake_timeout = clock_.ApproximateNow().Add(timeout).Subtract( 2870 QuicTime handshake_timeout =
2870 QuicTime::Delta::FromSeconds(1)); 2871 clock_.ApproximateNow() + timeout - QuicTime::Delta::FromSeconds(1);
2871 EXPECT_EQ(handshake_timeout, connection_.GetTimeoutAlarm()->deadline()); 2872 EXPECT_EQ(handshake_timeout, connection_.GetTimeoutAlarm()->deadline());
2872 EXPECT_TRUE(connection_.connected()); 2873 EXPECT_TRUE(connection_.connected());
2873 2874
2874 // Send and ack new data 3 seconds later to lengthen the idle timeout. 2875 // Send and ack new data 3 seconds later to lengthen the idle timeout.
2875 SendStreamDataToPeer(kHeadersStreamId, "GET /", 0, kFin, nullptr); 2876 SendStreamDataToPeer(kHeadersStreamId, "GET /", 0, kFin, nullptr);
2876 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(3)); 2877 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(3));
2877 QuicAckFrame frame = InitAckFrame(1); 2878 QuicAckFrame frame = InitAckFrame(1);
2878 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2879 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2879 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 2880 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
2880 ProcessAckPacket(&frame); 2881 ProcessAckPacket(&frame);
2881 2882
2882 // Fire early to verify it wouldn't timeout yet. 2883 // Fire early to verify it wouldn't timeout yet.
2883 connection_.GetTimeoutAlarm()->Fire(); 2884 connection_.GetTimeoutAlarm()->Fire();
2884 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet()); 2885 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet());
2885 EXPECT_TRUE(connection_.connected()); 2886 EXPECT_TRUE(connection_.connected());
2886 2887
2887 clock_.AdvanceTime(timeout.Subtract(QuicTime::Delta::FromSeconds(2))); 2888 clock_.AdvanceTime(timeout - QuicTime::Delta::FromSeconds(2));
2888 2889
2889 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_HANDSHAKE_TIMEOUT, _, 2890 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_HANDSHAKE_TIMEOUT, _,
2890 ConnectionCloseSource::FROM_SELF)); 2891 ConnectionCloseSource::FROM_SELF));
2891 // Simulate the timeout alarm firing. 2892 // Simulate the timeout alarm firing.
2892 connection_.GetTimeoutAlarm()->Fire(); 2893 connection_.GetTimeoutAlarm()->Fire();
2893 2894
2894 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 2895 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
2895 EXPECT_FALSE(connection_.connected()); 2896 EXPECT_FALSE(connection_.connected());
2896 2897
2897 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 2898 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
2898 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); 2899 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet());
2899 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet()); 2900 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet());
2900 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 2901 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2901 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet()); 2902 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet());
2902 } 2903 }
2903 2904
2904 TEST_P(QuicConnectionTest, PingAfterSend) { 2905 TEST_P(QuicConnectionTest, PingAfterSend) {
2905 EXPECT_TRUE(connection_.connected()); 2906 EXPECT_TRUE(connection_.connected());
2906 EXPECT_CALL(visitor_, HasOpenDynamicStreams()).WillRepeatedly(Return(true)); 2907 EXPECT_CALL(visitor_, HasOpenDynamicStreams()).WillRepeatedly(Return(true));
2907 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); 2908 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet());
2908 2909
2909 // Advance to 5ms, and send a packet to the peer, which will set 2910 // Advance to 5ms, and send a packet to the peer, which will set
2910 // the ping alarm. 2911 // the ping alarm.
2911 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); 2912 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5));
2912 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 2913 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2913 SendStreamDataToPeer(kHeadersStreamId, "GET /", 0, kFin, nullptr); 2914 SendStreamDataToPeer(kHeadersStreamId, "GET /", 0, kFin, nullptr);
2914 EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); 2915 EXPECT_TRUE(connection_.GetPingAlarm()->IsSet());
2915 EXPECT_EQ(clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(15)), 2916 EXPECT_EQ(clock_.ApproximateNow() + QuicTime::Delta::FromSeconds(15),
2916 connection_.GetPingAlarm()->deadline()); 2917 connection_.GetPingAlarm()->deadline());
2917 2918
2918 // Now recevie and ACK of the previous packet, which will move the 2919 // Now recevie and ACK of the previous packet, which will move the
2919 // ping alarm forward. 2920 // ping alarm forward.
2920 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); 2921 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5));
2921 QuicAckFrame frame = InitAckFrame(1); 2922 QuicAckFrame frame = InitAckFrame(1);
2922 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2923 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2923 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 2924 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
2924 ProcessAckPacket(&frame); 2925 ProcessAckPacket(&frame);
2925 EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); 2926 EXPECT_TRUE(connection_.GetPingAlarm()->IsSet());
2926 // The ping timer is set slightly less than 15 seconds in the future, because 2927 // The ping timer is set slightly less than 15 seconds in the future, because
2927 // of the 1s ping timer alarm granularity. 2928 // of the 1s ping timer alarm granularity.
2928 EXPECT_EQ(clock_.ApproximateNow() 2929 EXPECT_EQ(clock_.ApproximateNow() + QuicTime::Delta::FromSeconds(15) -
2929 .Add(QuicTime::Delta::FromSeconds(15)) 2930 QuicTime::Delta::FromMilliseconds(5),
2930 .Subtract(QuicTime::Delta::FromMilliseconds(5)),
2931 connection_.GetPingAlarm()->deadline()); 2931 connection_.GetPingAlarm()->deadline());
2932 2932
2933 writer_->Reset(); 2933 writer_->Reset();
2934 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(15)); 2934 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(15));
2935 connection_.GetPingAlarm()->Fire(); 2935 connection_.GetPingAlarm()->Fire();
2936 EXPECT_EQ(1u, writer_->frame_count()); 2936 EXPECT_EQ(1u, writer_->frame_count());
2937 ASSERT_EQ(1u, writer_->ping_frames().size()); 2937 ASSERT_EQ(1u, writer_->ping_frames().size());
2938 writer_->Reset(); 2938 writer_->Reset();
2939 2939
2940 EXPECT_CALL(visitor_, HasOpenDynamicStreams()).WillRepeatedly(Return(false)); 2940 EXPECT_CALL(visitor_, HasOpenDynamicStreams()).WillRepeatedly(Return(false));
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
3179 TEST_P(QuicConnectionTest, TimeoutAfterSend) { 3179 TEST_P(QuicConnectionTest, TimeoutAfterSend) {
3180 EXPECT_TRUE(connection_.connected()); 3180 EXPECT_TRUE(connection_.connected());
3181 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); 3181 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
3182 QuicConfig config; 3182 QuicConfig config;
3183 connection_.SetFromConfig(config); 3183 connection_.SetFromConfig(config);
3184 EXPECT_FALSE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_)); 3184 EXPECT_FALSE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_));
3185 3185
3186 const QuicTime::Delta initial_idle_timeout = 3186 const QuicTime::Delta initial_idle_timeout =
3187 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1); 3187 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1);
3188 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5); 3188 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5);
3189 QuicTime default_timeout = clock_.ApproximateNow().Add(initial_idle_timeout); 3189 QuicTime default_timeout = clock_.ApproximateNow() + initial_idle_timeout;
3190 3190
3191 // When we send a packet, the timeout will change to 5ms + 3191 // When we send a packet, the timeout will change to 5ms +
3192 // kInitialIdleTimeoutSecs. 3192 // kInitialIdleTimeoutSecs.
3193 clock_.AdvanceTime(five_ms); 3193 clock_.AdvanceTime(five_ms);
3194 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, kFin, nullptr); 3194 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, kFin, nullptr);
3195 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); 3195 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
3196 3196
3197 // Now send more data. This will not move the timeout becase 3197 // Now send more data. This will not move the timeout becase
3198 // no data has been recieved since the previous write. 3198 // no data has been recieved since the previous write.
3199 clock_.AdvanceTime(five_ms); 3199 clock_.AdvanceTime(five_ms);
3200 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, kFin, nullptr); 3200 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, kFin, nullptr);
3201 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); 3201 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
3202 3202
3203 // The original alarm will fire. We should not time out because we had a 3203 // The original alarm will fire. We should not time out because we had a
3204 // network event at t=5ms. The alarm will reregister. 3204 // network event at t=5ms. The alarm will reregister.
3205 clock_.AdvanceTime(initial_idle_timeout.Subtract(five_ms).Subtract(five_ms)); 3205 clock_.AdvanceTime(initial_idle_timeout - five_ms - five_ms);
3206 EXPECT_EQ(default_timeout, clock_.ApproximateNow()); 3206 EXPECT_EQ(default_timeout, clock_.ApproximateNow());
3207 connection_.GetTimeoutAlarm()->Fire(); 3207 connection_.GetTimeoutAlarm()->Fire();
3208 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet()); 3208 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet());
3209 EXPECT_TRUE(connection_.connected()); 3209 EXPECT_TRUE(connection_.connected());
3210 EXPECT_EQ(default_timeout.Add(five_ms).Add(five_ms), 3210 EXPECT_EQ(default_timeout + five_ms + five_ms,
3211 connection_.GetTimeoutAlarm()->deadline()); 3211 connection_.GetTimeoutAlarm()->deadline());
3212 3212
3213 // This time, we should time out. 3213 // This time, we should time out.
3214 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_NETWORK_IDLE_TIMEOUT, _, 3214 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_NETWORK_IDLE_TIMEOUT, _,
3215 ConnectionCloseSource::FROM_SELF)); 3215 ConnectionCloseSource::FROM_SELF));
3216 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 3216 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
3217 clock_.AdvanceTime(five_ms); 3217 clock_.AdvanceTime(five_ms);
3218 EXPECT_EQ(default_timeout.Add(five_ms), clock_.ApproximateNow()); 3218 EXPECT_EQ(default_timeout + five_ms, clock_.ApproximateNow());
3219 connection_.GetTimeoutAlarm()->Fire(); 3219 connection_.GetTimeoutAlarm()->Fire();
3220 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 3220 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
3221 EXPECT_FALSE(connection_.connected()); 3221 EXPECT_FALSE(connection_.connected());
3222 } 3222 }
3223 3223
3224 TEST_P(QuicConnectionTest, NewTimeoutAfterSendSilentClose) { 3224 TEST_P(QuicConnectionTest, NewTimeoutAfterSendSilentClose) {
3225 // Same test as above, but complete a handshake which enables silent close, 3225 // Same test as above, but complete a handshake which enables silent close,
3226 // causing no connection close packet to be sent. 3226 // causing no connection close packet to be sent.
3227 EXPECT_TRUE(connection_.connected()); 3227 EXPECT_TRUE(connection_.connected());
3228 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); 3228 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
(...skipping 14 matching lines...) Expand all
3243 const QuicErrorCode error = 3243 const QuicErrorCode error =
3244 config.ProcessPeerHello(msg, CLIENT, &error_details); 3244 config.ProcessPeerHello(msg, CLIENT, &error_details);
3245 EXPECT_EQ(QUIC_NO_ERROR, error); 3245 EXPECT_EQ(QUIC_NO_ERROR, error);
3246 3246
3247 connection_.SetFromConfig(config); 3247 connection_.SetFromConfig(config);
3248 EXPECT_TRUE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_)); 3248 EXPECT_TRUE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_));
3249 3249
3250 const QuicTime::Delta default_idle_timeout = 3250 const QuicTime::Delta default_idle_timeout =
3251 QuicTime::Delta::FromSeconds(kDefaultIdleTimeoutSecs - 1); 3251 QuicTime::Delta::FromSeconds(kDefaultIdleTimeoutSecs - 1);
3252 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5); 3252 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5);
3253 QuicTime default_timeout = clock_.ApproximateNow().Add(default_idle_timeout); 3253 QuicTime default_timeout = clock_.ApproximateNow() + default_idle_timeout;
3254 3254
3255 // When we send a packet, the timeout will change to 5ms + 3255 // When we send a packet, the timeout will change to 5ms +
3256 // kInitialIdleTimeoutSecs. 3256 // kInitialIdleTimeoutSecs.
3257 clock_.AdvanceTime(five_ms); 3257 clock_.AdvanceTime(five_ms);
3258 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, kFin, nullptr); 3258 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, kFin, nullptr);
3259 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); 3259 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
3260 3260
3261 // Now send more data. This will not move the timeout becase 3261 // Now send more data. This will not move the timeout becase
3262 // no data has been recieved since the previous write. 3262 // no data has been recieved since the previous write.
3263 clock_.AdvanceTime(five_ms); 3263 clock_.AdvanceTime(five_ms);
3264 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, kFin, nullptr); 3264 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, kFin, nullptr);
3265 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); 3265 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
3266 3266
3267 // The original alarm will fire. We should not time out because we had a 3267 // The original alarm will fire. We should not time out because we had a
3268 // network event at t=5ms. The alarm will reregister. 3268 // network event at t=5ms. The alarm will reregister.
3269 clock_.AdvanceTime(default_idle_timeout.Subtract(five_ms).Subtract(five_ms)); 3269 clock_.AdvanceTime(default_idle_timeout - five_ms - five_ms);
3270 EXPECT_EQ(default_timeout, clock_.ApproximateNow()); 3270 EXPECT_EQ(default_timeout, clock_.ApproximateNow());
3271 connection_.GetTimeoutAlarm()->Fire(); 3271 connection_.GetTimeoutAlarm()->Fire();
3272 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet()); 3272 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet());
3273 EXPECT_TRUE(connection_.connected()); 3273 EXPECT_TRUE(connection_.connected());
3274 EXPECT_EQ(default_timeout.Add(five_ms).Add(five_ms), 3274 EXPECT_EQ(default_timeout + five_ms + five_ms,
3275 connection_.GetTimeoutAlarm()->deadline()); 3275 connection_.GetTimeoutAlarm()->deadline());
3276 3276
3277 // This time, we should time out. 3277 // This time, we should time out.
3278 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_NETWORK_IDLE_TIMEOUT, _, 3278 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_NETWORK_IDLE_TIMEOUT, _,
3279 ConnectionCloseSource::FROM_SELF)); 3279 ConnectionCloseSource::FROM_SELF));
3280 clock_.AdvanceTime(five_ms); 3280 clock_.AdvanceTime(five_ms);
3281 EXPECT_EQ(default_timeout.Add(five_ms), clock_.ApproximateNow()); 3281 EXPECT_EQ(default_timeout + five_ms, clock_.ApproximateNow());
3282 connection_.GetTimeoutAlarm()->Fire(); 3282 connection_.GetTimeoutAlarm()->Fire();
3283 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 3283 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
3284 EXPECT_FALSE(connection_.connected()); 3284 EXPECT_FALSE(connection_.connected());
3285 } 3285 }
3286 3286
3287 TEST_P(QuicConnectionTest, TimeoutAfterReceive) { 3287 TEST_P(QuicConnectionTest, TimeoutAfterReceive) {
3288 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3288 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3289 EXPECT_TRUE(connection_.connected()); 3289 EXPECT_TRUE(connection_.connected());
3290 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); 3290 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
3291 QuicConfig config; 3291 QuicConfig config;
3292 connection_.SetFromConfig(config); 3292 connection_.SetFromConfig(config);
3293 EXPECT_FALSE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_)); 3293 EXPECT_FALSE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_));
3294 3294
3295 const QuicTime::Delta initial_idle_timeout = 3295 const QuicTime::Delta initial_idle_timeout =
3296 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1); 3296 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1);
3297 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5); 3297 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5);
3298 QuicTime default_timeout = clock_.ApproximateNow().Add(initial_idle_timeout); 3298 QuicTime default_timeout = clock_.ApproximateNow() + initial_idle_timeout;
3299 3299
3300 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, !kFin, 3300 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, !kFin,
3301 nullptr); 3301 nullptr);
3302 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 3, !kFin, 3302 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 3, !kFin,
3303 nullptr); 3303 nullptr);
3304 3304
3305 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); 3305 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
3306 clock_.AdvanceTime(five_ms); 3306 clock_.AdvanceTime(five_ms);
3307 3307
3308 // When we receive a packet, the timeout will change to 5ms + 3308 // When we receive a packet, the timeout will change to 5ms +
3309 // kInitialIdleTimeoutSecs. 3309 // kInitialIdleTimeoutSecs.
3310 QuicAckFrame ack = InitAckFrame(2); 3310 QuicAckFrame ack = InitAckFrame(2);
3311 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 3311 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
3312 ProcessAckPacket(&ack); 3312 ProcessAckPacket(&ack);
3313 3313
3314 // The original alarm will fire. We should not time out because we had a 3314 // The original alarm will fire. We should not time out because we had a
3315 // network event at t=5ms. The alarm will reregister. 3315 // network event at t=5ms. The alarm will reregister.
3316 clock_.AdvanceTime(initial_idle_timeout.Subtract(five_ms)); 3316 clock_.AdvanceTime(initial_idle_timeout - five_ms);
3317 EXPECT_EQ(default_timeout, clock_.ApproximateNow()); 3317 EXPECT_EQ(default_timeout, clock_.ApproximateNow());
3318 connection_.GetTimeoutAlarm()->Fire(); 3318 connection_.GetTimeoutAlarm()->Fire();
3319 EXPECT_TRUE(connection_.connected()); 3319 EXPECT_TRUE(connection_.connected());
3320 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet()); 3320 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet());
3321 EXPECT_EQ(default_timeout.Add(five_ms), 3321 EXPECT_EQ(default_timeout + five_ms,
3322 connection_.GetTimeoutAlarm()->deadline()); 3322 connection_.GetTimeoutAlarm()->deadline());
3323 3323
3324 // This time, we should time out. 3324 // This time, we should time out.
3325 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_NETWORK_IDLE_TIMEOUT, _, 3325 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_NETWORK_IDLE_TIMEOUT, _,
3326 ConnectionCloseSource::FROM_SELF)); 3326 ConnectionCloseSource::FROM_SELF));
3327 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 3327 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
3328 clock_.AdvanceTime(five_ms); 3328 clock_.AdvanceTime(five_ms);
3329 EXPECT_EQ(default_timeout.Add(five_ms), clock_.ApproximateNow()); 3329 EXPECT_EQ(default_timeout + five_ms, clock_.ApproximateNow());
3330 connection_.GetTimeoutAlarm()->Fire(); 3330 connection_.GetTimeoutAlarm()->Fire();
3331 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 3331 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
3332 EXPECT_FALSE(connection_.connected()); 3332 EXPECT_FALSE(connection_.connected());
3333 } 3333 }
3334 3334
3335 TEST_P(QuicConnectionTest, TimeoutAfterReceiveNotSendWhenUnacked) { 3335 TEST_P(QuicConnectionTest, TimeoutAfterReceiveNotSendWhenUnacked) {
3336 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3336 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3337 EXPECT_TRUE(connection_.connected()); 3337 EXPECT_TRUE(connection_.connected());
3338 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); 3338 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
3339 QuicConfig config; 3339 QuicConfig config;
3340 connection_.SetFromConfig(config); 3340 connection_.SetFromConfig(config);
3341 EXPECT_FALSE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_)); 3341 EXPECT_FALSE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_));
3342 3342
3343 const QuicTime::Delta initial_idle_timeout = 3343 const QuicTime::Delta initial_idle_timeout =
3344 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1); 3344 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1);
3345 connection_.SetNetworkTimeouts( 3345 connection_.SetNetworkTimeouts(
3346 QuicTime::Delta::Infinite(), 3346 QuicTime::Delta::Infinite(),
3347 initial_idle_timeout.Add(QuicTime::Delta::FromSeconds(1))); 3347 initial_idle_timeout + QuicTime::Delta::FromSeconds(1));
3348 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5); 3348 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5);
3349 QuicTime default_timeout = clock_.ApproximateNow().Add(initial_idle_timeout); 3349 QuicTime default_timeout = clock_.ApproximateNow() + initial_idle_timeout;
3350 3350
3351 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 3351 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
3352 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, !kFin, 3352 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, !kFin,
3353 nullptr); 3353 nullptr);
3354 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 3354 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
3355 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 3, !kFin, 3355 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 3, !kFin,
3356 nullptr); 3356 nullptr);
3357 3357
3358 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); 3358 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
3359 3359
3360 clock_.AdvanceTime(five_ms); 3360 clock_.AdvanceTime(five_ms);
3361 3361
3362 // When we receive a packet, the timeout will change to 5ms + 3362 // When we receive a packet, the timeout will change to 5ms +
3363 // kInitialIdleTimeoutSecs. 3363 // kInitialIdleTimeoutSecs.
3364 QuicAckFrame ack = InitAckFrame(2); 3364 QuicAckFrame ack = InitAckFrame(2);
3365 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 3365 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
3366 ProcessAckPacket(&ack); 3366 ProcessAckPacket(&ack);
3367 3367
3368 // The original alarm will fire. We should not time out because we had a 3368 // The original alarm will fire. We should not time out because we had a
3369 // network event at t=5ms. The alarm will reregister. 3369 // network event at t=5ms. The alarm will reregister.
3370 clock_.AdvanceTime(initial_idle_timeout.Subtract(five_ms)); 3370 clock_.AdvanceTime(initial_idle_timeout - five_ms);
3371 EXPECT_EQ(default_timeout, clock_.ApproximateNow()); 3371 EXPECT_EQ(default_timeout, clock_.ApproximateNow());
3372 connection_.GetTimeoutAlarm()->Fire(); 3372 connection_.GetTimeoutAlarm()->Fire();
3373 EXPECT_TRUE(connection_.connected()); 3373 EXPECT_TRUE(connection_.connected());
3374 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet()); 3374 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet());
3375 EXPECT_EQ(default_timeout.Add(five_ms), 3375 EXPECT_EQ(default_timeout + five_ms,
3376 connection_.GetTimeoutAlarm()->deadline()); 3376 connection_.GetTimeoutAlarm()->deadline());
3377 3377
3378 // Now, send packets while advancing the time and verify that the connection 3378 // Now, send packets while advancing the time and verify that the connection
3379 // eventually times out. 3379 // eventually times out.
3380 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_NETWORK_IDLE_TIMEOUT, _, 3380 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_NETWORK_IDLE_TIMEOUT, _,
3381 ConnectionCloseSource::FROM_SELF)); 3381 ConnectionCloseSource::FROM_SELF));
3382 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber()); 3382 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber());
3383 for (int i = 0; i < 100 && connection_.connected(); ++i) { 3383 for (int i = 0; i < 100 && connection_.connected(); ++i) {
3384 VLOG(1) << "sending data packet"; 3384 VLOG(1) << "sending data packet";
3385 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, !kFin, 3385 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, !kFin,
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
3521 connection_.SetFromConfig(config); 3521 connection_.SetFromConfig(config);
3522 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); 3522 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
3523 EXPECT_EQ(payload.size(), 3523 EXPECT_EQ(payload.size(),
3524 connection_.SendStreamDataWithString(3, payload, 0, !kFin, nullptr) 3524 connection_.SendStreamDataWithString(3, payload, 0, !kFin, nullptr)
3525 .bytes_consumed); 3525 .bytes_consumed);
3526 // Just like above, we save 8 bytes on payload, and 8 on truncation. 3526 // Just like above, we save 8 bytes on payload, and 8 on truncation.
3527 EXPECT_EQ(non_truncated_packet_size, writer_->last_packet_size() + 8 * 2); 3527 EXPECT_EQ(non_truncated_packet_size, writer_->last_packet_size() + 8 * 2);
3528 } 3528 }
3529 3529
3530 TEST_P(QuicConnectionTest, SendDelayedAck) { 3530 TEST_P(QuicConnectionTest, SendDelayedAck) {
3531 QuicTime ack_time = clock_.ApproximateNow().Add(DefaultDelayedAckTime()); 3531 QuicTime ack_time = clock_.ApproximateNow() + DefaultDelayedAckTime();
3532 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3532 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3533 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 3533 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3534 const uint8_t tag = 0x07; 3534 const uint8_t tag = 0x07;
3535 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); 3535 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag));
3536 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 3536 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
3537 // Process a packet from the non-crypto stream. 3537 // Process a packet from the non-crypto stream.
3538 frame1_.stream_id = 3; 3538 frame1_.stream_id = 3;
3539 3539
3540 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used 3540 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used
3541 // instead of ENCRYPTION_NONE. 3541 // instead of ENCRYPTION_NONE.
(...skipping 15 matching lines...) Expand all
3557 3557
3558 TEST_P(QuicConnectionTest, SendDelayedAckDecimation) { 3558 TEST_P(QuicConnectionTest, SendDelayedAckDecimation) {
3559 QuicConnectionPeer::SetAckMode(&connection_, QuicConnection::ACK_DECIMATION); 3559 QuicConnectionPeer::SetAckMode(&connection_, QuicConnection::ACK_DECIMATION);
3560 3560
3561 const size_t kMinRttMs = 40; 3561 const size_t kMinRttMs = 40;
3562 RttStats* rtt_stats = const_cast<RttStats*>(manager_->GetRttStats()); 3562 RttStats* rtt_stats = const_cast<RttStats*>(manager_->GetRttStats());
3563 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(kMinRttMs), 3563 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(kMinRttMs),
3564 QuicTime::Delta::Zero(), QuicTime::Zero()); 3564 QuicTime::Delta::Zero(), QuicTime::Zero());
3565 // The ack time should be based on min_rtt/4, since it's less than the 3565 // The ack time should be based on min_rtt/4, since it's less than the
3566 // default delayed ack time. 3566 // default delayed ack time.
3567 QuicTime ack_time = clock_.ApproximateNow().Add( 3567 QuicTime ack_time = clock_.ApproximateNow() +
3568 QuicTime::Delta::FromMilliseconds(kMinRttMs / 4)); 3568 QuicTime::Delta::FromMilliseconds(kMinRttMs / 4);
3569 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3569 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3570 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 3570 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3571 const uint8_t tag = 0x07; 3571 const uint8_t tag = 0x07;
3572 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); 3572 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag));
3573 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 3573 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
3574 // Process a packet from the non-crypto stream. 3574 // Process a packet from the non-crypto stream.
3575 frame1_.stream_id = 3; 3575 frame1_.stream_id = 3;
3576 3576
3577 // Process all the initial packets in order so there aren't missing packets. 3577 // Process all the initial packets in order so there aren't missing packets.
3578 QuicPacketNumber kFirstDecimatedPacket = 101; 3578 QuicPacketNumber kFirstDecimatedPacket = 101;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
3610 TEST_P(QuicConnectionTest, SendDelayedAckDecimationEighthRtt) { 3610 TEST_P(QuicConnectionTest, SendDelayedAckDecimationEighthRtt) {
3611 QuicConnectionPeer::SetAckMode(&connection_, QuicConnection::ACK_DECIMATION); 3611 QuicConnectionPeer::SetAckMode(&connection_, QuicConnection::ACK_DECIMATION);
3612 QuicConnectionPeer::SetAckDecimationDelay(&connection_, 0.125); 3612 QuicConnectionPeer::SetAckDecimationDelay(&connection_, 0.125);
3613 3613
3614 const size_t kMinRttMs = 40; 3614 const size_t kMinRttMs = 40;
3615 RttStats* rtt_stats = const_cast<RttStats*>(manager_->GetRttStats()); 3615 RttStats* rtt_stats = const_cast<RttStats*>(manager_->GetRttStats());
3616 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(kMinRttMs), 3616 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(kMinRttMs),
3617 QuicTime::Delta::Zero(), QuicTime::Zero()); 3617 QuicTime::Delta::Zero(), QuicTime::Zero());
3618 // The ack time should be based on min_rtt/8, since it's less than the 3618 // The ack time should be based on min_rtt/8, since it's less than the
3619 // default delayed ack time. 3619 // default delayed ack time.
3620 QuicTime ack_time = clock_.ApproximateNow().Add( 3620 QuicTime ack_time = clock_.ApproximateNow() +
3621 QuicTime::Delta::FromMilliseconds(kMinRttMs / 8)); 3621 QuicTime::Delta::FromMilliseconds(kMinRttMs / 8);
3622 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3622 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3623 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 3623 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3624 const uint8_t tag = 0x07; 3624 const uint8_t tag = 0x07;
3625 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); 3625 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag));
3626 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 3626 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
3627 // Process a packet from the non-crypto stream. 3627 // Process a packet from the non-crypto stream.
3628 frame1_.stream_id = 3; 3628 frame1_.stream_id = 3;
3629 3629
3630 // Process all the initial packets in order so there aren't missing packets. 3630 // Process all the initial packets in order so there aren't missing packets.
3631 QuicPacketNumber kFirstDecimatedPacket = 101; 3631 QuicPacketNumber kFirstDecimatedPacket = 101;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
3663 TEST_P(QuicConnectionTest, SendDelayedAckDecimationWithReordering) { 3663 TEST_P(QuicConnectionTest, SendDelayedAckDecimationWithReordering) {
3664 QuicConnectionPeer::SetAckMode( 3664 QuicConnectionPeer::SetAckMode(
3665 &connection_, QuicConnection::ACK_DECIMATION_WITH_REORDERING); 3665 &connection_, QuicConnection::ACK_DECIMATION_WITH_REORDERING);
3666 3666
3667 const size_t kMinRttMs = 40; 3667 const size_t kMinRttMs = 40;
3668 RttStats* rtt_stats = const_cast<RttStats*>(manager_->GetRttStats()); 3668 RttStats* rtt_stats = const_cast<RttStats*>(manager_->GetRttStats());
3669 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(kMinRttMs), 3669 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(kMinRttMs),
3670 QuicTime::Delta::Zero(), QuicTime::Zero()); 3670 QuicTime::Delta::Zero(), QuicTime::Zero());
3671 // The ack time should be based on min_rtt/4, since it's less than the 3671 // The ack time should be based on min_rtt/4, since it's less than the
3672 // default delayed ack time. 3672 // default delayed ack time.
3673 QuicTime ack_time = clock_.ApproximateNow().Add( 3673 QuicTime ack_time = clock_.ApproximateNow() +
3674 QuicTime::Delta::FromMilliseconds(kMinRttMs / 4)); 3674 QuicTime::Delta::FromMilliseconds(kMinRttMs / 4);
3675 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3675 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3676 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 3676 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3677 const uint8_t tag = 0x07; 3677 const uint8_t tag = 0x07;
3678 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); 3678 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag));
3679 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 3679 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
3680 // Process a packet from the non-crypto stream. 3680 // Process a packet from the non-crypto stream.
3681 frame1_.stream_id = 3; 3681 frame1_.stream_id = 3;
3682 3682
3683 // Process all the initial packets in order so there aren't missing packets. 3683 // Process all the initial packets in order so there aren't missing packets.
3684 QuicPacketNumber kFirstDecimatedPacket = 101; 3684 QuicPacketNumber kFirstDecimatedPacket = 101;
(...skipping 10 matching lines...) Expand all
3695 !kHasStopWaiting, ENCRYPTION_INITIAL); 3695 !kHasStopWaiting, ENCRYPTION_INITIAL);
3696 3696
3697 // Check if delayed ack timer is running for the expected interval. 3697 // Check if delayed ack timer is running for the expected interval.
3698 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); 3698 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
3699 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); 3699 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline());
3700 3700
3701 // Process packet 10 first and ensure the alarm is one eighth min_rtt. 3701 // Process packet 10 first and ensure the alarm is one eighth min_rtt.
3702 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); 3702 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3703 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 9, 3703 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 9,
3704 !kEntropyFlag, !kHasStopWaiting, ENCRYPTION_INITIAL); 3704 !kEntropyFlag, !kHasStopWaiting, ENCRYPTION_INITIAL);
3705 ack_time = clock_.ApproximateNow().Add(QuicTime::Delta::FromMilliseconds(5)); 3705 ack_time = clock_.ApproximateNow() + QuicTime::Delta::FromMilliseconds(5);
3706 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); 3706 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
3707 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); 3707 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline());
3708 3708
3709 // The 10th received packet causes an ack to be sent. 3709 // The 10th received packet causes an ack to be sent.
3710 for (int i = 0; i < 8; ++i) { 3710 for (int i = 0; i < 8; ++i) {
3711 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); 3711 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
3712 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); 3712 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3713 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 1 + i, 3713 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 1 + i,
3714 !kEntropyFlag, !kHasStopWaiting, 3714 !kEntropyFlag, !kHasStopWaiting,
3715 ENCRYPTION_INITIAL); 3715 ENCRYPTION_INITIAL);
3716 } 3716 }
3717 // Check that ack is sent and that delayed ack alarm is reset. 3717 // Check that ack is sent and that delayed ack alarm is reset.
3718 EXPECT_EQ(2u, writer_->frame_count()); 3718 EXPECT_EQ(2u, writer_->frame_count());
3719 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); 3719 EXPECT_FALSE(writer_->stop_waiting_frames().empty());
3720 EXPECT_FALSE(writer_->ack_frames().empty()); 3720 EXPECT_FALSE(writer_->ack_frames().empty());
3721 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 3721 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3722 } 3722 }
3723 3723
3724 TEST_P(QuicConnectionTest, SendDelayedAckDecimationWithLargeReordering) { 3724 TEST_P(QuicConnectionTest, SendDelayedAckDecimationWithLargeReordering) {
3725 QuicConnectionPeer::SetAckMode( 3725 QuicConnectionPeer::SetAckMode(
3726 &connection_, QuicConnection::ACK_DECIMATION_WITH_REORDERING); 3726 &connection_, QuicConnection::ACK_DECIMATION_WITH_REORDERING);
3727 3727
3728 const size_t kMinRttMs = 40; 3728 const size_t kMinRttMs = 40;
3729 RttStats* rtt_stats = const_cast<RttStats*>(manager_->GetRttStats()); 3729 RttStats* rtt_stats = const_cast<RttStats*>(manager_->GetRttStats());
3730 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(kMinRttMs), 3730 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(kMinRttMs),
3731 QuicTime::Delta::Zero(), QuicTime::Zero()); 3731 QuicTime::Delta::Zero(), QuicTime::Zero());
3732 // The ack time should be based on min_rtt/4, since it's less than the 3732 // The ack time should be based on min_rtt/4, since it's less than the
3733 // default delayed ack time. 3733 // default delayed ack time.
3734 QuicTime ack_time = clock_.ApproximateNow().Add( 3734 QuicTime ack_time = clock_.ApproximateNow() +
3735 QuicTime::Delta::FromMilliseconds(kMinRttMs / 4)); 3735 QuicTime::Delta::FromMilliseconds(kMinRttMs / 4);
3736 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3736 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3737 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 3737 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3738 const uint8_t tag = 0x07; 3738 const uint8_t tag = 0x07;
3739 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); 3739 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag));
3740 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 3740 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
3741 // Process a packet from the non-crypto stream. 3741 // Process a packet from the non-crypto stream.
3742 frame1_.stream_id = 3; 3742 frame1_.stream_id = 3;
3743 3743
3744 // Process all the initial packets in order so there aren't missing packets. 3744 // Process all the initial packets in order so there aren't missing packets.
3745 QuicPacketNumber kFirstDecimatedPacket = 101; 3745 QuicPacketNumber kFirstDecimatedPacket = 101;
(...skipping 10 matching lines...) Expand all
3756 !kHasStopWaiting, ENCRYPTION_INITIAL); 3756 !kHasStopWaiting, ENCRYPTION_INITIAL);
3757 3757
3758 // Check if delayed ack timer is running for the expected interval. 3758 // Check if delayed ack timer is running for the expected interval.
3759 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); 3759 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
3760 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); 3760 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline());
3761 3761
3762 // Process packet 10 first and ensure the alarm is one eighth min_rtt. 3762 // Process packet 10 first and ensure the alarm is one eighth min_rtt.
3763 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); 3763 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3764 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 19, 3764 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 19,
3765 !kEntropyFlag, !kHasStopWaiting, ENCRYPTION_INITIAL); 3765 !kEntropyFlag, !kHasStopWaiting, ENCRYPTION_INITIAL);
3766 ack_time = clock_.ApproximateNow().Add(QuicTime::Delta::FromMilliseconds(5)); 3766 ack_time = clock_.ApproximateNow() + QuicTime::Delta::FromMilliseconds(5);
3767 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); 3767 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
3768 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); 3768 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline());
3769 3769
3770 // The 10th received packet causes an ack to be sent. 3770 // The 10th received packet causes an ack to be sent.
3771 for (int i = 0; i < 8; ++i) { 3771 for (int i = 0; i < 8; ++i) {
3772 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); 3772 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
3773 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); 3773 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3774 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 1 + i, 3774 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 1 + i,
3775 !kEntropyFlag, !kHasStopWaiting, 3775 !kEntropyFlag, !kHasStopWaiting,
3776 ENCRYPTION_INITIAL); 3776 ENCRYPTION_INITIAL);
(...skipping 21 matching lines...) Expand all
3798 QuicConnectionPeer::SetAckMode( 3798 QuicConnectionPeer::SetAckMode(
3799 &connection_, QuicConnection::ACK_DECIMATION_WITH_REORDERING); 3799 &connection_, QuicConnection::ACK_DECIMATION_WITH_REORDERING);
3800 QuicConnectionPeer::SetAckDecimationDelay(&connection_, 0.125); 3800 QuicConnectionPeer::SetAckDecimationDelay(&connection_, 0.125);
3801 3801
3802 const size_t kMinRttMs = 40; 3802 const size_t kMinRttMs = 40;
3803 RttStats* rtt_stats = const_cast<RttStats*>(manager_->GetRttStats()); 3803 RttStats* rtt_stats = const_cast<RttStats*>(manager_->GetRttStats());
3804 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(kMinRttMs), 3804 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(kMinRttMs),
3805 QuicTime::Delta::Zero(), QuicTime::Zero()); 3805 QuicTime::Delta::Zero(), QuicTime::Zero());
3806 // The ack time should be based on min_rtt/8, since it's less than the 3806 // The ack time should be based on min_rtt/8, since it's less than the
3807 // default delayed ack time. 3807 // default delayed ack time.
3808 QuicTime ack_time = clock_.ApproximateNow().Add( 3808 QuicTime ack_time = clock_.ApproximateNow() +
3809 QuicTime::Delta::FromMilliseconds(kMinRttMs / 8)); 3809 QuicTime::Delta::FromMilliseconds(kMinRttMs / 8);
3810 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3810 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3811 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 3811 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3812 const uint8_t tag = 0x07; 3812 const uint8_t tag = 0x07;
3813 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); 3813 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag));
3814 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 3814 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
3815 // Process a packet from the non-crypto stream. 3815 // Process a packet from the non-crypto stream.
3816 frame1_.stream_id = 3; 3816 frame1_.stream_id = 3;
3817 3817
3818 // Process all the initial packets in order so there aren't missing packets. 3818 // Process all the initial packets in order so there aren't missing packets.
3819 QuicPacketNumber kFirstDecimatedPacket = 101; 3819 QuicPacketNumber kFirstDecimatedPacket = 101;
(...skipping 10 matching lines...) Expand all
3830 !kHasStopWaiting, ENCRYPTION_INITIAL); 3830 !kHasStopWaiting, ENCRYPTION_INITIAL);
3831 3831
3832 // Check if delayed ack timer is running for the expected interval. 3832 // Check if delayed ack timer is running for the expected interval.
3833 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); 3833 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
3834 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); 3834 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline());
3835 3835
3836 // Process packet 10 first and ensure the alarm is one eighth min_rtt. 3836 // Process packet 10 first and ensure the alarm is one eighth min_rtt.
3837 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); 3837 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3838 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 9, 3838 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 9,
3839 !kEntropyFlag, !kHasStopWaiting, ENCRYPTION_INITIAL); 3839 !kEntropyFlag, !kHasStopWaiting, ENCRYPTION_INITIAL);
3840 ack_time = clock_.ApproximateNow().Add(QuicTime::Delta::FromMilliseconds(5)); 3840 ack_time = clock_.ApproximateNow() + QuicTime::Delta::FromMilliseconds(5);
3841 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); 3841 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
3842 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); 3842 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline());
3843 3843
3844 // The 10th received packet causes an ack to be sent. 3844 // The 10th received packet causes an ack to be sent.
3845 for (int i = 0; i < 8; ++i) { 3845 for (int i = 0; i < 8; ++i) {
3846 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); 3846 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
3847 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); 3847 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3848 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 1 + i, 3848 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 1 + i,
3849 !kEntropyFlag, !kHasStopWaiting, 3849 !kEntropyFlag, !kHasStopWaiting,
3850 ENCRYPTION_INITIAL); 3850 ENCRYPTION_INITIAL);
(...skipping 10 matching lines...) Expand all
3861 QuicConnectionPeer::SetAckMode( 3861 QuicConnectionPeer::SetAckMode(
3862 &connection_, QuicConnection::ACK_DECIMATION_WITH_REORDERING); 3862 &connection_, QuicConnection::ACK_DECIMATION_WITH_REORDERING);
3863 QuicConnectionPeer::SetAckDecimationDelay(&connection_, 0.125); 3863 QuicConnectionPeer::SetAckDecimationDelay(&connection_, 0.125);
3864 3864
3865 const size_t kMinRttMs = 40; 3865 const size_t kMinRttMs = 40;
3866 RttStats* rtt_stats = const_cast<RttStats*>(manager_->GetRttStats()); 3866 RttStats* rtt_stats = const_cast<RttStats*>(manager_->GetRttStats());
3867 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(kMinRttMs), 3867 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(kMinRttMs),
3868 QuicTime::Delta::Zero(), QuicTime::Zero()); 3868 QuicTime::Delta::Zero(), QuicTime::Zero());
3869 // The ack time should be based on min_rtt/8, since it's less than the 3869 // The ack time should be based on min_rtt/8, since it's less than the
3870 // default delayed ack time. 3870 // default delayed ack time.
3871 QuicTime ack_time = clock_.ApproximateNow().Add( 3871 QuicTime ack_time = clock_.ApproximateNow() +
3872 QuicTime::Delta::FromMilliseconds(kMinRttMs / 8)); 3872 QuicTime::Delta::FromMilliseconds(kMinRttMs / 8);
3873 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3873 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3874 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 3874 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3875 const uint8_t tag = 0x07; 3875 const uint8_t tag = 0x07;
3876 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); 3876 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag));
3877 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 3877 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
3878 // Process a packet from the non-crypto stream. 3878 // Process a packet from the non-crypto stream.
3879 frame1_.stream_id = 3; 3879 frame1_.stream_id = 3;
3880 3880
3881 // Process all the initial packets in order so there aren't missing packets. 3881 // Process all the initial packets in order so there aren't missing packets.
3882 QuicPacketNumber kFirstDecimatedPacket = 101; 3882 QuicPacketNumber kFirstDecimatedPacket = 101;
(...skipping 10 matching lines...) Expand all
3893 !kHasStopWaiting, ENCRYPTION_INITIAL); 3893 !kHasStopWaiting, ENCRYPTION_INITIAL);
3894 3894
3895 // Check if delayed ack timer is running for the expected interval. 3895 // Check if delayed ack timer is running for the expected interval.
3896 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); 3896 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
3897 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); 3897 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline());
3898 3898
3899 // Process packet 10 first and ensure the alarm is one eighth min_rtt. 3899 // Process packet 10 first and ensure the alarm is one eighth min_rtt.
3900 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); 3900 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3901 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 19, 3901 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 19,
3902 !kEntropyFlag, !kHasStopWaiting, ENCRYPTION_INITIAL); 3902 !kEntropyFlag, !kHasStopWaiting, ENCRYPTION_INITIAL);
3903 ack_time = clock_.ApproximateNow().Add(QuicTime::Delta::FromMilliseconds(5)); 3903 ack_time = clock_.ApproximateNow() + QuicTime::Delta::FromMilliseconds(5);
3904 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); 3904 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
3905 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); 3905 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline());
3906 3906
3907 // The 10th received packet causes an ack to be sent. 3907 // The 10th received packet causes an ack to be sent.
3908 for (int i = 0; i < 8; ++i) { 3908 for (int i = 0; i < 8; ++i) {
3909 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); 3909 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
3910 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); 3910 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3911 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 1 + i, 3911 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 1 + i,
3912 !kEntropyFlag, !kHasStopWaiting, 3912 !kEntropyFlag, !kHasStopWaiting,
3913 ENCRYPTION_INITIAL); 3913 ENCRYPTION_INITIAL);
(...skipping 15 matching lines...) Expand all
3929 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); 3929 EXPECT_FALSE(writer_->stop_waiting_frames().empty());
3930 EXPECT_FALSE(writer_->ack_frames().empty()); 3930 EXPECT_FALSE(writer_->ack_frames().empty());
3931 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 3931 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3932 } 3932 }
3933 3933
3934 TEST_P(QuicConnectionTest, SendDelayedAckOnHandshakeConfirmed) { 3934 TEST_P(QuicConnectionTest, SendDelayedAckOnHandshakeConfirmed) {
3935 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3935 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3936 ProcessPacket(kDefaultPathId, 1); 3936 ProcessPacket(kDefaultPathId, 1);
3937 // Check that ack is sent and that delayed ack alarm is set. 3937 // Check that ack is sent and that delayed ack alarm is set.
3938 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); 3938 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
3939 QuicTime ack_time = clock_.ApproximateNow().Add(DefaultDelayedAckTime()); 3939 QuicTime ack_time = clock_.ApproximateNow() + DefaultDelayedAckTime();
3940 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); 3940 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline());
3941 3941
3942 // Completing the handshake as the server does nothing. 3942 // Completing the handshake as the server does nothing.
3943 QuicConnectionPeer::SetPerspective(&connection_, Perspective::IS_SERVER); 3943 QuicConnectionPeer::SetPerspective(&connection_, Perspective::IS_SERVER);
3944 connection_.OnHandshakeComplete(); 3944 connection_.OnHandshakeComplete();
3945 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); 3945 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
3946 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); 3946 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline());
3947 3947
3948 // Complete the handshake as the client decreases the delayed ack time to 0ms. 3948 // Complete the handshake as the client decreases the delayed ack time to 0ms.
3949 QuicConnectionPeer::SetPerspective(&connection_, Perspective::IS_CLIENT); 3949 QuicConnectionPeer::SetPerspective(&connection_, Perspective::IS_CLIENT);
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after
4654 // AckNotifierCallback is triggered by the ack of a packet that timed 4654 // AckNotifierCallback is triggered by the ack of a packet that timed
4655 // out and was retransmitted, even though the retransmission has a 4655 // out and was retransmitted, even though the retransmission has a
4656 // different packet number. 4656 // different packet number.
4657 TEST_P(QuicConnectionTest, AckNotifierCallbackForAckAfterRTO) { 4657 TEST_P(QuicConnectionTest, AckNotifierCallbackForAckAfterRTO) {
4658 connection_.DisableTailLossProbe(); 4658 connection_.DisableTailLossProbe();
4659 4659
4660 // Create a listener which we expect to be called. 4660 // Create a listener which we expect to be called.
4661 scoped_refptr<MockAckListener> listener(new StrictMock<MockAckListener>); 4661 scoped_refptr<MockAckListener> listener(new StrictMock<MockAckListener>);
4662 4662
4663 QuicTime default_retransmission_time = 4663 QuicTime default_retransmission_time =
4664 clock_.ApproximateNow().Add(DefaultRetransmissionTime()); 4664 clock_.ApproximateNow() + DefaultRetransmissionTime();
4665 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, listener.get()); 4665 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, listener.get());
4666 EXPECT_EQ(1u, stop_waiting()->least_unacked); 4666 EXPECT_EQ(1u, stop_waiting()->least_unacked);
4667 4667
4668 EXPECT_EQ(1u, writer_->header().packet_number); 4668 EXPECT_EQ(1u, writer_->header().packet_number);
4669 EXPECT_EQ(default_retransmission_time, 4669 EXPECT_EQ(default_retransmission_time,
4670 connection_.GetRetransmissionAlarm()->deadline()); 4670 connection_.GetRetransmissionAlarm()->deadline());
4671 // Simulate the retransmission alarm firing. 4671 // Simulate the retransmission alarm firing.
4672 clock_.AdvanceTime(DefaultRetransmissionTime()); 4672 clock_.AdvanceTime(DefaultRetransmissionTime());
4673 EXPECT_CALL(*listener, OnPacketRetransmitted(3)); 4673 EXPECT_CALL(*listener, OnPacketRetransmitted(3));
4674 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _)); 4674 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _));
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
4810 TEST_P(QuicConnectionTest, ReevaluateTimeUntilSendOnAck) { 4810 TEST_P(QuicConnectionTest, ReevaluateTimeUntilSendOnAck) {
4811 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4811 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4812 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, !kFin, 4812 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, !kFin,
4813 nullptr); 4813 nullptr);
4814 4814
4815 // Evaluate CanWrite, and have it return a non-Zero value. 4815 // Evaluate CanWrite, and have it return a non-Zero value.
4816 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)) 4816 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _))
4817 .WillRepeatedly(Return(QuicTime::Delta::FromMilliseconds(1))); 4817 .WillRepeatedly(Return(QuicTime::Delta::FromMilliseconds(1)));
4818 connection_.OnCanWrite(); 4818 connection_.OnCanWrite();
4819 EXPECT_TRUE(connection_.GetSendAlarm()->IsSet()); 4819 EXPECT_TRUE(connection_.GetSendAlarm()->IsSet());
4820 EXPECT_EQ(clock_.Now().Add(QuicTime::Delta::FromMilliseconds(1)), 4820 EXPECT_EQ(clock_.Now() + QuicTime::Delta::FromMilliseconds(1),
4821 connection_.GetSendAlarm()->deadline()); 4821 connection_.GetSendAlarm()->deadline());
4822 4822
4823 // Process an ack and the send alarm will be set to the new 2ms delay. 4823 // Process an ack and the send alarm will be set to the new 2ms delay.
4824 QuicAckFrame ack = InitAckFrame(1); 4824 QuicAckFrame ack = InitAckFrame(1);
4825 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)); 4825 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _));
4826 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 4826 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
4827 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)) 4827 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _))
4828 .WillRepeatedly(Return(QuicTime::Delta::FromMilliseconds(2))); 4828 .WillRepeatedly(Return(QuicTime::Delta::FromMilliseconds(2)));
4829 ProcessAckPacket(&ack); 4829 ProcessAckPacket(&ack);
4830 EXPECT_EQ(1u, writer_->frame_count()); 4830 EXPECT_EQ(1u, writer_->frame_count());
4831 EXPECT_EQ(1u, writer_->stream_frames().size()); 4831 EXPECT_EQ(1u, writer_->stream_frames().size());
4832 EXPECT_TRUE(connection_.GetSendAlarm()->IsSet()); 4832 EXPECT_TRUE(connection_.GetSendAlarm()->IsSet());
4833 EXPECT_EQ(clock_.Now().Add(QuicTime::Delta::FromMilliseconds(2)), 4833 EXPECT_EQ(clock_.Now() + QuicTime::Delta::FromMilliseconds(2),
4834 connection_.GetSendAlarm()->deadline()); 4834 connection_.GetSendAlarm()->deadline());
4835 writer_->Reset(); 4835 writer_->Reset();
4836 } 4836 }
4837 4837
4838 TEST_P(QuicConnectionTest, SendAcksImmediately) { 4838 TEST_P(QuicConnectionTest, SendAcksImmediately) {
4839 CongestionBlockWrites(); 4839 CongestionBlockWrites();
4840 SendAckPacketToPeer(); 4840 SendAckPacketToPeer();
4841 } 4841 }
4842 4842
4843 TEST_P(QuicConnectionTest, SendPingImmediately) { 4843 TEST_P(QuicConnectionTest, SendPingImmediately) {
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
4975 frame1_.data_length = data->length(); 4975 frame1_.data_length = data->length();
4976 4976
4977 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_MAYBE_CORRUPTED_MEMORY, _, 4977 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_MAYBE_CORRUPTED_MEMORY, _,
4978 ConnectionCloseSource::FROM_SELF)); 4978 ConnectionCloseSource::FROM_SELF));
4979 ProcessFramePacket(QuicFrame(&frame1_)); 4979 ProcessFramePacket(QuicFrame(&frame1_));
4980 } 4980 }
4981 4981
4982 } // namespace 4982 } // namespace
4983 } // namespace test 4983 } // namespace test
4984 } // namespace net 4984 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection_logger.cc ('k') | net/quic/quic_crypto_client_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698