OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/tools/quic/quic_time_wait_list_manager.h" | 5 #include "net/tools/quic/quic_time_wait_list_manager.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 | 8 |
9 #include "net/quic/crypto/crypto_protocol.h" | 9 #include "net/quic/crypto/crypto_protocol.h" |
10 #include "net/quic/crypto/null_encrypter.h" | 10 #include "net/quic/crypto/null_encrypter.h" |
11 #include "net/quic/crypto/quic_decrypter.h" | 11 #include "net/quic/crypto/quic_decrypter.h" |
12 #include "net/quic/crypto/quic_encrypter.h" | 12 #include "net/quic/crypto/quic_encrypter.h" |
13 #include "net/quic/quic_data_reader.h" | 13 #include "net/quic/quic_data_reader.h" |
| 14 #include "net/quic/quic_flags.h" |
14 #include "net/quic/quic_framer.h" | 15 #include "net/quic/quic_framer.h" |
15 #include "net/quic/quic_packet_writer.h" | 16 #include "net/quic/quic_packet_writer.h" |
16 #include "net/quic/quic_protocol.h" | 17 #include "net/quic/quic_protocol.h" |
17 #include "net/quic/quic_utils.h" | 18 #include "net/quic/quic_utils.h" |
18 #include "net/quic/test_tools/quic_test_utils.h" | 19 #include "net/quic/test_tools/quic_test_utils.h" |
19 #include "net/tools/quic/test_tools/mock_epoll_server.h" | 20 #include "net/tools/quic/test_tools/mock_epoll_server.h" |
20 #include "net/tools/quic/test_tools/quic_test_utils.h" | 21 #include "net/tools/quic/test_tools/quic_test_utils.h" |
21 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
23 | 24 |
24 using net::test::BuildUnsizedDataPacket; | 25 using net::test::BuildUnsizedDataPacket; |
25 using net::test::NoOpFramerVisitor; | 26 using net::test::NoOpFramerVisitor; |
26 using net::test::QuicVersionMax; | 27 using net::test::QuicVersionMax; |
27 using net::test::QuicVersionMin; | 28 using net::test::QuicVersionMin; |
| 29 using net::test::ValueRestore; |
28 using testing::Args; | 30 using testing::Args; |
29 using testing::Assign; | 31 using testing::Assign; |
30 using testing::DoAll; | 32 using testing::DoAll; |
31 using testing::Matcher; | 33 using testing::Matcher; |
32 using testing::MatcherInterface; | 34 using testing::MatcherInterface; |
33 using testing::NiceMock; | 35 using testing::NiceMock; |
34 using testing::Return; | 36 using testing::Return; |
35 using testing::ReturnPointee; | 37 using testing::ReturnPointee; |
36 using testing::SetArgPointee; | 38 using testing::SetArgPointee; |
37 using testing::StrictMock; | 39 using testing::StrictMock; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 QuicConnectionId connection_id, | 213 QuicConnectionId connection_id, |
212 QuicPacketSequenceNumber sequence_number) { | 214 QuicPacketSequenceNumber sequence_number) { |
213 return MakeMatcher(new ValidatePublicResetPacketPredicate(connection_id, | 215 return MakeMatcher(new ValidatePublicResetPacketPredicate(connection_id, |
214 sequence_number)); | 216 sequence_number)); |
215 } | 217 } |
216 | 218 |
217 TEST_F(QuicTimeWaitListManagerTest, CheckConnectionIdInTimeWait) { | 219 TEST_F(QuicTimeWaitListManagerTest, CheckConnectionIdInTimeWait) { |
218 EXPECT_FALSE(IsConnectionIdInTimeWait(connection_id_)); | 220 EXPECT_FALSE(IsConnectionIdInTimeWait(connection_id_)); |
219 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); | 221 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); |
220 AddConnectionId(connection_id_); | 222 AddConnectionId(connection_id_); |
| 223 EXPECT_EQ(1u, time_wait_list_manager_.num_connections()); |
221 EXPECT_TRUE(IsConnectionIdInTimeWait(connection_id_)); | 224 EXPECT_TRUE(IsConnectionIdInTimeWait(connection_id_)); |
222 } | 225 } |
223 | 226 |
224 TEST_F(QuicTimeWaitListManagerTest, SendConnectionClose) { | 227 TEST_F(QuicTimeWaitListManagerTest, SendConnectionClose) { |
225 size_t kConnectionCloseLength = 100; | 228 size_t kConnectionCloseLength = 100; |
226 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); | 229 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); |
227 AddConnectionId( | 230 AddConnectionId( |
228 connection_id_, | 231 connection_id_, |
229 QuicVersionMax(), | 232 QuicVersionMax(), |
230 new QuicEncryptedPacket( | 233 new QuicEncryptedPacket( |
(...skipping 17 matching lines...) Expand all Loading... |
248 .With(Args<0, 1>(PublicResetPacketEq(connection_id_, | 251 .With(Args<0, 1>(PublicResetPacketEq(connection_id_, |
249 kRandomSequenceNumber))) | 252 kRandomSequenceNumber))) |
250 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 0))); | 253 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 0))); |
251 | 254 |
252 ProcessPacket(connection_id_, kRandomSequenceNumber); | 255 ProcessPacket(connection_id_, kRandomSequenceNumber); |
253 } | 256 } |
254 | 257 |
255 TEST_F(QuicTimeWaitListManagerTest, SendPublicResetWithExponentialBackOff) { | 258 TEST_F(QuicTimeWaitListManagerTest, SendPublicResetWithExponentialBackOff) { |
256 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); | 259 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); |
257 AddConnectionId(connection_id_); | 260 AddConnectionId(connection_id_); |
| 261 EXPECT_EQ(1u, time_wait_list_manager_.num_connections()); |
258 for (int sequence_number = 1; sequence_number < 101; ++sequence_number) { | 262 for (int sequence_number = 1; sequence_number < 101; ++sequence_number) { |
259 if ((sequence_number & (sequence_number - 1)) == 0) { | 263 if ((sequence_number & (sequence_number - 1)) == 0) { |
260 EXPECT_CALL(writer_, WritePacket(_, _, _, _)) | 264 EXPECT_CALL(writer_, WritePacket(_, _, _, _)) |
261 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); | 265 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); |
262 } | 266 } |
263 ProcessPacket(connection_id_, sequence_number); | 267 ProcessPacket(connection_id_, sequence_number); |
264 // Send public reset with exponential back off. | 268 // Send public reset with exponential back off. |
265 if ((sequence_number & (sequence_number - 1)) == 0) { | 269 if ((sequence_number & (sequence_number - 1)) == 0) { |
266 EXPECT_TRUE(QuicTimeWaitListManagerPeer::ShouldSendResponse( | 270 EXPECT_TRUE(QuicTimeWaitListManagerPeer::ShouldSendResponse( |
267 &time_wait_list_manager_, sequence_number)); | 271 &time_wait_list_manager_, sequence_number)); |
268 } else { | 272 } else { |
269 EXPECT_FALSE(QuicTimeWaitListManagerPeer::ShouldSendResponse( | 273 EXPECT_FALSE(QuicTimeWaitListManagerPeer::ShouldSendResponse( |
270 &time_wait_list_manager_, sequence_number)); | 274 &time_wait_list_manager_, sequence_number)); |
271 } | 275 } |
272 } | 276 } |
273 } | 277 } |
274 | 278 |
275 TEST_F(QuicTimeWaitListManagerTest, CleanUpOldConnectionIds) { | 279 TEST_F(QuicTimeWaitListManagerTest, CleanUpOldConnectionIds) { |
276 const int kConnectionIdCount = 100; | 280 const size_t kConnectionIdCount = 100; |
277 const int kOldConnectionIdCount = 31; | 281 const size_t kOldConnectionIdCount = 31; |
278 | 282 |
279 // Add connection_ids such that their expiry time is kTimeWaitPeriod_. | 283 // Add connection_ids such that their expiry time is kTimeWaitPeriod_. |
280 epoll_server_.set_now_in_usec(0); | 284 epoll_server_.set_now_in_usec(0); |
281 for (int connection_id = 1; | 285 for (size_t connection_id = 1; connection_id <= kOldConnectionIdCount; |
282 connection_id <= kOldConnectionIdCount; | |
283 ++connection_id) { | 286 ++connection_id) { |
284 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id)); | 287 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id)); |
285 AddConnectionId(connection_id); | 288 AddConnectionId(connection_id); |
286 } | 289 } |
| 290 EXPECT_EQ(kOldConnectionIdCount, time_wait_list_manager_.num_connections()); |
287 | 291 |
288 // Add remaining connection_ids such that their add time is | 292 // Add remaining connection_ids such that their add time is |
289 // 2 * kTimeWaitPeriod. | 293 // 2 * kTimeWaitPeriod. |
290 const QuicTime::Delta time_wait_period = | 294 const QuicTime::Delta time_wait_period = |
291 QuicTimeWaitListManagerPeer::time_wait_period(&time_wait_list_manager_); | 295 QuicTimeWaitListManagerPeer::time_wait_period(&time_wait_list_manager_); |
292 epoll_server_.set_now_in_usec(time_wait_period.ToMicroseconds()); | 296 epoll_server_.set_now_in_usec(time_wait_period.ToMicroseconds()); |
293 for (int connection_id = kOldConnectionIdCount + 1; | 297 for (size_t connection_id = kOldConnectionIdCount + 1; |
294 connection_id <= kConnectionIdCount; | 298 connection_id <= kConnectionIdCount; ++connection_id) { |
295 ++connection_id) { | |
296 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id)); | 299 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id)); |
297 AddConnectionId(connection_id); | 300 AddConnectionId(connection_id); |
298 } | 301 } |
| 302 EXPECT_EQ(kConnectionIdCount, time_wait_list_manager_.num_connections()); |
299 | 303 |
300 QuicTime::Delta offset = QuicTime::Delta::FromMicroseconds(39); | 304 QuicTime::Delta offset = QuicTime::Delta::FromMicroseconds(39); |
301 // Now set the current time as time_wait_period + offset usecs. | 305 // Now set the current time as time_wait_period + offset usecs. |
302 epoll_server_.set_now_in_usec(time_wait_period.Add(offset).ToMicroseconds()); | 306 epoll_server_.set_now_in_usec(time_wait_period.Add(offset).ToMicroseconds()); |
303 // After all the old connection_ids are cleaned up, check the next alarm | 307 // After all the old connection_ids are cleaned up, check the next alarm |
304 // interval. | 308 // interval. |
305 int64 next_alarm_time = epoll_server_.ApproximateNowInUsec() + | 309 int64 next_alarm_time = epoll_server_.ApproximateNowInUsec() + |
306 time_wait_period.Subtract(offset).ToMicroseconds(); | 310 time_wait_period.Subtract(offset).ToMicroseconds(); |
307 EXPECT_CALL(epoll_server_, RegisterAlarm(next_alarm_time, _)); | 311 EXPECT_CALL(epoll_server_, RegisterAlarm(next_alarm_time, _)); |
308 | 312 |
309 for (int connection_id = 1; connection_id <= kConnectionIdCount; | 313 for (size_t connection_id = 1; connection_id <= kConnectionIdCount; |
310 ++connection_id) { | 314 ++connection_id) { |
311 if (connection_id <= kOldConnectionIdCount) { | 315 if (connection_id <= kOldConnectionIdCount) { |
312 EXPECT_CALL(visitor_, OnConnectionRemovedFromTimeWaitList(connection_id)); | 316 EXPECT_CALL(visitor_, OnConnectionRemovedFromTimeWaitList(connection_id)); |
313 } | 317 } |
314 } | 318 } |
315 time_wait_list_manager_.CleanUpOldConnectionIds(); | 319 time_wait_list_manager_.CleanUpOldConnectionIds(); |
316 for (int connection_id = 1; | 320 for (size_t connection_id = 1; connection_id <= kConnectionIdCount; |
317 connection_id <= kConnectionIdCount; | |
318 ++connection_id) { | 321 ++connection_id) { |
319 EXPECT_EQ(connection_id > kOldConnectionIdCount, | 322 EXPECT_EQ(connection_id > kOldConnectionIdCount, |
320 IsConnectionIdInTimeWait(connection_id)) | 323 IsConnectionIdInTimeWait(connection_id)) |
321 << "kOldConnectionIdCount: " << kOldConnectionIdCount | 324 << "kOldConnectionIdCount: " << kOldConnectionIdCount |
322 << " connection_id: " << connection_id; | 325 << " connection_id: " << connection_id; |
323 } | 326 } |
| 327 EXPECT_EQ(kConnectionIdCount - kOldConnectionIdCount, |
| 328 time_wait_list_manager_.num_connections()); |
324 } | 329 } |
325 | 330 |
326 TEST_F(QuicTimeWaitListManagerTest, SendQueuedPackets) { | 331 TEST_F(QuicTimeWaitListManagerTest, SendQueuedPackets) { |
327 QuicConnectionId connection_id = 1; | 332 QuicConnectionId connection_id = 1; |
328 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id)); | 333 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id)); |
329 AddConnectionId(connection_id); | 334 AddConnectionId(connection_id); |
330 QuicPacketSequenceNumber sequence_number = 234; | 335 QuicPacketSequenceNumber sequence_number = 234; |
331 scoped_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket( | 336 scoped_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket( |
332 ENCRYPTION_NONE, connection_id, sequence_number)); | 337 ENCRYPTION_NONE, connection_id, sequence_number)); |
333 // Let first write through. | 338 // Let first write through. |
(...skipping 25 matching lines...) Expand all Loading... |
359 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(other_connection_id)); | 364 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(other_connection_id)); |
360 AddConnectionId(other_connection_id); | 365 AddConnectionId(other_connection_id); |
361 QuicPacketSequenceNumber other_sequence_number = 23423; | 366 QuicPacketSequenceNumber other_sequence_number = 23423; |
362 scoped_ptr<QuicEncryptedPacket> other_packet( | 367 scoped_ptr<QuicEncryptedPacket> other_packet( |
363 ConstructEncryptedPacket( | 368 ConstructEncryptedPacket( |
364 ENCRYPTION_NONE, other_connection_id, other_sequence_number)); | 369 ENCRYPTION_NONE, other_connection_id, other_sequence_number)); |
365 EXPECT_CALL(writer_, WritePacket(_, _, _, _)) | 370 EXPECT_CALL(writer_, WritePacket(_, _, _, _)) |
366 .Times(0); | 371 .Times(0); |
367 EXPECT_CALL(visitor_, OnWriteBlocked(&time_wait_list_manager_)); | 372 EXPECT_CALL(visitor_, OnWriteBlocked(&time_wait_list_manager_)); |
368 ProcessPacket(other_connection_id, other_sequence_number); | 373 ProcessPacket(other_connection_id, other_sequence_number); |
| 374 EXPECT_EQ(2u, time_wait_list_manager_.num_connections()); |
369 | 375 |
370 // Now expect all the write blocked public reset packets to be sent again. | 376 // Now expect all the write blocked public reset packets to be sent again. |
371 writer_is_blocked_ = false; | 377 writer_is_blocked_ = false; |
372 EXPECT_CALL(writer_, WritePacket(_, _, | 378 EXPECT_CALL(writer_, WritePacket(_, _, |
373 server_address_.address(), | 379 server_address_.address(), |
374 client_address_)) | 380 client_address_)) |
375 .With(Args<0, 1>(PublicResetPacketEq(connection_id, | 381 .With(Args<0, 1>(PublicResetPacketEq(connection_id, |
376 sequence_number))) | 382 sequence_number))) |
377 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, packet->length()))); | 383 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, packet->length()))); |
378 EXPECT_CALL(writer_, WritePacket(_, _, | 384 EXPECT_CALL(writer_, WritePacket(_, _, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); | 420 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); |
415 AddConnectionId(connection_id_); | 421 AddConnectionId(connection_id_); |
416 EXPECT_TRUE(IsConnectionIdInTimeWait(connection_id_)); | 422 EXPECT_TRUE(IsConnectionIdInTimeWait(connection_id_)); |
417 size_t kConnectionCloseLength = 100; | 423 size_t kConnectionCloseLength = 100; |
418 AddConnectionId( | 424 AddConnectionId( |
419 connection_id_, | 425 connection_id_, |
420 QuicVersionMax(), | 426 QuicVersionMax(), |
421 new QuicEncryptedPacket( | 427 new QuicEncryptedPacket( |
422 new char[kConnectionCloseLength], kConnectionCloseLength, true)); | 428 new char[kConnectionCloseLength], kConnectionCloseLength, true)); |
423 EXPECT_TRUE(IsConnectionIdInTimeWait(connection_id_)); | 429 EXPECT_TRUE(IsConnectionIdInTimeWait(connection_id_)); |
| 430 EXPECT_EQ(1u, time_wait_list_manager_.num_connections()); |
424 | 431 |
425 EXPECT_CALL(writer_, WritePacket(_, | 432 EXPECT_CALL(writer_, WritePacket(_, |
426 kConnectionCloseLength, | 433 kConnectionCloseLength, |
427 server_address_.address(), | 434 server_address_.address(), |
428 client_address_)) | 435 client_address_)) |
429 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); | 436 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); |
430 | 437 |
431 const int kRandomSequenceNumber = 1; | 438 const int kRandomSequenceNumber = 1; |
432 ProcessPacket(connection_id_, kRandomSequenceNumber); | 439 ProcessPacket(connection_id_, kRandomSequenceNumber); |
433 | 440 |
434 const QuicTime::Delta time_wait_period = | 441 const QuicTime::Delta time_wait_period = |
435 QuicTimeWaitListManagerPeer::time_wait_period(&time_wait_list_manager_); | 442 QuicTimeWaitListManagerPeer::time_wait_period(&time_wait_list_manager_); |
436 | 443 |
437 QuicTime::Delta offset = QuicTime::Delta::FromMicroseconds(39); | 444 QuicTime::Delta offset = QuicTime::Delta::FromMicroseconds(39); |
438 // Now set the current time as time_wait_period + offset usecs. | 445 // Now set the current time as time_wait_period + offset usecs. |
439 epoll_server_.set_now_in_usec(time_wait_period.Add(offset).ToMicroseconds()); | 446 epoll_server_.set_now_in_usec(time_wait_period.Add(offset).ToMicroseconds()); |
440 // After the connection_ids are cleaned up, check the next alarm interval. | 447 // After the connection_ids are cleaned up, check the next alarm interval. |
441 int64 next_alarm_time = epoll_server_.ApproximateNowInUsec() + | 448 int64 next_alarm_time = epoll_server_.ApproximateNowInUsec() + |
442 time_wait_period.ToMicroseconds(); | 449 time_wait_period.ToMicroseconds(); |
443 | 450 |
444 EXPECT_CALL(epoll_server_, RegisterAlarm(next_alarm_time, _)); | 451 EXPECT_CALL(epoll_server_, RegisterAlarm(next_alarm_time, _)); |
445 EXPECT_CALL(visitor_, OnConnectionRemovedFromTimeWaitList(connection_id_)); | 452 EXPECT_CALL(visitor_, OnConnectionRemovedFromTimeWaitList(connection_id_)); |
446 time_wait_list_manager_.CleanUpOldConnectionIds(); | 453 time_wait_list_manager_.CleanUpOldConnectionIds(); |
447 EXPECT_FALSE(IsConnectionIdInTimeWait(connection_id_)); | 454 EXPECT_FALSE(IsConnectionIdInTimeWait(connection_id_)); |
| 455 EXPECT_EQ(0u, time_wait_list_manager_.num_connections()); |
448 } | 456 } |
449 | 457 |
450 TEST_F(QuicTimeWaitListManagerTest, ConnectionIdsOrderedByTime) { | 458 TEST_F(QuicTimeWaitListManagerTest, ConnectionIdsOrderedByTime) { |
451 // Simple randomization: the values of connection_ids are swapped based on the | 459 // Simple randomization: the values of connection_ids are swapped based on the |
452 // current seconds on the clock. If the container is broken, the test will be | 460 // current seconds on the clock. If the container is broken, the test will be |
453 // 50% flaky. | 461 // 50% flaky. |
454 int odd_second = static_cast<int>(epoll_server_.ApproximateNowInUsec()) % 2; | 462 int odd_second = static_cast<int>(epoll_server_.ApproximateNowInUsec()) % 2; |
455 EXPECT_TRUE(odd_second == 0 || odd_second == 1); | 463 EXPECT_TRUE(odd_second == 0 || odd_second == 1); |
456 const QuicConnectionId kConnectionId1 = odd_second; | 464 const QuicConnectionId kConnectionId1 = odd_second; |
457 const QuicConnectionId kConnectionId2 = 1 - odd_second; | 465 const QuicConnectionId kConnectionId2 = 1 - odd_second; |
458 | 466 |
459 // 1 will hash lower than 2, but we add it later. They should come out in the | 467 // 1 will hash lower than 2, but we add it later. They should come out in the |
460 // add order, not hash order. | 468 // add order, not hash order. |
461 epoll_server_.set_now_in_usec(0); | 469 epoll_server_.set_now_in_usec(0); |
462 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(kConnectionId1)); | 470 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(kConnectionId1)); |
463 AddConnectionId(kConnectionId1); | 471 AddConnectionId(kConnectionId1); |
464 epoll_server_.set_now_in_usec(10); | 472 epoll_server_.set_now_in_usec(10); |
465 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(kConnectionId2)); | 473 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(kConnectionId2)); |
466 AddConnectionId(kConnectionId2); | 474 AddConnectionId(kConnectionId2); |
| 475 EXPECT_EQ(2u, time_wait_list_manager_.num_connections()); |
467 | 476 |
468 const QuicTime::Delta time_wait_period = | 477 const QuicTime::Delta time_wait_period = |
469 QuicTimeWaitListManagerPeer::time_wait_period(&time_wait_list_manager_); | 478 QuicTimeWaitListManagerPeer::time_wait_period(&time_wait_list_manager_); |
470 epoll_server_.set_now_in_usec(time_wait_period.ToMicroseconds() + 1); | 479 epoll_server_.set_now_in_usec(time_wait_period.ToMicroseconds() + 1); |
471 | 480 |
472 EXPECT_CALL(epoll_server_, RegisterAlarm(_, _)); | 481 EXPECT_CALL(epoll_server_, RegisterAlarm(_, _)); |
473 | 482 |
474 EXPECT_CALL(visitor_, OnConnectionRemovedFromTimeWaitList(kConnectionId1)); | 483 EXPECT_CALL(visitor_, OnConnectionRemovedFromTimeWaitList(kConnectionId1)); |
475 time_wait_list_manager_.CleanUpOldConnectionIds(); | 484 time_wait_list_manager_.CleanUpOldConnectionIds(); |
476 EXPECT_FALSE(IsConnectionIdInTimeWait(kConnectionId1)); | 485 EXPECT_FALSE(IsConnectionIdInTimeWait(kConnectionId1)); |
477 EXPECT_TRUE(IsConnectionIdInTimeWait(kConnectionId2)); | 486 EXPECT_TRUE(IsConnectionIdInTimeWait(kConnectionId2)); |
| 487 EXPECT_EQ(1u, time_wait_list_manager_.num_connections()); |
478 } | 488 } |
| 489 |
| 490 TEST_F(QuicTimeWaitListManagerTest, MaxConnectionsTest) { |
| 491 ValueRestore<bool> old_flag(&FLAGS_quic_limit_time_wait_list_size, true); |
| 492 // Basically, shut off time-based eviction. |
| 493 FLAGS_quic_time_wait_list_seconds = 10000000000; |
| 494 FLAGS_quic_time_wait_list_max_connections = 5; |
| 495 |
| 496 QuicConnectionId current_connection_id = 0; |
| 497 // Add exactly the maximum number of connections |
| 498 for (int64 i = 0; i < FLAGS_quic_time_wait_list_max_connections; ++i) { |
| 499 ++current_connection_id; |
| 500 EXPECT_FALSE(IsConnectionIdInTimeWait(current_connection_id)); |
| 501 EXPECT_CALL(visitor_, |
| 502 OnConnectionAddedToTimeWaitList(current_connection_id)); |
| 503 AddConnectionId(current_connection_id); |
| 504 EXPECT_EQ(current_connection_id, time_wait_list_manager_.num_connections()); |
| 505 EXPECT_TRUE(IsConnectionIdInTimeWait(current_connection_id)); |
| 506 } |
| 507 |
| 508 // Now keep adding. Since we're already at the max, every new connection-id |
| 509 // will evict the oldest one. |
| 510 for (int64 i = 0; i < FLAGS_quic_time_wait_list_max_connections; ++i) { |
| 511 ++current_connection_id; |
| 512 const QuicConnectionId id_to_evict = |
| 513 current_connection_id - FLAGS_quic_time_wait_list_max_connections; |
| 514 EXPECT_TRUE(IsConnectionIdInTimeWait(id_to_evict)); |
| 515 EXPECT_FALSE(IsConnectionIdInTimeWait(current_connection_id)); |
| 516 EXPECT_CALL(visitor_, OnConnectionRemovedFromTimeWaitList(id_to_evict)); |
| 517 EXPECT_CALL(visitor_, |
| 518 OnConnectionAddedToTimeWaitList(current_connection_id)); |
| 519 AddConnectionId(current_connection_id); |
| 520 EXPECT_EQ(static_cast<size_t>(FLAGS_quic_time_wait_list_max_connections), |
| 521 time_wait_list_manager_.num_connections()); |
| 522 EXPECT_FALSE(IsConnectionIdInTimeWait(id_to_evict)); |
| 523 EXPECT_TRUE(IsConnectionIdInTimeWait(current_connection_id)); |
| 524 } |
| 525 } |
| 526 |
479 } // namespace | 527 } // namespace |
480 } // namespace test | 528 } // namespace test |
481 } // namespace tools | 529 } // namespace tools |
482 } // namespace net | 530 } // namespace net |
OLD | NEW |