diff options
author | Abhishek Kumar <abhikumar@google.com> | 2015-04-17 13:30:51 -0700 |
---|---|---|
committer | Abhishek Kumar <abhikumar@google.com> | 2015-04-17 13:30:51 -0700 |
commit | 82a83313db78563e32aadfb457198c512749d3f3 (patch) | |
tree | 579a7ec3fb0d95cccca61f787d8b84b3aae74b71 /test | |
parent | 4f558f536c1bfe523e0dd0250420785d54dcc326 (diff) |
Added test case demonstrating cancel on bidi stream
Diffstat (limited to 'test')
-rw-r--r-- | test/cpp/end2end/end2end_test.cc | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index f96051cafa..9d61428d24 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -491,6 +491,41 @@ TEST_F(End2endTest, ServerCancelsRpc) { EXPECT_TRUE(s.details().empty()); } +// Client cancels bidi stream after sending some messages +TEST_F(End2endTest, ClientCancelsBidi) { + ResetStub(); + EchoRequest request; + EchoResponse response; + ClientContext context; + grpc::string msg("hello"); + + auto stream = stub_->BidiStream(&context); + + request.set_message(msg + "0"); + EXPECT_TRUE(stream->Write(request)); + EXPECT_TRUE(stream->Read(&response)); + EXPECT_EQ(response.message(), request.message()); + + request.set_message(msg + "1"); + EXPECT_TRUE(stream->Write(request)); + + 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()); + // 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()); +} + + + } // namespace testing } // namespace grpc |