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

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

Issue 2288843002: Fix QUIC connection's last_send_for_timeout_ (Closed)
Patch Set: Created 4 years, 3 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/core/quic_connection.cc ('k') | net/quic/core/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/core/quic_connection.h" 5 #include "net/quic/core/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 833 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 bool entropy_flag, 844 bool entropy_flag,
845 bool has_stop_waiting, 845 bool has_stop_waiting,
846 EncryptionLevel level) { 846 EncryptionLevel level) {
847 std::unique_ptr<QuicPacket> packet( 847 std::unique_ptr<QuicPacket> packet(
848 ConstructDataPacket(path_id, number, entropy_flag, has_stop_waiting)); 848 ConstructDataPacket(path_id, number, entropy_flag, has_stop_waiting));
849 char buffer[kMaxPacketSize]; 849 char buffer[kMaxPacketSize];
850 size_t encrypted_length = framer_.EncryptPayload( 850 size_t encrypted_length = framer_.EncryptPayload(
851 level, path_id, number, *packet, buffer, kMaxPacketSize); 851 level, path_id, number, *packet, buffer, kMaxPacketSize);
852 connection_.ProcessUdpPacket( 852 connection_.ProcessUdpPacket(
853 kSelfAddress, kPeerAddress, 853 kSelfAddress, kPeerAddress,
854 QuicReceivedPacket(buffer, encrypted_length, QuicTime::Zero(), false)); 854 QuicReceivedPacket(buffer, encrypted_length, clock_.Now(), false));
855 if (connection_.GetSendAlarm()->IsSet()) { 855 if (connection_.GetSendAlarm()->IsSet()) {
856 connection_.GetSendAlarm()->Fire(); 856 connection_.GetSendAlarm()->Fire();
857 } 857 }
858 return encrypted_length; 858 return encrypted_length;
859 } 859 }
860 860
861 void ProcessClosePacket(QuicPathId path_id, QuicPacketNumber number) { 861 void ProcessClosePacket(QuicPathId path_id, QuicPacketNumber number) {
862 std::unique_ptr<QuicPacket> packet(ConstructClosePacket(number)); 862 std::unique_ptr<QuicPacket> packet(ConstructClosePacket(number));
863 char buffer[kMaxPacketSize]; 863 char buffer[kMaxPacketSize];
864 size_t encrypted_length = framer_.EncryptPayload( 864 size_t encrypted_length = framer_.EncryptPayload(
(...skipping 2375 matching lines...) Expand 10 before | Expand all | Expand 10 after
3240 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, kFin, nullptr); 3240 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, kFin, nullptr);
3241 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); 3241 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
3242 3242
3243 // The original alarm will fire. We should not time out because we had a 3243 // The original alarm will fire. We should not time out because we had a
3244 // network event at t=5ms. The alarm will reregister. 3244 // network event at t=5ms. The alarm will reregister.
3245 clock_.AdvanceTime(initial_idle_timeout - five_ms - five_ms); 3245 clock_.AdvanceTime(initial_idle_timeout - five_ms - five_ms);
3246 EXPECT_EQ(default_timeout, clock_.ApproximateNow()); 3246 EXPECT_EQ(default_timeout, clock_.ApproximateNow());
3247 connection_.GetTimeoutAlarm()->Fire(); 3247 connection_.GetTimeoutAlarm()->Fire();
3248 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet()); 3248 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet());
3249 EXPECT_TRUE(connection_.connected()); 3249 EXPECT_TRUE(connection_.connected());
3250 EXPECT_EQ(default_timeout + five_ms + five_ms, 3250 if (FLAGS_quic_better_last_send_for_timeout) {
3251 connection_.GetTimeoutAlarm()->deadline()); 3251 EXPECT_EQ(default_timeout + five_ms,
3252 connection_.GetTimeoutAlarm()->deadline());
3253 } else {
3254 EXPECT_EQ(default_timeout + five_ms + five_ms,
3255 connection_.GetTimeoutAlarm()->deadline());
3256 }
3252 3257
3253 // This time, we should time out. 3258 // This time, we should time out.
3254 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_NETWORK_IDLE_TIMEOUT, _, 3259 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_NETWORK_IDLE_TIMEOUT, _,
3255 ConnectionCloseSource::FROM_SELF)); 3260 ConnectionCloseSource::FROM_SELF));
3256 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 3261 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
3257 clock_.AdvanceTime(five_ms); 3262 clock_.AdvanceTime(five_ms);
3258 EXPECT_EQ(default_timeout + five_ms, clock_.ApproximateNow()); 3263 EXPECT_EQ(default_timeout + five_ms, clock_.ApproximateNow());
3259 connection_.GetTimeoutAlarm()->Fire(); 3264 connection_.GetTimeoutAlarm()->Fire();
3260 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 3265 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
3261 EXPECT_FALSE(connection_.connected()); 3266 EXPECT_FALSE(connection_.connected());
3262 } 3267 }
3263 3268
3269 TEST_P(QuicConnectionTest, TimeoutAfterRetransmission) {
3270 FLAGS_quic_better_last_send_for_timeout = true;
3271 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3272 EXPECT_TRUE(connection_.connected());
3273 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
3274 QuicConfig config;
3275 connection_.SetFromConfig(config);
3276 EXPECT_FALSE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_));
3277
3278 const QuicTime start_time = clock_.Now();
3279 const QuicTime::Delta initial_idle_timeout =
3280 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1);
3281 QuicTime default_timeout = clock_.Now() + initial_idle_timeout;
3282
3283 connection_.SetMaxTailLossProbes(kDefaultPathId, 0);
3284 const QuicTime default_retransmission_time =
3285 start_time + DefaultRetransmissionTime();
3286
3287 ASSERT_LT(default_retransmission_time, default_timeout);
3288
3289 // When we send a packet, the timeout will change to 5 ms +
3290 // kInitialIdleTimeoutSecs (but it will not reschedule the alarm).
3291 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5);
3292 const QuicTime send_time = start_time + five_ms;
3293 clock_.AdvanceTime(five_ms);
3294 ASSERT_EQ(send_time, clock_.Now());
3295 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, kFin, nullptr);
3296 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
3297
3298 // Move forward 5 ms and receive a packet, which will move the timeout
3299 // forward 5 ms more (but will not reschedule the alarm).
3300 const QuicTime receive_time = send_time + five_ms;
3301 clock_.AdvanceTime(receive_time - clock_.Now());
3302 ASSERT_EQ(receive_time, clock_.Now());
3303 ProcessPacket(kDefaultPathId, 1);
3304
3305 // Now move forward to the retransmission time and retransmit the
3306 // packet, which should move the timeout forward again (but will not
3307 // reschedule the alarm).
3308 EXPECT_EQ(default_retransmission_time + five_ms,
3309 connection_.GetRetransmissionAlarm()->deadline());
3310 // Simulate the retransmission alarm firing.
3311 const QuicTime rto_time = send_time + DefaultRetransmissionTime();
3312 const QuicTime final_timeout = rto_time + initial_idle_timeout;
3313 clock_.AdvanceTime(rto_time - clock_.Now());
3314 ASSERT_EQ(rto_time, clock_.Now());
3315 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _));
3316 connection_.GetRetransmissionAlarm()->Fire();
3317
3318 // Advance to the original timeout and fire the alarm. The connection should
3319 // timeout, and the alarm should be registered based on the time of the
3320 // retransmission.
3321 clock_.AdvanceTime(default_timeout - clock_.Now());
3322 ASSERT_EQ(default_timeout.ToDebuggingValue(),
3323 clock_.Now().ToDebuggingValue());
3324 EXPECT_EQ(default_timeout, clock_.Now());
3325 connection_.GetTimeoutAlarm()->Fire();
3326 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet());
3327 EXPECT_TRUE(connection_.connected());
3328 ASSERT_EQ(final_timeout.ToDebuggingValue(),
3329 connection_.GetTimeoutAlarm()->deadline().ToDebuggingValue());
3330
3331 // This time, we should time out.
3332 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_NETWORK_IDLE_TIMEOUT, _,
3333 ConnectionCloseSource::FROM_SELF));
3334 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
3335 clock_.AdvanceTime(final_timeout - clock_.Now());
3336 EXPECT_EQ(connection_.GetTimeoutAlarm()->deadline(), clock_.Now());
3337 EXPECT_EQ(final_timeout, clock_.Now());
3338 connection_.GetTimeoutAlarm()->Fire();
3339 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
3340 EXPECT_FALSE(connection_.connected());
3341 }
3342
3264 TEST_P(QuicConnectionTest, NewTimeoutAfterSendSilentClose) { 3343 TEST_P(QuicConnectionTest, NewTimeoutAfterSendSilentClose) {
3265 // Same test as above, but complete a handshake which enables silent close, 3344 // Same test as above, but complete a handshake which enables silent close,
3266 // causing no connection close packet to be sent. 3345 // causing no connection close packet to be sent.
3267 EXPECT_TRUE(connection_.connected()); 3346 EXPECT_TRUE(connection_.connected());
3268 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); 3347 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
3269 QuicConfig config; 3348 QuicConfig config;
3270 3349
3271 // Create a handshake message that also enables silent close. 3350 // Create a handshake message that also enables silent close.
3272 CryptoHandshakeMessage msg; 3351 CryptoHandshakeMessage msg;
3273 string error_details; 3352 string error_details;
(...skipping 30 matching lines...) Expand all
3304 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, kFin, nullptr); 3383 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, kFin, nullptr);
3305 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); 3384 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
3306 3385
3307 // The original alarm will fire. We should not time out because we had a 3386 // The original alarm will fire. We should not time out because we had a
3308 // network event at t=5ms. The alarm will reregister. 3387 // network event at t=5ms. The alarm will reregister.
3309 clock_.AdvanceTime(default_idle_timeout - five_ms - five_ms); 3388 clock_.AdvanceTime(default_idle_timeout - five_ms - five_ms);
3310 EXPECT_EQ(default_timeout, clock_.ApproximateNow()); 3389 EXPECT_EQ(default_timeout, clock_.ApproximateNow());
3311 connection_.GetTimeoutAlarm()->Fire(); 3390 connection_.GetTimeoutAlarm()->Fire();
3312 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet()); 3391 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet());
3313 EXPECT_TRUE(connection_.connected()); 3392 EXPECT_TRUE(connection_.connected());
3314 EXPECT_EQ(default_timeout + five_ms + five_ms, 3393 if (FLAGS_quic_better_last_send_for_timeout) {
3315 connection_.GetTimeoutAlarm()->deadline()); 3394 EXPECT_EQ(default_timeout + five_ms,
3395 connection_.GetTimeoutAlarm()->deadline());
3396 } else {
3397 EXPECT_EQ(default_timeout + five_ms + five_ms,
3398 connection_.GetTimeoutAlarm()->deadline());
3399 }
3316 3400
3317 // This time, we should time out. 3401 // This time, we should time out.
3318 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_NETWORK_IDLE_TIMEOUT, _, 3402 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_NETWORK_IDLE_TIMEOUT, _,
3319 ConnectionCloseSource::FROM_SELF)); 3403 ConnectionCloseSource::FROM_SELF));
3320 clock_.AdvanceTime(five_ms); 3404 clock_.AdvanceTime(five_ms);
3321 EXPECT_EQ(default_timeout + five_ms, clock_.ApproximateNow()); 3405 EXPECT_EQ(default_timeout + five_ms, clock_.ApproximateNow());
3322 connection_.GetTimeoutAlarm()->Fire(); 3406 connection_.GetTimeoutAlarm()->Fire();
3323 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 3407 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
3324 EXPECT_FALSE(connection_.connected()); 3408 EXPECT_FALSE(connection_.connected());
3325 } 3409 }
(...skipping 1795 matching lines...) Expand 10 before | Expand all | Expand 10 after
5121 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); 5205 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr);
5122 EXPECT_EQ(1u, writer_->frame_count()); 5206 EXPECT_EQ(1u, writer_->frame_count());
5123 EXPECT_FALSE(writer_->connection_close_frames().empty()); 5207 EXPECT_FALSE(writer_->connection_close_frames().empty());
5124 // Ack frame is not bundled in connection close packet. 5208 // Ack frame is not bundled in connection close packet.
5125 EXPECT_TRUE(writer_->ack_frames().empty()); 5209 EXPECT_TRUE(writer_->ack_frames().empty());
5126 } 5210 }
5127 5211
5128 } // namespace 5212 } // namespace
5129 } // namespace test 5213 } // namespace test
5130 } // namespace net 5214 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/quic_connection.cc ('k') | net/quic/core/quic_flags.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698