diff options
author | Abhishek Kumar <abhikumar@google.com> | 2015-04-17 14:12:33 -0700 |
---|---|---|
committer | Abhishek Kumar <abhikumar@google.com> | 2015-04-17 14:12:33 -0700 |
commit | e41d0402ba727d5f89bdf39e90e406227cc23601 (patch) | |
tree | c14b38c6d16e6cf696905a02d511b909d3e96a99 /test/cpp/end2end | |
parent | 82a83313db78563e32aadfb457198c512749d3f3 (diff) |
Added end2end test for server streaming rpc cancellation.
Diffstat (limited to 'test/cpp/end2end')
-rw-r--r-- | test/cpp/end2end/end2end_test.cc | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index 9d61428d24..3193a2af58 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -491,6 +491,36 @@ TEST_F(End2endTest, ServerCancelsRpc) { EXPECT_TRUE(s.details().empty()); } +// Client cancels server stream after sending some messages + TEST_F(End2endTest, ClientCancelsResponseStream) { + ResetStub(); + EchoRequest request; + EchoResponse response; + ClientContext context; + request.set_message("hello"); + + auto stream = stub_->ResponseStream(&context, request); + + EXPECT_TRUE(stream->Read(&response)); + EXPECT_EQ(response.message(), request.message() + "0"); + EXPECT_TRUE(stream->Read(&response)); + EXPECT_EQ(response.message(), request.message() + "1"); + + context.TryCancel(); + + // The cancellation races with responses, so there might be zero or + // one responses pending, read till failure + + if (stream->Read(&response)) { + EXPECT_EQ(response.message(), request.message() + "2"); + // Since we have cancelled, we expect the next attempt to read to fail + EXPECT_FALSE(stream->Read(&response)); + } + + Status s = stream->Finish(); + EXPECT_EQ(grpc::StatusCode::CANCELLED, s.code()); +} + // Client cancels bidi stream after sending some messages TEST_F(End2endTest, ClientCancelsBidi) { ResetStub(); @@ -525,7 +555,6 @@ TEST_F(End2endTest, ClientCancelsBidi) { } - } // namespace testing } // namespace grpc |