Skip to content

Commit 55f95d3

Browse files
yoneyfacebook-github-bot
authored andcommitted
Update test for TCP_KEEPALIVE
Summary: On MacOS `TCP_KEEPALIVE` can be used in the same way `TCP_KEEPIDLE` is used on Linux. Update the test for macos build. Reviewed By: vitaut Differential Revision: D69248193 fbshipit-source-id: c9822c2faf1f826df33ed95d40d47c4213b9cd26
1 parent 5692f76 commit 55f95d3

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

third-party/thrift/src/thrift/lib/cpp2/test/server/ThriftServerTest.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -3674,6 +3674,13 @@ TEST(ThriftServer, SocketQueueTimeout) {
36743674
}
36753675

36763676
TEST(ThriftServer, PerConnectionSocketOptions) {
3677+
// On MacOS TCP_KEEPALIVE can be used in the same way TCP_KEEPIDLE is used on
3678+
// Linux.
3679+
#if defined(__APPLE__) && defined(TCP_KEEPALIVE)
3680+
constexpr auto kTCPKeepIdle = TCP_KEEPALIVE;
3681+
#else
3682+
constexpr auto kTCPKeepIdle = TCP_KEEPIDLE;
3683+
#endif
36773684
class TestServiceHandler
36783685
: public apache::thrift::ServiceHandler<TestService> {
36793686
void voidResponse() override {
@@ -3690,7 +3697,7 @@ TEST(ThriftServer, PerConnectionSocketOptions) {
36903697
return value;
36913698
};
36923699
soKeepAlive = readSockOpt(SOL_SOCKET, SO_KEEPALIVE);
3693-
tcpKeepIdle = readSockOpt(IPPROTO_TCP, TCP_KEEPIDLE);
3700+
tcpKeepIdle = readSockOpt(IPPROTO_TCP, kTCPKeepIdle);
36943701
tcpKeepIntvl = readSockOpt(IPPROTO_TCP, TCP_KEEPINTVL);
36953702
tcpKeepCnt = readSockOpt(IPPROTO_TCP, TCP_KEEPCNT);
36963703
}
@@ -3706,7 +3713,7 @@ TEST(ThriftServer, PerConnectionSocketOptions) {
37063713
ScopedServerInterfaceThread runner(handler, [](ThriftServer& server) {
37073714
folly::SocketOptionMap socketOptions{
37083715
{{SOL_SOCKET, SO_KEEPALIVE}, 1},
3709-
{{IPPROTO_TCP, TCP_KEEPIDLE}, 2},
3716+
{{IPPROTO_TCP, kTCPKeepIdle}, 2},
37103717
{{IPPROTO_TCP, TCP_KEEPINTVL}, 3},
37113718
{{IPPROTO_TCP, TCP_KEEPCNT}, 4},
37123719
};
@@ -3716,7 +3723,7 @@ TEST(ThriftServer, PerConnectionSocketOptions) {
37163723
auto client = runner.newClient<apache::thrift::Client<TestService>>();
37173724
client->sync_voidResponse();
37183725

3719-
EXPECT_EQ(handler->soKeepAlive, 1);
3726+
EXPECT_TRUE(handler->soKeepAlive);
37203727
EXPECT_EQ(handler->tcpKeepIdle, 2);
37213728
EXPECT_EQ(handler->tcpKeepIntvl, 3);
37223729
EXPECT_EQ(handler->tcpKeepCnt, 4);

0 commit comments

Comments
 (0)