Merge pull request #19138 from rmstar/cfstreamtestlog

cfstream_test: print HTTP2 stream id of completed RPCs
reviewable/pr19276/r1
rmstar 6 years ago committed by GitHub
commit 7d99c560ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 37
      test/cpp/end2end/cfstream_test.cc

@ -42,6 +42,7 @@
#include "src/core/lib/gpr/env.h" #include "src/core/lib/gpr/env.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h" #include "src/proto/grpc/testing/echo.grpc.pb.h"
#include "test/core/util/debugger_macros.h"
#include "test/core/util/port.h" #include "test/core/util/port.h"
#include "test/core/util/test_config.h" #include "test/core/util/test_config.h"
#include "test/cpp/end2end/test_service_impl.h" #include "test/cpp/end2end/test_service_impl.h"
@ -144,6 +145,18 @@ class CFStreamTest : public ::testing::TestWithParam<TestScenario> {
return CreateCustomChannel(server_address.str(), channel_creds, args); return CreateCustomChannel(server_address.str(), channel_creds, args);
} }
int GetStreamID(ClientContext& context) {
int stream_id = 0;
grpc_call* call = context.c_call();
if (call) {
grpc_chttp2_stream* stream = grpc_chttp2_stream_from_call(call);
if (stream) {
stream_id = stream->id;
}
}
return stream_id;
}
void SendRpc( void SendRpc(
const std::unique_ptr<grpc::testing::EchoTestService::Stub>& stub, const std::unique_ptr<grpc::testing::EchoTestService::Stub>& stub,
bool expect_success = false) { bool expect_success = false) {
@ -153,10 +166,13 @@ class CFStreamTest : public ::testing::TestWithParam<TestScenario> {
request.set_message(msg); request.set_message(msg);
ClientContext context; ClientContext context;
Status status = stub->Echo(&context, request, response.get()); Status status = stub->Echo(&context, request, response.get());
int stream_id = GetStreamID(context);
if (status.ok()) { if (status.ok()) {
gpr_log(GPR_DEBUG, "RPC with stream_id %d succeeded", stream_id);
EXPECT_EQ(msg, response->message()); EXPECT_EQ(msg, response->message());
} else { } else {
gpr_log(GPR_DEBUG, "RPC failed: %s", status.error_message().c_str()); gpr_log(GPR_DEBUG, "RPC with stream_id %d failed: %s", stream_id,
status.error_message().c_str());
} }
if (expect_success) { if (expect_success) {
EXPECT_TRUE(status.ok()); EXPECT_TRUE(status.ok());
@ -361,14 +377,17 @@ TEST_P(CFStreamTest, NetworkFlapRpcsInFlight) {
++total_completions; ++total_completions;
GPR_ASSERT(ok); GPR_ASSERT(ok);
AsyncClientCall* call = static_cast<AsyncClientCall*>(got_tag); AsyncClientCall* call = static_cast<AsyncClientCall*>(got_tag);
int stream_id = GetStreamID(call->context);
if (!call->status.ok()) { if (!call->status.ok()) {
gpr_log(GPR_DEBUG, "RPC failed with error: %s", gpr_log(GPR_DEBUG, "RPC with stream_id %d failed with error: %s",
call->status.error_message().c_str()); stream_id, call->status.error_message().c_str());
// Bring network up when RPCs start failing // Bring network up when RPCs start failing
if (network_down) { if (network_down) {
NetworkUp(); NetworkUp();
network_down = false; network_down = false;
} }
} else {
gpr_log(GPR_DEBUG, "RPC with stream_id %d succeeded", stream_id);
} }
delete call; delete call;
} }
@ -397,21 +416,19 @@ TEST_P(CFStreamTest, ConcurrentRpc) {
std::thread thd = std::thread([this, &rpcs_sent]() { std::thread thd = std::thread([this, &rpcs_sent]() {
void* got_tag; void* got_tag;
bool ok = false; bool ok = false;
bool network_down = true;
int total_completions = 0; int total_completions = 0;
while (CQNext(&got_tag, &ok)) { while (CQNext(&got_tag, &ok)) {
++total_completions; ++total_completions;
GPR_ASSERT(ok); GPR_ASSERT(ok);
AsyncClientCall* call = static_cast<AsyncClientCall*>(got_tag); AsyncClientCall* call = static_cast<AsyncClientCall*>(got_tag);
int stream_id = GetStreamID(call->context);
if (!call->status.ok()) { if (!call->status.ok()) {
gpr_log(GPR_DEBUG, "RPC failed: %s", gpr_log(GPR_DEBUG, "RPC with stream_id %d failed with error: %s",
call->status.error_message().c_str()); stream_id, call->status.error_message().c_str());
// Bring network up when RPCs start failing // Bring network up when RPCs start failing
if (network_down) { } else {
NetworkUp(); gpr_log(GPR_DEBUG, "RPC with stream_id %d succeeded", stream_id);
network_down = false;
}
} }
delete call; delete call;
} }

Loading…
Cancel
Save