Commit ea2d4e84 authored by Orvid King's avatar Orvid King Committed by Facebook Github Bot

Nuke AsyncSocketTest.ConnectionsStorm

Summary: This test is the definition of how not to write a reliable test, resulting in extreme flakyness and timeouts, so nuke it.

Reviewed By: yfeldblum

Differential Revision: D10856270

fbshipit-source-id: d8b585d439c091e763075a604d2fe21b517ae93c
parent 37f21767
......@@ -2319,89 +2319,6 @@ TEST(AsyncSocketTest, NumPendingMessagesInQueue) {
ASSERT_EQ(4, count);
}
TEST(AsyncSocketTest, ConnectionsStorm) {
enum class AcceptCobLocation {
Default,
Primary,
Secondary,
};
auto testFunc = [](AcceptCobLocation mode) {
EventBase eventBase;
// Counter of how many connections have been accepted
std::atomic<size_t> count{0};
// Create a server socket
auto serverSocket(AsyncServerSocket::newSocket(&eventBase));
serverSocket->bind(0);
serverSocket->listen(100);
folly::SocketAddress serverAddress;
serverSocket->getAddress(&serverAddress);
TestConnectionEventCallback connectionEventCallback;
serverSocket->setConnectionEventCallback(&connectionEventCallback);
// Add a callback to accept connections
std::shared_ptr<ScopedEventBaseThread> thread;
TestAcceptCallback acceptCallback;
bool stopAccepting = false;
const size_t maxSockets = 2000;
acceptCallback.setConnectionAcceptedFn(
[&](int /* fd */, const folly::SocketAddress& /* addr */) {
count++;
if (!stopAccepting &&
(count == maxSockets ||
connectionEventCallback.getConnectionDropped() > 0)) {
stopAccepting = true;
eventBase.runInEventBaseThread([&] {
serverSocket->removeAcceptCallback(&acceptCallback, nullptr);
});
}
});
acceptCallback.setAcceptErrorFn([&](const std::exception& /* ex */) {
eventBase.runInEventBaseThread([&] {
stopAccepting = true;
serverSocket->removeAcceptCallback(&acceptCallback, nullptr);
});
});
if (mode == AcceptCobLocation::Default) {
serverSocket->addAcceptCallback(&acceptCallback, nullptr);
} else if (mode == AcceptCobLocation::Primary) {
serverSocket->addAcceptCallback(&acceptCallback, &eventBase);
} else if (mode == AcceptCobLocation::Secondary) {
thread = std::make_shared<ScopedEventBaseThread>();
serverSocket->addAcceptCallback(&acceptCallback, thread->getEventBase());
}
serverSocket->startAccepting();
// Create connection storm to create connections fast but
// also pace it to not overflow servers' listening queue.
vector<std::shared_ptr<AsyncSocket>> sockets;
folly::Function<void()> fnOpenSockets = [&]() {
// Counter of connections pending the invocation of accept callback.
auto pending = serverSocket->getNumPendingMessagesInQueue();
while (sockets.size() < std::min(maxSockets, pending + count + 30)) {
auto socket = folly::AsyncSocket::newSocket(&eventBase);
socket->connect(nullptr, serverAddress, 5000);
sockets.push_back(socket);
}
if (sockets.size() < maxSockets && !stopAccepting) {
eventBase.runInEventBaseThread([&] { fnOpenSockets(); });
}
};
eventBase.runInEventBaseThread([&] { fnOpenSockets(); });
eventBase.loop();
ASSERT_EQ(maxSockets, count);
};
testFunc(AcceptCobLocation::Default);
testFunc(AcceptCobLocation::Primary);
testFunc(AcceptCobLocation::Secondary);
}
/**
* Test AsyncTransport::BufferCallback
*/
......
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