From 0b6ad7d4bc686c78995a830cccb39a7de2a929ae Mon Sep 17 00:00:00 2001 From: yang-g Date: Thu, 25 Jun 2015 14:39:01 -0700 Subject: Bug fix. Do not push to incoming_queue after it is flushed. --- test/cpp/end2end/end2end_test.cc | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'test/cpp/end2end') diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index 45ba8b0878..5e850ea30a 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -68,6 +68,8 @@ namespace testing { namespace { +const char* kServerCancelAfterReads = "cancel_after_reads"; + // When echo_deadline is requested, deadline seen in the ServerContext is set in // the response in seconds. void MaybeEchoDeadline(ServerContext* context, const EchoRequest* request, @@ -131,7 +133,23 @@ class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service { EchoResponse* response) GRPC_OVERRIDE { EchoRequest request; response->set_message(""); + int cancel_after_reads = 0; + const std::multimap client_initial_metadata = + context->client_metadata(); + if (client_initial_metadata.find(kServerCancelAfterReads) != + client_initial_metadata.end()) { + std::istringstream iss( + client_initial_metadata.find(kServerCancelAfterReads)->second); + iss >> cancel_after_reads; + gpr_log(GPR_INFO, "cancel_after_reads %d", cancel_after_reads); + } while (reader->Read(&request)) { + if (cancel_after_reads == 1) { + gpr_log(GPR_INFO, "return cancel status"); + return Status::CANCELLED; + } else if (cancel_after_reads > 0) { + cancel_after_reads--; + } response->mutable_message()->append(request.message()); } return Status::OK; @@ -687,6 +705,27 @@ TEST_F(End2endTest, OverridePerCallCredentials) { EXPECT_TRUE(s.ok()); } +// Client sends 20 requests and the server returns CANCELLED status after +// reading 10 requests. +TEST_F(End2endTest, RequestStreamServerEarlyCancelTest) { + ResetStub(); + EchoRequest request; + EchoResponse response; + ClientContext context; + + context.AddMetadata(kServerCancelAfterReads, "10"); + auto stream = stub_->RequestStream(&context, &response); + request.set_message("hello"); + int send_messages = 20; + while (send_messages > 0) { + EXPECT_TRUE(stream->Write(request)); + send_messages--; + } + stream->WritesDone(); + Status s = stream->Finish(); + EXPECT_EQ(s.error_code(), StatusCode::CANCELLED); +} + } // namespace testing } // namespace grpc -- cgit v1.2.3