|
|
|
@ -144,7 +144,7 @@ class ChannelzServerTest : public ::testing::Test { |
|
|
|
|
ClientContext context; |
|
|
|
|
Status s = echo_stub_->Echo(&context, request, &response); |
|
|
|
|
EXPECT_EQ(response.message(), request.message()); |
|
|
|
|
EXPECT_TRUE(s.ok()) << s.error_message(); |
|
|
|
|
EXPECT_TRUE(s.ok()) << "s.error_message() = " << s.error_message(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void SendFailedEcho(int channel_idx) { |
|
|
|
@ -160,6 +160,19 @@ class ChannelzServerTest : public ::testing::Test { |
|
|
|
|
EXPECT_FALSE(s.ok()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Uses GetTopChannels to return the channel_id of a particular channel,
|
|
|
|
|
// so that the unit tests may test GetChannel call.
|
|
|
|
|
intptr_t GetChannelId(int channel_idx) { |
|
|
|
|
GetTopChannelsRequest request; |
|
|
|
|
GetTopChannelsResponse response; |
|
|
|
|
request.set_start_channel_id(0); |
|
|
|
|
ClientContext context; |
|
|
|
|
Status s = channelz_stub_->GetTopChannels(&context, request, &response); |
|
|
|
|
EXPECT_TRUE(s.ok()) << "s.error_message() = " << s.error_message(); |
|
|
|
|
EXPECT_GT(response.channel_size(), channel_idx); |
|
|
|
|
return response.channel(channel_idx).ref().channel_id(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static string to_string(const int number) { |
|
|
|
|
std::stringstream strs; |
|
|
|
|
strs << number; |
|
|
|
@ -194,7 +207,7 @@ TEST_F(ChannelzServerTest, BasicTest) { |
|
|
|
|
request.set_start_channel_id(0); |
|
|
|
|
ClientContext context; |
|
|
|
|
Status s = channelz_stub_->GetTopChannels(&context, request, &response); |
|
|
|
|
EXPECT_TRUE(s.ok()) << s.error_message(); |
|
|
|
|
EXPECT_TRUE(s.ok()) << "s.error_message() = " << s.error_message(); |
|
|
|
|
EXPECT_EQ(response.channel_size(), 1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -206,7 +219,7 @@ TEST_F(ChannelzServerTest, HighStartId) { |
|
|
|
|
request.set_start_channel_id(10000); |
|
|
|
|
ClientContext context; |
|
|
|
|
Status s = channelz_stub_->GetTopChannels(&context, request, &response); |
|
|
|
|
EXPECT_TRUE(s.ok()) << s.error_message(); |
|
|
|
|
EXPECT_TRUE(s.ok()) << "s.error_message() = " << s.error_message(); |
|
|
|
|
EXPECT_EQ(response.channel_size(), 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -216,10 +229,10 @@ TEST_F(ChannelzServerTest, SuccessfulRequestTest) { |
|
|
|
|
SendSuccessfulEcho(0); |
|
|
|
|
GetChannelRequest request; |
|
|
|
|
GetChannelResponse response; |
|
|
|
|
request.set_channel_id(1); |
|
|
|
|
request.set_channel_id(GetChannelId(0)); |
|
|
|
|
ClientContext context; |
|
|
|
|
Status s = channelz_stub_->GetChannel(&context, request, &response); |
|
|
|
|
EXPECT_TRUE(s.ok()) << s.error_message(); |
|
|
|
|
EXPECT_TRUE(s.ok()) << "s.error_message() = " << s.error_message(); |
|
|
|
|
EXPECT_EQ(response.channel().data().calls_started(), 1); |
|
|
|
|
EXPECT_EQ(response.channel().data().calls_succeeded(), 1); |
|
|
|
|
EXPECT_EQ(response.channel().data().calls_failed(), 0); |
|
|
|
@ -231,10 +244,10 @@ TEST_F(ChannelzServerTest, FailedRequestTest) { |
|
|
|
|
SendFailedEcho(0); |
|
|
|
|
GetChannelRequest request; |
|
|
|
|
GetChannelResponse response; |
|
|
|
|
request.set_channel_id(1); |
|
|
|
|
request.set_channel_id(GetChannelId(0)); |
|
|
|
|
ClientContext context; |
|
|
|
|
Status s = channelz_stub_->GetChannel(&context, request, &response); |
|
|
|
|
EXPECT_TRUE(s.ok()) << s.error_message(); |
|
|
|
|
EXPECT_TRUE(s.ok()) << "s.error_message() = " << s.error_message(); |
|
|
|
|
EXPECT_EQ(response.channel().data().calls_started(), 1); |
|
|
|
|
EXPECT_EQ(response.channel().data().calls_succeeded(), 0); |
|
|
|
|
EXPECT_EQ(response.channel().data().calls_failed(), 1); |
|
|
|
@ -254,10 +267,10 @@ TEST_F(ChannelzServerTest, ManyRequestsTest) { |
|
|
|
|
} |
|
|
|
|
GetChannelRequest request; |
|
|
|
|
GetChannelResponse response; |
|
|
|
|
request.set_channel_id(1); |
|
|
|
|
request.set_channel_id(GetChannelId(0)); |
|
|
|
|
ClientContext context; |
|
|
|
|
Status s = channelz_stub_->GetChannel(&context, request, &response); |
|
|
|
|
EXPECT_TRUE(s.ok()) << s.error_message(); |
|
|
|
|
EXPECT_TRUE(s.ok()) << "s.error_message() = " << s.error_message(); |
|
|
|
|
EXPECT_EQ(response.channel().data().calls_started(), |
|
|
|
|
kNumSuccess + kNumFailed); |
|
|
|
|
EXPECT_EQ(response.channel().data().calls_succeeded(), kNumSuccess); |
|
|
|
@ -273,7 +286,7 @@ TEST_F(ChannelzServerTest, ManyChannels) { |
|
|
|
|
request.set_start_channel_id(0); |
|
|
|
|
ClientContext context; |
|
|
|
|
Status s = channelz_stub_->GetTopChannels(&context, request, &response); |
|
|
|
|
EXPECT_TRUE(s.ok()) << s.error_message(); |
|
|
|
|
EXPECT_TRUE(s.ok()) << "s.error_message() = " << s.error_message(); |
|
|
|
|
EXPECT_EQ(response.channel_size(), kNumChannels); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -296,10 +309,10 @@ TEST_F(ChannelzServerTest, ManyRequestsManyChannels) { |
|
|
|
|
{ |
|
|
|
|
GetChannelRequest request; |
|
|
|
|
GetChannelResponse response; |
|
|
|
|
request.set_channel_id(1); |
|
|
|
|
request.set_channel_id(GetChannelId(0)); |
|
|
|
|
ClientContext context; |
|
|
|
|
Status s = channelz_stub_->GetChannel(&context, request, &response); |
|
|
|
|
EXPECT_TRUE(s.ok()) << s.error_message(); |
|
|
|
|
EXPECT_TRUE(s.ok()) << "s.error_message() = " << s.error_message(); |
|
|
|
|
EXPECT_EQ(response.channel().data().calls_started(), kNumSuccess); |
|
|
|
|
EXPECT_EQ(response.channel().data().calls_succeeded(), kNumSuccess); |
|
|
|
|
EXPECT_EQ(response.channel().data().calls_failed(), 0); |
|
|
|
@ -309,10 +322,10 @@ TEST_F(ChannelzServerTest, ManyRequestsManyChannels) { |
|
|
|
|
{ |
|
|
|
|
GetChannelRequest request; |
|
|
|
|
GetChannelResponse response; |
|
|
|
|
request.set_channel_id(2); |
|
|
|
|
request.set_channel_id(GetChannelId(1)); |
|
|
|
|
ClientContext context; |
|
|
|
|
Status s = channelz_stub_->GetChannel(&context, request, &response); |
|
|
|
|
EXPECT_TRUE(s.ok()) << s.error_message(); |
|
|
|
|
EXPECT_TRUE(s.ok()) << "s.error_message() = " << s.error_message(); |
|
|
|
|
EXPECT_EQ(response.channel().data().calls_started(), kNumFailed); |
|
|
|
|
EXPECT_EQ(response.channel().data().calls_succeeded(), 0); |
|
|
|
|
EXPECT_EQ(response.channel().data().calls_failed(), kNumFailed); |
|
|
|
@ -322,10 +335,10 @@ TEST_F(ChannelzServerTest, ManyRequestsManyChannels) { |
|
|
|
|
{ |
|
|
|
|
GetChannelRequest request; |
|
|
|
|
GetChannelResponse response; |
|
|
|
|
request.set_channel_id(3); |
|
|
|
|
request.set_channel_id(GetChannelId(2)); |
|
|
|
|
ClientContext context; |
|
|
|
|
Status s = channelz_stub_->GetChannel(&context, request, &response); |
|
|
|
|
EXPECT_TRUE(s.ok()) << s.error_message(); |
|
|
|
|
EXPECT_TRUE(s.ok()) << "s.error_message() = " << s.error_message(); |
|
|
|
|
EXPECT_EQ(response.channel().data().calls_started(), |
|
|
|
|
kNumSuccess + kNumFailed); |
|
|
|
|
EXPECT_EQ(response.channel().data().calls_succeeded(), kNumSuccess); |
|
|
|
@ -336,10 +349,10 @@ TEST_F(ChannelzServerTest, ManyRequestsManyChannels) { |
|
|
|
|
{ |
|
|
|
|
GetChannelRequest request; |
|
|
|
|
GetChannelResponse response; |
|
|
|
|
request.set_channel_id(4); |
|
|
|
|
request.set_channel_id(GetChannelId(3)); |
|
|
|
|
ClientContext context; |
|
|
|
|
Status s = channelz_stub_->GetChannel(&context, request, &response); |
|
|
|
|
EXPECT_TRUE(s.ok()) << s.error_message(); |
|
|
|
|
EXPECT_TRUE(s.ok()) << "s.error_message() = " << s.error_message(); |
|
|
|
|
EXPECT_EQ(response.channel().data().calls_started(), 0); |
|
|
|
|
EXPECT_EQ(response.channel().data().calls_succeeded(), 0); |
|
|
|
|
EXPECT_EQ(response.channel().data().calls_failed(), 0); |
|
|
|
|