make AsyncServerSocket bind to same port on ipv4 and ipv6 with port=0
[folly.git] / folly / io / async / test / AsyncSocketTest.cpp
index 34971dc2efa35338cb08a009cb065fb142af224d..e8f3cf120fcf84d8440fe4bdb37e7cc747e36eef 100644 (file)
@@ -64,4 +64,16 @@ TEST(AsyncSocketTest, REUSEPORT) {
 
 }
 
+TEST(AsyncSocketTest, v4v6samePort) {
+  EventBase base;
+  auto serverSocket = AsyncServerSocket::newSocket(&base);
+  serverSocket->bind(0);
+  auto addrs = serverSocket->getAddresses();
+  ASSERT_GT(addrs.size(), 0);
+  uint16_t port = addrs[0].getPort();
+  for (const auto& addr : addrs) {
+    EXPECT_EQ(port, addr.getPort());
+  }
+}
+
 } // namespace