diff options
author | Eric Gribkoff <ericgribkoff@google.com> | 2017-03-01 08:15:25 -0800 |
---|---|---|
committer | Eric Gribkoff <ericgribkoff@google.com> | 2017-03-01 22:22:38 -0800 |
commit | caf7ea53be2f93c310acbaddbe3da90ccc7e6411 (patch) | |
tree | 4687c28b4a44aeb33cda4ab0c9a81fd661779438 /test | |
parent | aa5e7600ec3d10993ec9a19287a98fd8d026c16c (diff) |
Enable C++ negative http2 test
Diffstat (limited to 'test')
-rw-r--r-- | test/cpp/interop/http2_client.cc | 49 |
1 files changed, 31 insertions, 18 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") { |