| 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 "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "net/quic/test_tools/crypto_test_utils.h" |
| 12 #include "net/quic/test_tools/quic_test_utils.h" | 13 #include "net/quic/test_tools/quic_test_utils.h" |
| 13 #include "net/tools/epoll_server/epoll_server.h" | 14 #include "net/tools/epoll_server/epoll_server.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 16 |
| 16 using net::EpollServer; | 17 using net::EpollServer; |
| 18 using net::test::CryptoTestUtils; |
| 17 | 19 |
| 18 namespace net { | 20 namespace net { |
| 19 namespace tools { | 21 namespace tools { |
| 20 namespace test { | 22 namespace test { |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| 23 int NumOpenFDs() { | 25 int NumOpenFDs() { |
| 24 int number_of_open_fds = 0; | 26 int number_of_open_fds = 0; |
| 25 char buf[256]; | 27 char buf[256]; |
| 26 struct dirent* dp; | 28 struct dirent* dp; |
| 27 | 29 |
| 28 base::snprintf(buf, arraysize(buf), "/proc/%i/fd/", getpid()); | 30 base::snprintf(buf, arraysize(buf), "/proc/%i/fd/", getpid()); |
| 29 DIR* dir = opendir(buf); | 31 DIR* dir = opendir(buf); |
| 30 while ((dp = readdir(dir)) != NULL) | 32 while ((dp = readdir(dir)) != NULL) |
| 31 number_of_open_fds++; | 33 number_of_open_fds++; |
| 32 closedir(dir); | 34 closedir(dir); |
| 33 | 35 |
| 34 return number_of_open_fds; | 36 return number_of_open_fds; |
| 35 } | 37 } |
| 36 | 38 |
| 37 // Creates a new QuicClient and Initializes it. Caller is responsible for | 39 // Creates a new QuicClient and Initializes it. Caller is responsible for |
| 38 // deletion. | 40 // deletion. |
| 39 QuicClient* CreateAndInitializeQuicClient(EpollServer* eps, uint16 port) { | 41 QuicClient* CreateAndInitializeQuicClient(EpollServer* eps, uint16 port) { |
| 40 IPEndPoint server_address(IPEndPoint(net::test::Loopback4(), port)); | 42 IPEndPoint server_address(IPEndPoint(net::test::Loopback4(), port)); |
| 41 QuicServerId server_id("hostname", server_address.port(), false, | 43 QuicServerId server_id("hostname", server_address.port(), |
| 42 PRIVACY_MODE_DISABLED); | 44 PRIVACY_MODE_DISABLED); |
| 43 QuicVersionVector versions = QuicSupportedVersions(); | 45 QuicVersionVector versions = QuicSupportedVersions(); |
| 44 QuicClient* client = new QuicClient(server_address, server_id, versions, eps); | 46 QuicClient* client = |
| 47 new QuicClient(server_address, server_id, versions, eps, |
| 48 CryptoTestUtils::ProofVerifierForTesting()); |
| 45 EXPECT_TRUE(client->Initialize()); | 49 EXPECT_TRUE(client->Initialize()); |
| 46 return client; | 50 return client; |
| 47 } | 51 } |
| 48 | 52 |
| 49 TEST(QuicClientTest, DoNotLeakFDs) { | 53 TEST(QuicClientTest, DoNotLeakFDs) { |
| 50 // Make sure that the QuicClient doesn't leak FDs. Doing so could cause port | 54 // Make sure that the QuicClient doesn't leak FDs. Doing so could cause port |
| 51 // exhaustion in long running processes which repeatedly create clients. | 55 // exhaustion in long running processes which repeatedly create clients. |
| 52 | 56 |
| 53 // Record initial number of FDs, after creation of EpollServer. | 57 // Record initial number of FDs, after creation of EpollServer. |
| 54 EpollServer eps; | 58 EpollServer eps; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 66 } | 70 } |
| 67 | 71 |
| 68 // The FDs created by the QuicClients should now be closed. | 72 // The FDs created by the QuicClients should now be closed. |
| 69 EXPECT_EQ(number_of_open_fds, NumOpenFDs()); | 73 EXPECT_EQ(number_of_open_fds, NumOpenFDs()); |
| 70 } | 74 } |
| 71 | 75 |
| 72 } // namespace | 76 } // namespace |
| 73 } // namespace test | 77 } // namespace test |
| 74 } // namespace tools | 78 } // namespace tools |
| 75 } // namespace net | 79 } // namespace net |
| OLD | NEW |