| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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_client.h" | 5 #include "net/tools/quic/quic_client.h" |
| 6 | 6 |
| 7 #include <dirent.h> | 7 #include <dirent.h> |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 | 9 |
| 10 #include <memory> |
| 11 |
| 10 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 11 #include "net/quic/test_tools/crypto_test_utils.h" | 13 #include "net/quic/test_tools/crypto_test_utils.h" |
| 12 #include "net/quic/test_tools/quic_test_utils.h" | 14 #include "net/quic/test_tools/quic_test_utils.h" |
| 13 #include "net/tools/epoll_server/epoll_server.h" | 15 #include "net/tools/epoll_server/epoll_server.h" |
| 14 #include "net/tools/quic/test_tools/quic_client_peer.h" | 16 #include "net/tools/quic/test_tools/quic_client_peer.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 18 |
| 17 using net::EpollServer; | 19 using net::EpollServer; |
| 18 using net::test::CryptoTestUtils; | 20 using net::test::CryptoTestUtils; |
| 19 | 21 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 // exhaustion in long running processes which repeatedly create clients. | 60 // exhaustion in long running processes which repeatedly create clients. |
| 59 | 61 |
| 60 // Record initial number of FDs, after creation of EpollServer. | 62 // Record initial number of FDs, after creation of EpollServer. |
| 61 EpollServer eps; | 63 EpollServer eps; |
| 62 int number_of_open_fds = NumOpenFDs(); | 64 int number_of_open_fds = NumOpenFDs(); |
| 63 | 65 |
| 64 // Create a number of clients, initialize them, and verify this has resulted | 66 // Create a number of clients, initialize them, and verify this has resulted |
| 65 // in additional FDs being opened. | 67 // in additional FDs being opened. |
| 66 const int kNumClients = 50; | 68 const int kNumClients = 50; |
| 67 for (int i = 0; i < kNumClients; ++i) { | 69 for (int i = 0; i < kNumClients; ++i) { |
| 68 scoped_ptr<QuicClient> client( | 70 std::unique_ptr<QuicClient> client( |
| 69 CreateAndInitializeQuicClient(&eps, net::test::kTestPort + i)); | 71 CreateAndInitializeQuicClient(&eps, net::test::kTestPort + i)); |
| 70 | 72 |
| 71 // Initializing the client will create a new FD. | 73 // Initializing the client will create a new FD. |
| 72 EXPECT_LT(number_of_open_fds, NumOpenFDs()); | 74 EXPECT_LT(number_of_open_fds, NumOpenFDs()); |
| 73 } | 75 } |
| 74 | 76 |
| 75 // The FDs created by the QuicClients should now be closed. | 77 // The FDs created by the QuicClients should now be closed. |
| 76 EXPECT_EQ(number_of_open_fds, NumOpenFDs()); | 78 EXPECT_EQ(number_of_open_fds, NumOpenFDs()); |
| 77 } | 79 } |
| 78 | 80 |
| 79 TEST(QuicClientTest, CreateAndCleanUpUDPSockets) { | 81 TEST(QuicClientTest, CreateAndCleanUpUDPSockets) { |
| 80 // Create a ProofVerifier before counting the number of open FDs to work | 82 // Create a ProofVerifier before counting the number of open FDs to work |
| 81 // around some ASAN weirdness. | 83 // around some ASAN weirdness. |
| 82 delete CryptoTestUtils::ProofVerifierForTesting(); | 84 delete CryptoTestUtils::ProofVerifierForTesting(); |
| 83 | 85 |
| 84 EpollServer eps; | 86 EpollServer eps; |
| 85 int number_of_open_fds = NumOpenFDs(); | 87 int number_of_open_fds = NumOpenFDs(); |
| 86 | 88 |
| 87 scoped_ptr<QuicClient> client( | 89 std::unique_ptr<QuicClient> client( |
| 88 CreateAndInitializeQuicClient(&eps, net::test::kTestPort)); | 90 CreateAndInitializeQuicClient(&eps, net::test::kTestPort)); |
| 89 EXPECT_EQ(number_of_open_fds + 1, NumOpenFDs()); | 91 EXPECT_EQ(number_of_open_fds + 1, NumOpenFDs()); |
| 90 // Create more UDP sockets. | 92 // Create more UDP sockets. |
| 91 EXPECT_TRUE(QuicClientPeer::CreateUDPSocketAndBind(client.get())); | 93 EXPECT_TRUE(QuicClientPeer::CreateUDPSocketAndBind(client.get())); |
| 92 EXPECT_EQ(number_of_open_fds + 2, NumOpenFDs()); | 94 EXPECT_EQ(number_of_open_fds + 2, NumOpenFDs()); |
| 93 EXPECT_TRUE(QuicClientPeer::CreateUDPSocketAndBind(client.get())); | 95 EXPECT_TRUE(QuicClientPeer::CreateUDPSocketAndBind(client.get())); |
| 94 EXPECT_EQ(number_of_open_fds + 3, NumOpenFDs()); | 96 EXPECT_EQ(number_of_open_fds + 3, NumOpenFDs()); |
| 95 | 97 |
| 96 // Clean up UDP sockets. | 98 // Clean up UDP sockets. |
| 97 QuicClientPeer::CleanUpUDPSocket(client.get(), client->GetLatestFD()); | 99 QuicClientPeer::CleanUpUDPSocket(client.get(), client->GetLatestFD()); |
| 98 EXPECT_EQ(number_of_open_fds + 2, NumOpenFDs()); | 100 EXPECT_EQ(number_of_open_fds + 2, NumOpenFDs()); |
| 99 QuicClientPeer::CleanUpUDPSocket(client.get(), client->GetLatestFD()); | 101 QuicClientPeer::CleanUpUDPSocket(client.get(), client->GetLatestFD()); |
| 100 EXPECT_EQ(number_of_open_fds + 1, NumOpenFDs()); | 102 EXPECT_EQ(number_of_open_fds + 1, NumOpenFDs()); |
| 101 } | 103 } |
| 102 | 104 |
| 103 } // namespace | 105 } // namespace |
| 104 } // namespace test | 106 } // namespace test |
| 105 } // namespace net | 107 } // namespace net |
| OLD | NEW |