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" |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 EXPECT_FALSE(IsConnectionIdInTimeWait(connection_id_)); | 461 EXPECT_FALSE(IsConnectionIdInTimeWait(connection_id_)); |
462 EXPECT_EQ(0u, time_wait_list_manager_.num_connections()); | 462 EXPECT_EQ(0u, time_wait_list_manager_.num_connections()); |
463 } | 463 } |
464 | 464 |
465 TEST_F(QuicTimeWaitListManagerTest, ConnectionIdsOrderedByTime) { | 465 TEST_F(QuicTimeWaitListManagerTest, ConnectionIdsOrderedByTime) { |
466 // Simple randomization: the values of connection_ids are swapped based on the | 466 // Simple randomization: the values of connection_ids are swapped based on the |
467 // current seconds on the clock. If the container is broken, the test will be | 467 // current seconds on the clock. If the container is broken, the test will be |
468 // 50% flaky. | 468 // 50% flaky. |
469 int odd_second = static_cast<int>(epoll_server_.ApproximateNowInUsec()) % 2; | 469 int odd_second = static_cast<int>(epoll_server_.ApproximateNowInUsec()) % 2; |
470 EXPECT_TRUE(odd_second == 0 || odd_second == 1); | 470 EXPECT_TRUE(odd_second == 0 || odd_second == 1); |
471 const QuicConnectionId kConnectionId1 = odd_second; | 471 const QuicConnectionId connection_id1 = odd_second; |
472 const QuicConnectionId kConnectionId2 = 1 - odd_second; | 472 const QuicConnectionId connection_id2 = 1 - odd_second; |
473 | 473 |
474 // 1 will hash lower than 2, but we add it later. They should come out in the | 474 // 1 will hash lower than 2, but we add it later. They should come out in the |
475 // add order, not hash order. | 475 // add order, not hash order. |
476 epoll_server_.set_now_in_usec(0); | 476 epoll_server_.set_now_in_usec(0); |
477 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(kConnectionId1)); | 477 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id1)); |
478 AddConnectionId(kConnectionId1); | 478 AddConnectionId(connection_id1); |
479 epoll_server_.set_now_in_usec(10); | 479 epoll_server_.set_now_in_usec(10); |
480 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(kConnectionId2)); | 480 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id2)); |
481 AddConnectionId(kConnectionId2); | 481 AddConnectionId(connection_id2); |
482 EXPECT_EQ(2u, time_wait_list_manager_.num_connections()); | 482 EXPECT_EQ(2u, time_wait_list_manager_.num_connections()); |
483 | 483 |
484 const QuicTime::Delta time_wait_period = | 484 const QuicTime::Delta time_wait_period = |
485 QuicTimeWaitListManagerPeer::time_wait_period(&time_wait_list_manager_); | 485 QuicTimeWaitListManagerPeer::time_wait_period(&time_wait_list_manager_); |
486 epoll_server_.set_now_in_usec(time_wait_period.ToMicroseconds() + 1); | 486 epoll_server_.set_now_in_usec(time_wait_period.ToMicroseconds() + 1); |
487 | 487 |
488 EXPECT_CALL(epoll_server_, RegisterAlarm(_, _)); | 488 EXPECT_CALL(epoll_server_, RegisterAlarm(_, _)); |
489 | 489 |
490 EXPECT_CALL(visitor_, OnConnectionRemovedFromTimeWaitList(kConnectionId1)); | 490 EXPECT_CALL(visitor_, OnConnectionRemovedFromTimeWaitList(connection_id1)); |
491 time_wait_list_manager_.CleanUpOldConnectionIds(); | 491 time_wait_list_manager_.CleanUpOldConnectionIds(); |
492 EXPECT_FALSE(IsConnectionIdInTimeWait(kConnectionId1)); | 492 EXPECT_FALSE(IsConnectionIdInTimeWait(connection_id1)); |
493 EXPECT_TRUE(IsConnectionIdInTimeWait(kConnectionId2)); | 493 EXPECT_TRUE(IsConnectionIdInTimeWait(connection_id2)); |
494 EXPECT_EQ(1u, time_wait_list_manager_.num_connections()); | 494 EXPECT_EQ(1u, time_wait_list_manager_.num_connections()); |
495 } | 495 } |
496 | 496 |
497 TEST_F(QuicTimeWaitListManagerTest, MaxConnectionsTest) { | 497 TEST_F(QuicTimeWaitListManagerTest, MaxConnectionsTest) { |
498 // Basically, shut off time-based eviction. | 498 // Basically, shut off time-based eviction. |
499 FLAGS_quic_time_wait_list_seconds = 10000000000; | 499 FLAGS_quic_time_wait_list_seconds = 10000000000; |
500 FLAGS_quic_time_wait_list_max_connections = 5; | 500 FLAGS_quic_time_wait_list_max_connections = 5; |
501 | 501 |
502 QuicConnectionId current_connection_id = 0; | 502 QuicConnectionId current_connection_id = 0; |
503 // Add exactly the maximum number of connections | 503 // Add exactly the maximum number of connections |
(...skipping 23 matching lines...) Expand all Loading... |
527 time_wait_list_manager_.num_connections()); | 527 time_wait_list_manager_.num_connections()); |
528 EXPECT_FALSE(IsConnectionIdInTimeWait(id_to_evict)); | 528 EXPECT_FALSE(IsConnectionIdInTimeWait(id_to_evict)); |
529 EXPECT_TRUE(IsConnectionIdInTimeWait(current_connection_id)); | 529 EXPECT_TRUE(IsConnectionIdInTimeWait(current_connection_id)); |
530 } | 530 } |
531 } | 531 } |
532 | 532 |
533 } // namespace | 533 } // namespace |
534 } // namespace test | 534 } // namespace test |
535 } // namespace tools | 535 } // namespace tools |
536 } // namespace net | 536 } // namespace net |
OLD | NEW |