From caf7ea53be2f93c310acbaddbe3da90ccc7e6411 Mon Sep 17 00:00:00 2001 From: Eric Gribkoff <ericgribkoff@google.com> Date: Wed, 1 Mar 2017 08:15:25 -0800 Subject: [PATCH] Enable C++ negative http2 test --- test/cpp/interop/http2_client.cc | 49 ++++++++++++------- .../grpc_interop_cxx/build_interop.sh | 3 ++ tools/run_tests/run_interop_tests.py | 6 ++- 3 files changed, 39 insertions(+), 19 deletions(-) diff --git a/test/cpp/interop/http2_client.cc b/test/cpp/interop/http2_client.cc index b96e9fac36..9ebbdd2af1 100644 --- a/test/cpp/interop/http2_client.cc +++ b/test/cpp/interop/http2_client.cc @@ -88,7 +88,7 @@ bool Http2Client::DoRstAfterHeader() { request.mutable_payload()->set_body(payload.c_str(), kLargeRequestSize); Status s = serviceStub_.Get()->UnaryCall(&context, request, &response); - AssertStatusCode(s, grpc::StatusCode::UNKNOWN); + AssertStatusCode(s, grpc::StatusCode::INTERNAL); GPR_ASSERT(!response.has_payload()); // no data should be received gpr_log(GPR_DEBUG, "Done testing reset stream after header"); @@ -106,7 +106,7 @@ bool Http2Client::DoRstAfterData() { request.mutable_payload()->set_body(payload.c_str(), kLargeRequestSize); Status s = serviceStub_.Get()->UnaryCall(&context, request, &response); - AssertStatusCode(s, grpc::StatusCode::UNKNOWN); + AssertStatusCode(s, grpc::StatusCode::INTERNAL); GPR_ASSERT(response.has_payload()); // data should be received gpr_log(GPR_DEBUG, "Done testing reset stream after data"); @@ -124,7 +124,7 @@ bool Http2Client::DoRstDuringData() { request.mutable_payload()->set_body(payload.c_str(), kLargeRequestSize); Status s = serviceStub_.Get()->UnaryCall(&context, request, &response); - AssertStatusCode(s, grpc::StatusCode::UNKNOWN); + AssertStatusCode(s, grpc::StatusCode::INTERNAL); GPR_ASSERT(!response.has_payload()); // no data should be received gpr_log(GPR_DEBUG, "Done testing reset stream during data"); @@ -134,20 +134,29 @@ bool Http2Client::DoRstDuringData() { bool Http2Client::DoGoaway() { gpr_log(GPR_DEBUG, "Sending two RPCs and expecting goaway"); - int numCalls = 2; - for (int i = 0; i < numCalls; i++) { - ClientContext context; - SimpleRequest request; - SimpleResponse response; - request.set_response_size(kLargeResponseSize); - grpc::string payload(kLargeRequestSize, '\0'); - request.mutable_payload()->set_body(payload.c_str(), kLargeRequestSize); - - Status s = serviceStub_.Get()->UnaryCall(&context, request, &response); - AssertStatusCode(s, grpc::StatusCode::OK); - GPR_ASSERT(response.payload().body() == - grpc::string(kLargeResponseSize, '\0')); - } + SimpleRequest request; + request.set_response_size(kLargeResponseSize); + grpc::string payload(kLargeRequestSize, '\0'); + request.mutable_payload()->set_body(payload.c_str(), kLargeRequestSize); + + ClientContext context1; + SimpleResponse response1; + Status s = serviceStub_.Get()->UnaryCall(&context1, request, &response1); + AssertStatusCode(s, grpc::StatusCode::OK); + GPR_ASSERT(response1.payload().body() == + grpc::string(kLargeResponseSize, '\0')); + + // Sleep for one second to give time for client to receive goaway frame. + gpr_timespec sleep_time = gpr_time_add( + gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis(1000, GPR_TIMESPAN)); + gpr_sleep_until(sleep_time); + + ClientContext context2; + SimpleResponse response2; + s = serviceStub_.Get()->UnaryCall(&context2, request, &response2); + AssertStatusCode(s, grpc::StatusCode::OK); + GPR_ASSERT(response2.payload().body() == + grpc::string(kLargeResponseSize, '\0')); gpr_log(GPR_DEBUG, "Done testing goaway"); return true; @@ -240,7 +249,11 @@ int main(int argc, char** argv) { char host_port[host_port_buf_size]; snprintf(host_port, host_port_buf_size, "%s:%d", FLAGS_server_host.c_str(), FLAGS_server_port); - grpc::testing::Http2Client client(grpc::CreateTestChannel(host_port, false)); + std::shared_ptr<grpc::Channel> channel = + grpc::CreateTestChannel(host_port, false); + GPR_ASSERT(channel->WaitForConnected(gpr_time_add( + gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(300, GPR_TIMESPAN)))); + grpc::testing::Http2Client client(channel); gpr_log(GPR_INFO, "Testing case: %s", FLAGS_test_case.c_str()); int ret = 0; if (FLAGS_test_case == "rst_after_header") { diff --git a/tools/dockerfile/interoptest/grpc_interop_cxx/build_interop.sh b/tools/dockerfile/interoptest/grpc_interop_cxx/build_interop.sh index 7a7ca0d3d1..0a61334103 100755 --- a/tools/dockerfile/interoptest/grpc_interop_cxx/build_interop.sh +++ b/tools/dockerfile/interoptest/grpc_interop_cxx/build_interop.sh @@ -47,3 +47,6 @@ make install-certs # build C++ interop client & server make interop_client interop_server + +# build C++ http2 client +make http2_client diff --git a/tools/run_tests/run_interop_tests.py b/tools/run_tests/run_interop_tests.py index d29bfa9b0c..0d5bec1d67 100755 --- a/tools/run_tests/run_interop_tests.py +++ b/tools/run_tests/run_interop_tests.py @@ -77,11 +77,15 @@ class CXXLanguage: def __init__(self): self.client_cwd = None self.server_cwd = None + self.http2_cwd = None self.safename = 'cxx' def client_cmd(self, args): return ['bins/opt/interop_client'] + args + def client_cmd_http2interop(self, args): + return ['bins/opt/http2_client'] + args + def cloud_to_prod_env(self): return {} @@ -474,7 +478,7 @@ _HTTP2_TEST_CASES = ['tls', 'framing'] _HTTP2_BADSERVER_TEST_CASES = ['rst_after_header', 'rst_after_data', 'rst_during_data', 'goaway', 'ping', 'max_streams'] -_LANGUAGES_FOR_HTTP2_BADSERVER_TESTS = ['java', 'go', 'python'] +_LANGUAGES_FOR_HTTP2_BADSERVER_TESTS = ['java', 'go', 'python', 'c++'] DOCKER_WORKDIR_ROOT = '/var/local/git/grpc' -- GitLab