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

Side by Side Diff: net/tools/quic/quic_time_wait_list_manager_test.cc

Issue 1535363003: Switch to standard integer types in net/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: stddef Created 5 years 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/tools/quic/quic_time_wait_list_manager.cc ('k') | net/tools/quic/spdy_balsa_utils.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 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 QuicConnectionId connection_id) { 82 QuicConnectionId connection_id) {
83 return manager->GetQuicVersionFromConnectionId(connection_id); 83 return manager->GetQuicVersionFromConnectionId(connection_id);
84 } 84 }
85 }; 85 };
86 86
87 namespace { 87 namespace {
88 88
89 class MockFakeTimeEpollServer : public FakeTimeEpollServer { 89 class MockFakeTimeEpollServer : public FakeTimeEpollServer {
90 public: 90 public:
91 MOCK_METHOD2(RegisterAlarm, 91 MOCK_METHOD2(RegisterAlarm,
92 void(int64 timeout_in_us, EpollAlarmCallbackInterface* alarm)); 92 void(int64_t timeout_in_us, EpollAlarmCallbackInterface* alarm));
93 }; 93 };
94 94
95 class QuicTimeWaitListManagerTest : public ::testing::Test { 95 class QuicTimeWaitListManagerTest : public ::testing::Test {
96 protected: 96 protected:
97 QuicTimeWaitListManagerTest() 97 QuicTimeWaitListManagerTest()
98 : helper_(&epoll_server_), 98 : helper_(&epoll_server_),
99 time_wait_list_manager_(&writer_, &visitor_, &helper_), 99 time_wait_list_manager_(&writer_, &visitor_, &helper_),
100 connection_id_(45), 100 connection_id_(45),
101 client_address_(net::test::TestPeerIPAddress(), kTestPort), 101 client_address_(net::test::TestPeerIPAddress(), kTestPort),
102 writer_is_blocked_(false) {} 102 writer_is_blocked_(false) {}
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id)); 324 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id));
325 AddConnectionId(connection_id); 325 AddConnectionId(connection_id);
326 } 326 }
327 EXPECT_EQ(kConnectionIdCount, time_wait_list_manager_.num_connections()); 327 EXPECT_EQ(kConnectionIdCount, time_wait_list_manager_.num_connections());
328 328
329 QuicTime::Delta offset = QuicTime::Delta::FromMicroseconds(39); 329 QuicTime::Delta offset = QuicTime::Delta::FromMicroseconds(39);
330 // Now set the current time as time_wait_period + offset usecs. 330 // Now set the current time as time_wait_period + offset usecs.
331 epoll_server_.set_now_in_usec(time_wait_period.Add(offset).ToMicroseconds()); 331 epoll_server_.set_now_in_usec(time_wait_period.Add(offset).ToMicroseconds());
332 // After all the old connection_ids are cleaned up, check the next alarm 332 // After all the old connection_ids are cleaned up, check the next alarm
333 // interval. 333 // interval.
334 int64 next_alarm_time = epoll_server_.ApproximateNowInUsec() + 334 int64_t next_alarm_time = epoll_server_.ApproximateNowInUsec() +
335 time_wait_period.Subtract(offset).ToMicroseconds(); 335 time_wait_period.Subtract(offset).ToMicroseconds();
336 EXPECT_CALL(epoll_server_, RegisterAlarm(next_alarm_time, _)); 336 EXPECT_CALL(epoll_server_, RegisterAlarm(next_alarm_time, _));
337 337
338 for (size_t connection_id = 1; connection_id <= kConnectionIdCount; 338 for (size_t connection_id = 1; connection_id <= kConnectionIdCount;
339 ++connection_id) { 339 ++connection_id) {
340 if (connection_id <= kOldConnectionIdCount) { 340 if (connection_id <= kOldConnectionIdCount) {
341 EXPECT_CALL(visitor_, OnConnectionRemovedFromTimeWaitList(connection_id)); 341 EXPECT_CALL(visitor_, OnConnectionRemovedFromTimeWaitList(connection_id));
342 } 342 }
343 } 343 }
344 time_wait_list_manager_.CleanUpOldConnectionIds(); 344 time_wait_list_manager_.CleanUpOldConnectionIds();
345 for (size_t connection_id = 1; connection_id <= kConnectionIdCount; 345 for (size_t connection_id = 1; connection_id <= kConnectionIdCount;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 const int kRandomSequenceNumber = 1; 454 const int kRandomSequenceNumber = 1;
455 ProcessPacket(connection_id_, kRandomSequenceNumber); 455 ProcessPacket(connection_id_, kRandomSequenceNumber);
456 456
457 const QuicTime::Delta time_wait_period = 457 const QuicTime::Delta time_wait_period =
458 QuicTimeWaitListManagerPeer::time_wait_period(&time_wait_list_manager_); 458 QuicTimeWaitListManagerPeer::time_wait_period(&time_wait_list_manager_);
459 459
460 QuicTime::Delta offset = QuicTime::Delta::FromMicroseconds(39); 460 QuicTime::Delta offset = QuicTime::Delta::FromMicroseconds(39);
461 // Now set the current time as time_wait_period + offset usecs. 461 // Now set the current time as time_wait_period + offset usecs.
462 epoll_server_.set_now_in_usec(time_wait_period.Add(offset).ToMicroseconds()); 462 epoll_server_.set_now_in_usec(time_wait_period.Add(offset).ToMicroseconds());
463 // After the connection_ids are cleaned up, check the next alarm interval. 463 // After the connection_ids are cleaned up, check the next alarm interval.
464 int64 next_alarm_time = 464 int64_t next_alarm_time =
465 epoll_server_.ApproximateNowInUsec() + time_wait_period.ToMicroseconds(); 465 epoll_server_.ApproximateNowInUsec() + time_wait_period.ToMicroseconds();
466 466
467 EXPECT_CALL(epoll_server_, RegisterAlarm(next_alarm_time, _)); 467 EXPECT_CALL(epoll_server_, RegisterAlarm(next_alarm_time, _));
468 EXPECT_CALL(visitor_, OnConnectionRemovedFromTimeWaitList(connection_id_)); 468 EXPECT_CALL(visitor_, OnConnectionRemovedFromTimeWaitList(connection_id_));
469 time_wait_list_manager_.CleanUpOldConnectionIds(); 469 time_wait_list_manager_.CleanUpOldConnectionIds();
470 EXPECT_FALSE(IsConnectionIdInTimeWait(connection_id_)); 470 EXPECT_FALSE(IsConnectionIdInTimeWait(connection_id_));
471 EXPECT_EQ(0u, time_wait_list_manager_.num_connections()); 471 EXPECT_EQ(0u, time_wait_list_manager_.num_connections());
472 } 472 }
473 473
474 TEST_F(QuicTimeWaitListManagerTest, ConnectionIdsOrderedByTime) { 474 TEST_F(QuicTimeWaitListManagerTest, ConnectionIdsOrderedByTime) {
(...skipping 28 matching lines...) Expand all
503 EXPECT_EQ(1u, time_wait_list_manager_.num_connections()); 503 EXPECT_EQ(1u, time_wait_list_manager_.num_connections());
504 } 504 }
505 505
506 TEST_F(QuicTimeWaitListManagerTest, MaxConnectionsTest) { 506 TEST_F(QuicTimeWaitListManagerTest, MaxConnectionsTest) {
507 // Basically, shut off time-based eviction. 507 // Basically, shut off time-based eviction.
508 FLAGS_quic_time_wait_list_seconds = 10000000000; 508 FLAGS_quic_time_wait_list_seconds = 10000000000;
509 FLAGS_quic_time_wait_list_max_connections = 5; 509 FLAGS_quic_time_wait_list_max_connections = 5;
510 510
511 QuicConnectionId current_connection_id = 0; 511 QuicConnectionId current_connection_id = 0;
512 // Add exactly the maximum number of connections 512 // Add exactly the maximum number of connections
513 for (int64 i = 0; i < FLAGS_quic_time_wait_list_max_connections; ++i) { 513 for (int64_t i = 0; i < FLAGS_quic_time_wait_list_max_connections; ++i) {
514 ++current_connection_id; 514 ++current_connection_id;
515 EXPECT_FALSE(IsConnectionIdInTimeWait(current_connection_id)); 515 EXPECT_FALSE(IsConnectionIdInTimeWait(current_connection_id));
516 EXPECT_CALL(visitor_, 516 EXPECT_CALL(visitor_,
517 OnConnectionAddedToTimeWaitList(current_connection_id)); 517 OnConnectionAddedToTimeWaitList(current_connection_id));
518 AddConnectionId(current_connection_id); 518 AddConnectionId(current_connection_id);
519 EXPECT_EQ(current_connection_id, time_wait_list_manager_.num_connections()); 519 EXPECT_EQ(current_connection_id, time_wait_list_manager_.num_connections());
520 EXPECT_TRUE(IsConnectionIdInTimeWait(current_connection_id)); 520 EXPECT_TRUE(IsConnectionIdInTimeWait(current_connection_id));
521 } 521 }
522 522
523 // Now keep adding. Since we're already at the max, every new connection-id 523 // Now keep adding. Since we're already at the max, every new connection-id
524 // will evict the oldest one. 524 // will evict the oldest one.
525 for (int64 i = 0; i < FLAGS_quic_time_wait_list_max_connections; ++i) { 525 for (int64_t i = 0; i < FLAGS_quic_time_wait_list_max_connections; ++i) {
526 ++current_connection_id; 526 ++current_connection_id;
527 const QuicConnectionId id_to_evict = 527 const QuicConnectionId id_to_evict =
528 current_connection_id - FLAGS_quic_time_wait_list_max_connections; 528 current_connection_id - FLAGS_quic_time_wait_list_max_connections;
529 EXPECT_TRUE(IsConnectionIdInTimeWait(id_to_evict)); 529 EXPECT_TRUE(IsConnectionIdInTimeWait(id_to_evict));
530 EXPECT_FALSE(IsConnectionIdInTimeWait(current_connection_id)); 530 EXPECT_FALSE(IsConnectionIdInTimeWait(current_connection_id));
531 EXPECT_CALL(visitor_, OnConnectionRemovedFromTimeWaitList(id_to_evict)); 531 EXPECT_CALL(visitor_, OnConnectionRemovedFromTimeWaitList(id_to_evict));
532 EXPECT_CALL(visitor_, 532 EXPECT_CALL(visitor_,
533 OnConnectionAddedToTimeWaitList(current_connection_id)); 533 OnConnectionAddedToTimeWaitList(current_connection_id));
534 AddConnectionId(current_connection_id); 534 AddConnectionId(current_connection_id);
535 EXPECT_EQ(static_cast<size_t>(FLAGS_quic_time_wait_list_max_connections), 535 EXPECT_EQ(static_cast<size_t>(FLAGS_quic_time_wait_list_max_connections),
536 time_wait_list_manager_.num_connections()); 536 time_wait_list_manager_.num_connections());
537 EXPECT_FALSE(IsConnectionIdInTimeWait(id_to_evict)); 537 EXPECT_FALSE(IsConnectionIdInTimeWait(id_to_evict));
538 EXPECT_TRUE(IsConnectionIdInTimeWait(current_connection_id)); 538 EXPECT_TRUE(IsConnectionIdInTimeWait(current_connection_id));
539 } 539 }
540 } 540 }
541 541
542 } // namespace 542 } // namespace
543 } // namespace test 543 } // namespace test
544 } // namespace tools 544 } // namespace tools
545 } // namespace net 545 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_time_wait_list_manager.cc ('k') | net/tools/quic/spdy_balsa_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698