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

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

Issue 1785693003: Deprecate FLAG_quic_use_new_idle_timeout (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@115891009
Patch Set: Created 4 years, 9 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.cc ('k') | net/quic/quic_flags.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 <ostream> 7 #include <ostream>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 3880 matching lines...) Expand 10 before | Expand all | Expand 10 after
3891 SendStreamDataToPeer(3, "!", kPacketsBetweenMtuProbesBase, 3891 SendStreamDataToPeer(3, "!", kPacketsBetweenMtuProbesBase,
3892 /*fin=*/false, nullptr); 3892 /*fin=*/false, nullptr);
3893 EXPECT_TRUE(connection_.GetMtuDiscoveryAlarm()->IsSet()); 3893 EXPECT_TRUE(connection_.GetMtuDiscoveryAlarm()->IsSet());
3894 3894
3895 EXPECT_CALL(visitor_, OnConnectionClosed(_, _)); 3895 EXPECT_CALL(visitor_, OnConnectionClosed(_, _));
3896 connection_.CloseConnection(QUIC_INTERNAL_ERROR, 3896 connection_.CloseConnection(QUIC_INTERNAL_ERROR,
3897 ConnectionCloseSource::FROM_SELF); 3897 ConnectionCloseSource::FROM_SELF);
3898 EXPECT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet()); 3898 EXPECT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet());
3899 } 3899 }
3900 3900
3901 TEST_P(QuicConnectionTest, OldTimeoutAfterSend) { 3901 TEST_P(QuicConnectionTest, TimeoutAfterSend) {
3902 ValueRestore<bool> old_flags(&FLAGS_quic_use_new_idle_timeout, false);
3903 EXPECT_TRUE(connection_.connected()); 3902 EXPECT_TRUE(connection_.connected());
3904 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); 3903 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
3905 QuicConfig config; 3904 QuicConfig config;
3906 connection_.SetFromConfig(config);
3907 EXPECT_FALSE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_));
3908
3909 const QuicTime::Delta initial_idle_timeout =
3910 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1);
3911 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5);
3912 QuicTime default_timeout = clock_.ApproximateNow().Add(initial_idle_timeout);
3913
3914 // When we send a packet, the timeout will change to 5ms +
3915 // kInitialIdleTimeoutSecs.
3916 clock_.AdvanceTime(five_ms);
3917
3918 // Send an ack so we don't set the retransmission alarm.
3919 SendAckPacketToPeer();
3920 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
3921
3922 // The original alarm will fire. We should not time out because we had a
3923 // network event at t=5ms. The alarm will reregister.
3924 clock_.AdvanceTime(initial_idle_timeout.Subtract(five_ms));
3925 EXPECT_EQ(default_timeout, clock_.ApproximateNow());
3926 connection_.GetTimeoutAlarm()->Fire();
3927 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet());
3928 EXPECT_TRUE(connection_.connected());
3929 EXPECT_EQ(default_timeout.Add(five_ms),
3930 connection_.GetTimeoutAlarm()->deadline());
3931
3932 // This time, we should time out.
3933 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_NETWORK_IDLE_TIMEOUT,
3934 ConnectionCloseSource::FROM_SELF));
3935 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
3936 clock_.AdvanceTime(five_ms);
3937 EXPECT_EQ(default_timeout.Add(five_ms), clock_.ApproximateNow());
3938 connection_.GetTimeoutAlarm()->Fire();
3939 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
3940 EXPECT_FALSE(connection_.connected());
3941 }
3942
3943 TEST_P(QuicConnectionTest, OldTimeoutAfterSendSilentClose) {
3944 ValueRestore<bool> old_flags(&FLAGS_quic_use_new_idle_timeout, false);
3945 // Same test as above, but complete a handshake which enables silent close,
3946 // causing no connection close packet to be sent.
3947 EXPECT_TRUE(connection_.connected());
3948 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
3949 QuicConfig config;
3950
3951 // Create a handshake message that also enables silent close.
3952 CryptoHandshakeMessage msg;
3953 string error_details;
3954 QuicConfig client_config;
3955 client_config.SetInitialStreamFlowControlWindowToSend(
3956 kInitialStreamFlowControlWindowForTest);
3957 client_config.SetInitialSessionFlowControlWindowToSend(
3958 kInitialSessionFlowControlWindowForTest);
3959 client_config.SetIdleConnectionStateLifetime(
3960 QuicTime::Delta::FromSeconds(kDefaultIdleTimeoutSecs),
3961 QuicTime::Delta::FromSeconds(kDefaultIdleTimeoutSecs));
3962 client_config.ToHandshakeMessage(&msg);
3963 const QuicErrorCode error =
3964 config.ProcessPeerHello(msg, CLIENT, &error_details);
3965 EXPECT_EQ(QUIC_NO_ERROR, error);
3966
3967 connection_.SetFromConfig(config);
3968 EXPECT_TRUE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_));
3969
3970 const QuicTime::Delta default_idle_timeout =
3971 QuicTime::Delta::FromSeconds(kDefaultIdleTimeoutSecs - 1);
3972 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5);
3973 QuicTime default_timeout = clock_.ApproximateNow().Add(default_idle_timeout);
3974
3975 // When we send a packet, the timeout will change to 5ms +
3976 // kInitialIdleTimeoutSecs.
3977 clock_.AdvanceTime(five_ms);
3978
3979 // Send an ack so we don't set the retransmission alarm.
3980 SendAckPacketToPeer();
3981 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
3982
3983 // The original alarm will fire. We should not time out because we had a
3984 // network event at t=5ms. The alarm will reregister.
3985 clock_.AdvanceTime(default_idle_timeout.Subtract(five_ms));
3986 EXPECT_EQ(default_timeout, clock_.ApproximateNow());
3987 connection_.GetTimeoutAlarm()->Fire();
3988 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet());
3989 EXPECT_TRUE(connection_.connected());
3990 EXPECT_EQ(default_timeout.Add(five_ms),
3991 connection_.GetTimeoutAlarm()->deadline());
3992
3993 // This time, we should time out.
3994 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_NETWORK_IDLE_TIMEOUT,
3995 ConnectionCloseSource::FROM_SELF));
3996 clock_.AdvanceTime(five_ms);
3997 EXPECT_EQ(default_timeout.Add(five_ms), clock_.ApproximateNow());
3998 connection_.GetTimeoutAlarm()->Fire();
3999 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
4000 EXPECT_FALSE(connection_.connected());
4001 }
4002
4003 TEST_P(QuicConnectionTest, TimeoutAfterSend) {
4004 ValueRestore<bool> old_flags(&FLAGS_quic_use_new_idle_timeout, true);
4005 EXPECT_TRUE(connection_.connected());
4006 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
4007 QuicConfig config;
4008 connection_.SetFromConfig(config); 3905 connection_.SetFromConfig(config);
4009 EXPECT_FALSE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_)); 3906 EXPECT_FALSE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_));
4010 3907
4011 const QuicTime::Delta initial_idle_timeout = 3908 const QuicTime::Delta initial_idle_timeout =
4012 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1); 3909 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1);
4013 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5); 3910 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5);
4014 QuicTime default_timeout = clock_.ApproximateNow().Add(initial_idle_timeout); 3911 QuicTime default_timeout = clock_.ApproximateNow().Add(initial_idle_timeout);
4015 3912
4016 // When we send a packet, the timeout will change to 5ms + 3913 // When we send a packet, the timeout will change to 5ms +
4017 // kInitialIdleTimeoutSecs. 3914 // kInitialIdleTimeoutSecs.
(...skipping 22 matching lines...) Expand all
4040 ConnectionCloseSource::FROM_SELF)); 3937 ConnectionCloseSource::FROM_SELF));
4041 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 3938 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
4042 clock_.AdvanceTime(five_ms); 3939 clock_.AdvanceTime(five_ms);
4043 EXPECT_EQ(default_timeout.Add(five_ms), clock_.ApproximateNow()); 3940 EXPECT_EQ(default_timeout.Add(five_ms), clock_.ApproximateNow());
4044 connection_.GetTimeoutAlarm()->Fire(); 3941 connection_.GetTimeoutAlarm()->Fire();
4045 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 3942 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
4046 EXPECT_FALSE(connection_.connected()); 3943 EXPECT_FALSE(connection_.connected());
4047 } 3944 }
4048 3945
4049 TEST_P(QuicConnectionTest, NewTimeoutAfterSendSilentClose) { 3946 TEST_P(QuicConnectionTest, NewTimeoutAfterSendSilentClose) {
4050 ValueRestore<bool> old_flags(&FLAGS_quic_use_new_idle_timeout, true);
4051 // Same test as above, but complete a handshake which enables silent close, 3947 // Same test as above, but complete a handshake which enables silent close,
4052 // causing no connection close packet to be sent. 3948 // causing no connection close packet to be sent.
4053 EXPECT_TRUE(connection_.connected()); 3949 EXPECT_TRUE(connection_.connected());
4054 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); 3950 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
4055 QuicConfig config; 3951 QuicConfig config;
4056 3952
4057 // Create a handshake message that also enables silent close. 3953 // Create a handshake message that also enables silent close.
4058 CryptoHandshakeMessage msg; 3954 CryptoHandshakeMessage msg;
4059 string error_details; 3955 string error_details;
4060 QuicConfig client_config; 3956 QuicConfig client_config;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
4152 ConnectionCloseSource::FROM_SELF)); 4048 ConnectionCloseSource::FROM_SELF));
4153 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 4049 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
4154 clock_.AdvanceTime(five_ms); 4050 clock_.AdvanceTime(five_ms);
4155 EXPECT_EQ(default_timeout.Add(five_ms), clock_.ApproximateNow()); 4051 EXPECT_EQ(default_timeout.Add(five_ms), clock_.ApproximateNow());
4156 connection_.GetTimeoutAlarm()->Fire(); 4052 connection_.GetTimeoutAlarm()->Fire();
4157 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 4053 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
4158 EXPECT_FALSE(connection_.connected()); 4054 EXPECT_FALSE(connection_.connected());
4159 } 4055 }
4160 4056
4161 TEST_P(QuicConnectionTest, TimeoutAfterReceiveNotSendWhenUnacked) { 4057 TEST_P(QuicConnectionTest, TimeoutAfterReceiveNotSendWhenUnacked) {
4162 ValueRestore<bool> old_flags(&FLAGS_quic_use_new_idle_timeout, true);
4163 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4058 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4164 EXPECT_TRUE(connection_.connected()); 4059 EXPECT_TRUE(connection_.connected());
4165 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); 4060 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
4166 QuicConfig config; 4061 QuicConfig config;
4167 connection_.SetFromConfig(config); 4062 connection_.SetFromConfig(config);
4168 EXPECT_FALSE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_)); 4063 EXPECT_FALSE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_));
4169 4064
4170 const QuicTime::Delta initial_idle_timeout = 4065 const QuicTime::Delta initial_idle_timeout =
4171 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1); 4066 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1);
4172 connection_.SetNetworkTimeouts( 4067 connection_.SetNetworkTimeouts(
(...skipping 1559 matching lines...) Expand 10 before | Expand all | Expand 10 after
5732 // result in multiple attempts to close the connection - it will be marked as 5627 // result in multiple attempts to close the connection - it will be marked as
5733 // disconnected after the first call. 5628 // disconnected after the first call.
5734 EXPECT_CALL(visitor_, OnConnectionClosed(_, _)).Times(1); 5629 EXPECT_CALL(visitor_, OnConnectionClosed(_, _)).Times(1);
5735 connection_.SendConnectionCloseWithDetails(QUIC_NO_ERROR, "no reason"); 5630 connection_.SendConnectionCloseWithDetails(QUIC_NO_ERROR, "no reason");
5736 connection_.SendConnectionCloseWithDetails(QUIC_NO_ERROR, "no reason"); 5631 connection_.SendConnectionCloseWithDetails(QUIC_NO_ERROR, "no reason");
5737 } 5632 }
5738 5633
5739 } // namespace 5634 } // namespace
5740 } // namespace test 5635 } // namespace test
5741 } // namespace net 5636 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection.cc ('k') | net/quic/quic_flags.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698