Skip to content

Commit b8c8a5d

Browse files
Speed up fboss2 CLI unit tests.
Tests using the mocked agent connection would often incur a 5-7 second delay because of the default Thrift configuration. By being more aggressive we can speed up the tests significantly. The 25 unit tests now take about 20-22s to complete (I’ve seen as low as 11s) vs 125-135s before (testing on Intel Xeon Silver 4309Y @ 2.80GHz).
1 parent 304768f commit b8c8a5d

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

fboss/cli/fboss2/test/CmdHandlerTestBase.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <gtest/gtest.h>
44

55
#include <folly/IPAddressV4.h>
6+
#include <thrift/lib/cpp2/server/ThriftServer.h>
67
#include <thrift/lib/cpp2/util/ScopedServerInterfaceThread.h>
78
#include <memory>
89
#include "fboss/cli/fboss2/CmdGlobalOptions.h"
@@ -23,17 +24,26 @@ class CmdHandlerTestBase : public ::testing::Test {
2324
"test.host", "test-oob.host", folly::IPAddressV6("::1"));
2425
}
2526

27+
// Helper to create server config with short idle timeout to avoid 5-7 second
28+
// delays in test responses. Without this, the default idle timeout causes
29+
// the server to wait before sending responses back to the client.
30+
static auto createFastMockServerConfig() {
31+
return [](apache::thrift::ThriftServer& server) {
32+
server.setIdleTimeout(std::chrono::milliseconds(50));
33+
};
34+
}
35+
2636
void setupMockedAgentServer() {
2737
mockedAgentServer_ =
2838
std::make_unique<apache::thrift::ScopedServerInterfaceThread>(
29-
mockedAgent_);
39+
mockedAgent_, createFastMockServerConfig());
3040
// set global agent thrift port to the fake server created on localhost
3141
CmdGlobalOptions::getInstance()->setAgentThriftPort(
3242
mockedAgentServer_->getAddress().getPort());
3343

3444
mockedQsfpServer_ =
3545
std::make_unique<apache::thrift::ScopedServerInterfaceThread>(
36-
mockedQsfpService_);
46+
mockedQsfpService_, createFastMockServerConfig());
3747
// set global agent thrift port to the fake server created on localhost
3848
CmdGlobalOptions::getInstance()->setQsfpThriftPort(
3949
mockedQsfpServer_->getAddress().getPort());
@@ -43,7 +53,7 @@ class CmdHandlerTestBase : public ::testing::Test {
4353
#ifndef IS_OSS
4454
mockedBgpServer_ =
4555
std::make_unique<apache::thrift::ScopedServerInterfaceThread>(
46-
mockedBgpService_);
56+
mockedBgpService_, createFastMockServerConfig());
4757
CmdGlobalOptions::getInstance()->setBgpThriftPort(
4858
mockedBgpServer_->getAddress().getPort());
4959
#endif

fboss/cli/fboss2/test/CmdShowHostTest.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,9 @@ std::vector<NdpEntryThrift> createMockNdpEntries() {
4444
ndpEntry2.port() = 1;
4545
ndpEntry2.classID() = 0;
4646

47-
NdpEntryThrift ndpEntry3;
48-
folly::IPAddressV6 ipv6_3("2401:db00:e13d:846::41");
49-
network::thrift::BinaryAddress binaryAddr3 =
50-
facebook::network::toBinaryAddress(ipv6_3);
51-
52-
ndpEntry3.ip() = binaryAddr3;
53-
ndpEntry3.port() = 51;
54-
ndpEntry3.classID() = 0;
55-
56-
std::vector<NdpEntryThrift> entries{ndpEntry1, ndpEntry2, ndpEntry3};
47+
// Only return entries that will be in the final model to avoid unnecessary
48+
// DNS lookups during tests
49+
std::vector<NdpEntryThrift> entries{ndpEntry1, ndpEntry2};
5750
return entries;
5851
}
5952

0 commit comments

Comments
 (0)