From 9c043baf4990139c222da49622c8b1172164dcf3 Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Mon, 21 Dec 2020 12:57:10 -0800 Subject: [PATCH] Allow the channelz service test to get different listen socket sizes --- test/cpp/end2end/channelz_service_test.cc | 25 +++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/test/cpp/end2end/channelz_service_test.cc b/test/cpp/end2end/channelz_service_test.cc index 51fccf33c7c..8faeb29f8fa 100644 --- a/test/cpp/end2end/channelz_service_test.cc +++ b/test/cpp/end2end/channelz_service_test.cc @@ -746,9 +746,10 @@ TEST_F(ChannelzServerTest, GetServerListenSocketsTest) { &get_server_response); EXPECT_TRUE(s.ok()) << "s.error_message() = " << s.error_message(); EXPECT_EQ(get_server_response.server_size(), 1); - // The server address gets resolved to two addresses, one for ipv4 and one for - // ipv6, and hence two sockets. - EXPECT_EQ(get_server_response.server(0).listen_socket_size(), 2); + // The resolver might return one or two addresses depending on the + // configuration, one for ipv4 and one for ipv6. + int listen_socket_size = get_server_response.server(0).listen_socket_size(); + EXPECT_TRUE(listen_socket_size == 1 || listen_socket_size == 2); GetSocketRequest get_socket_request; GetSocketResponse get_socket_response; get_socket_request.set_socket_id( @@ -759,14 +760,16 @@ TEST_F(ChannelzServerTest, GetServerListenSocketsTest) { s = channelz_stub_->GetSocket(&get_socket_context_1, get_socket_request, &get_socket_response); EXPECT_TRUE(s.ok()) << "s.error_message() = " << s.error_message(); - get_socket_request.set_socket_id( - get_server_response.server(0).listen_socket(1).socket_id()); - ClientContext get_socket_context_2; - EXPECT_TRUE( - get_server_response.server(0).listen_socket(1).name().find("http")); - s = channelz_stub_->GetSocket(&get_socket_context_2, get_socket_request, - &get_socket_response); - EXPECT_TRUE(s.ok()) << "s.error_message() = " << s.error_message(); + if (listen_socket_size == 2) { + get_socket_request.set_socket_id( + get_server_response.server(0).listen_socket(1).socket_id()); + ClientContext get_socket_context_2; + EXPECT_TRUE( + get_server_response.server(0).listen_socket(1).name().find("http")); + s = channelz_stub_->GetSocket(&get_socket_context_2, get_socket_request, + &get_socket_response); + EXPECT_TRUE(s.ok()) << "s.error_message() = " << s.error_message(); + } } } // namespace testing