From 873d451128cf4aee2b8a7b7c460e24ed8e42c334 Mon Sep 17 00:00:00 2001 From: Maxim Georgiev Date: Thu, 23 Mar 2017 10:31:34 -0700 Subject: [PATCH] Randomize the Unix socket name in AsyncSocketTest.SendMessageAncillaryData test to avoid collisions. Summary: Our test framework reports frequent failures of AsyncSocketTest.SendMessageAncillaryData. According to the logs the socket fails to bind: folly/io/async/test/AsyncSocketTest2.cpp:3098: Failure Expected: (bind(lfd, (struct sockaddr*)&addr, sizeof(addr))) != (-1), actual: -1 vs -1 Bind failed: 98 This diff adds the socket name randomization to avoid name collisions between tests running concurrently on the same test box. Reviewed By: yfeldblum Differential Revision: D4758942 fbshipit-source-id: 6066dbc18222a4521c40b2ff218cb7dab8bd789d --- folly/io/async/test/AsyncSocketTest2.cpp | 33 ++++++------------------ 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/folly/io/async/test/AsyncSocketTest2.cpp b/folly/io/async/test/AsyncSocketTest2.cpp index cbca3d34..e90bca5c 100644 --- a/folly/io/async/test/AsyncSocketTest2.cpp +++ b/folly/io/async/test/AsyncSocketTest2.cpp @@ -3085,38 +3085,21 @@ TEST(AsyncSocketTest, SendMessageFlags) { } TEST(AsyncSocketTest, SendMessageAncillaryData) { - struct sockaddr_un addr = {AF_UNIX, - "AsyncSocketTest.SendMessageAncillaryData\0"}; + int fds[2]; + EXPECT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, fds), 0); - // Clean up the name in the name space we're going to use - ASSERT_FALSE(remove(addr.sun_path) == -1 && errno != ENOENT); + // "Client" socket + int cfd = fds[0]; + ASSERT_NE(cfd, -1); - // Set up listening socket - int lfd = fsp::socket(AF_UNIX, SOCK_STREAM, 0); - ASSERT_NE(lfd, -1); - SCOPE_EXIT { close(lfd); }; - ASSERT_NE(bind(lfd, (struct sockaddr*)&addr, sizeof(addr)), -1) - << "Bind failed: " << errno; - - // Create the connecting socket - int csd = fsp::socket(AF_UNIX, SOCK_STREAM, 0); - ASSERT_NE(csd, -1); - - // Listen for incoming connect - ASSERT_NE(listen(lfd, 5), -1); - - // Connect to the listening socket - ASSERT_NE(fsp::connect(csd, (struct sockaddr*)&addr, sizeof(addr)), -1) - << "Connect request failed: " << errno; - - // Accept the connection - int sfd = accept(lfd, nullptr, nullptr); + // "Server" socket + int sfd = fds[1]; ASSERT_NE(sfd, -1); SCOPE_EXIT { close(sfd); }; // Instantiate AsyncSocket object for the connected socket EventBase evb; - std::shared_ptr socket = AsyncSocket::newSocket(&evb, csd); + std::shared_ptr socket = AsyncSocket::newSocket(&evb, cfd); // Open a temporary file and write a magic string to it // We'll transfer the file handle to test the message parameters -- 2.34.1