| 32 | class FreePortTest: public NetworkTestBase {}; |
| 33 | |
| 34 | TEST_F(NetworkTest, FreePort) { |
| 35 | NTesting::TScopedEnvironment envGuard("PORT_SYNC_PATH", TmpDir->Name()); |
| 36 | NTesting::InitPortManagerFromEnv(); |
| 37 | TVector<NTesting::TPortHolder> ports(Reserve(100)); |
| 38 | |
| 39 | for (size_t i = 0; i < 100; ++i) { |
| 40 | ports.push_back(NTesting::GetFreePort()); |
| 41 | } |
| 42 | |
| 43 | THashSet<ui16> uniqPorts; |
| 44 | for (auto& port : ports) { |
| 45 | const TString guardPath = TmpDir->Path() / ToString(static_cast<ui16>(port)); |
| 46 | EXPECT_TRUE(NFs::Exists(guardPath)); |
| 47 | EXPECT_TRUE(uniqPorts.emplace(port).second); |
| 48 | |
| 49 | TInetStreamSocket sock; |
| 50 | TSockAddrInet addr(TIpHost{INADDR_ANY}, port); |
| 51 | ASSERT_EQ(0, SetSockOpt(sock, SOL_SOCKET, SO_REUSEADDR, 1)); |
| 52 | EXPECT_EQ(0, sock.Bind(&addr)); |
| 53 | } |
| 54 | ports.clear(); |
| 55 | for (ui16 port : uniqPorts) { |
| 56 | const TString guardPath = TmpDir->Path() / ToString(port); |
| 57 | EXPECT_FALSE(NFs::Exists(guardPath)); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | TEST_F(NetworkTest, FreePortWithinRanges) { |
| 62 | NTesting::TScopedEnvironment envGuard{{ |
nothing calls this directly
no test coverage detected