Skip to content

Commit

Permalink
fix keepalive UT
Browse files Browse the repository at this point in the history
  • Loading branch information
chenguangming committed Jan 31, 2023
1 parent 64ba10b commit 21ba918
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/brpc/input_messenger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ int InputMessenger::Create(SocketOptions options, SocketId* id) {
}
// Enable keepalive by options or Gflag.
// Priority: options > Gflag.
while (options.keepalive_options || FLAGS_socket_keepalive) {
if (options.keepalive_options || FLAGS_socket_keepalive) {
if (!options.keepalive_options) {
options.keepalive_options = std::make_shared<SocketKeepaliveOptions>();
}
Expand Down
34 changes: 21 additions & 13 deletions test/brpc_socket_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@ TEST_F(SocketTest, keepalive) {
butil::fd_guard sockfd(socket(AF_INET, SOCK_STREAM, 0));
brpc::SocketOptions options;
options.fd = sockfd;
options.enable_keepalive();
options.keepalive_options = std::make_shared<brpc::SocketKeepaliveOptions>();
brpc::SocketId id;
ASSERT_EQ(0, brpc::Socket::Create(options, &id));
brpc::SocketUniquePtr ptr;
Expand All @@ -1143,7 +1143,8 @@ TEST_F(SocketTest, keepalive) {
butil::fd_guard sockfd(socket(AF_INET, SOCK_STREAM, 0));
brpc::SocketOptions options;
options.fd = sockfd;
options.mutable_keepalive_options()->keepalive_idle_s
options.keepalive_options = std::make_shared<brpc::SocketKeepaliveOptions>();
options.keepalive_options->keepalive_idle_s
= keepalive_idle;
brpc::SocketId id;
ASSERT_EQ(0, brpc::Socket::Create(options, &id));
Expand All @@ -1161,7 +1162,8 @@ TEST_F(SocketTest, keepalive) {
butil::fd_guard sockfd(socket(AF_INET, SOCK_STREAM, 0));
brpc::SocketOptions options;
options.fd = sockfd;
options.mutable_keepalive_options()->keepalive_interval_s
options.keepalive_options = std::make_shared<brpc::SocketKeepaliveOptions>();
options.keepalive_options->keepalive_interval_s
= keepalive_interval;
brpc::SocketId id;
ASSERT_EQ(0, brpc::Socket::Create(options, &id));
Expand All @@ -1179,7 +1181,8 @@ TEST_F(SocketTest, keepalive) {
butil::fd_guard sockfd(socket(AF_INET, SOCK_STREAM, 0));
brpc::SocketOptions options;
options.fd = sockfd;
options.mutable_keepalive_options()->keepalive_count
options.keepalive_options = std::make_shared<brpc::SocketKeepaliveOptions>();
options.keepalive_options->keepalive_count
= keepalive_count;
brpc::SocketId id;
ASSERT_EQ(0, brpc::Socket::Create(options, &id));
Expand All @@ -1197,11 +1200,12 @@ TEST_F(SocketTest, keepalive) {
butil::fd_guard sockfd(socket(AF_INET, SOCK_STREAM, 0));
brpc::SocketOptions options;
options.fd = sockfd;
options.mutable_keepalive_options()->keepalive_idle_s
options.keepalive_options = std::make_shared<brpc::SocketKeepaliveOptions>();
options.keepalive_options->keepalive_idle_s
= keepalive_idle;
options.mutable_keepalive_options()->keepalive_interval_s
options.keepalive_options->keepalive_interval_s
= keepalive_interval;
options.mutable_keepalive_options()->keepalive_count
options.keepalive_options->keepalive_count
= keepalive_count;
brpc::SocketId id;
ASSERT_EQ(0, brpc::Socket::Create(options, &id));
Expand Down Expand Up @@ -1323,7 +1327,8 @@ TEST_F(SocketTest, keepalive_input_message) {
butil::fd_guard sockfd(socket(AF_INET, SOCK_STREAM, 0));
brpc::SocketOptions options;
options.fd = sockfd;
options.mutable_keepalive_options()->keepalive_idle_s
options.keepalive_options = std::make_shared<brpc::SocketKeepaliveOptions>();
options.keepalive_options->keepalive_idle_s
= keepalive_idle;
brpc::SocketId id;
ASSERT_EQ(0, brpc::get_or_new_client_side_messenger()
Expand All @@ -1341,7 +1346,8 @@ TEST_F(SocketTest, keepalive_input_message) {
butil::fd_guard sockfd(socket(AF_INET, SOCK_STREAM, 0));
brpc::SocketOptions options;
options.fd = sockfd;
options.mutable_keepalive_options()->keepalive_interval_s
options.keepalive_options = std::make_shared<brpc::SocketKeepaliveOptions>();
options.keepalive_options->keepalive_interval_s
= keepalive_interval;
brpc::SocketId id;
ASSERT_EQ(0, brpc::get_or_new_client_side_messenger()
Expand All @@ -1359,7 +1365,8 @@ TEST_F(SocketTest, keepalive_input_message) {
butil::fd_guard sockfd(socket(AF_INET, SOCK_STREAM, 0));
brpc::SocketOptions options;
options.fd = sockfd;
options.mutable_keepalive_options()->keepalive_count
options.keepalive_options = std::make_shared<brpc::SocketKeepaliveOptions>();
options.keepalive_options->keepalive_count
= keepalive_count;
brpc::SocketId id;
ASSERT_EQ(0, brpc::get_or_new_client_side_messenger()
Expand All @@ -1377,11 +1384,12 @@ TEST_F(SocketTest, keepalive_input_message) {
butil::fd_guard sockfd(socket(AF_INET, SOCK_STREAM, 0));
brpc::SocketOptions options;
options.fd = sockfd;
options.mutable_keepalive_options()->keepalive_idle_s
options.keepalive_options = std::make_shared<brpc::SocketKeepaliveOptions>();
options.keepalive_options->keepalive_idle_s
= keepalive_idle;
options.mutable_keepalive_options()->keepalive_interval_s
options.keepalive_options->keepalive_interval_s
= keepalive_interval;
options.mutable_keepalive_options()->keepalive_count
options.keepalive_options->keepalive_count
= keepalive_count;
brpc::SocketId id;
ASSERT_EQ(0, brpc::get_or_new_client_side_messenger()
Expand Down

0 comments on commit 21ba918

Please sign in to comment.