Commit 873d4511 authored by Maxim Georgiev's avatar Maxim Georgiev Committed by Facebook Github Bot

Randomize the Unix socket name in AsyncSocketTest.SendMessageAncillaryData...

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
parent 18f713a6
......@@ -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<AsyncSocket> socket = AsyncSocket::newSocket(&evb, csd);
std::shared_ptr<AsyncSocket> 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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment