diff options
author | Yang Gao <yangg@google.com> | 2015-03-17 15:45:33 -0700 |
---|---|---|
committer | Yang Gao <yangg@google.com> | 2015-03-17 15:45:33 -0700 |
commit | 700bdeb6f549ed79d586f962b8347b9a5275d5c8 (patch) | |
tree | 4812bfebcb980c4c7bbc8aec5418e5ec9e972de1 /test/cpp | |
parent | d9427202661411b975fcb22f338ed03503d9af6a (diff) | |
parent | 7aadf46fdb05b5f595440c41998023e69e1700e5 (diff) |
Merge pull request #1023 from vjpai/async
Non-blocking Next method for C++ async completion queue
Diffstat (limited to 'test/cpp')
-rw-r--r-- | test/cpp/end2end/async_end2end_test.cc | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc index 70df9e14b2..e011b788ff 100644 --- a/test/cpp/end2end/async_end2end_test.cc +++ b/test/cpp/end2end/async_end2end_test.cc @@ -76,6 +76,20 @@ void verify_ok(CompletionQueue* cq, int i, bool expect_ok) { EXPECT_EQ(tag(i), got_tag); } +void verify_timed_ok(CompletionQueue* cq, int i, bool expect_ok, + std::chrono::system_clock::time_point deadline = + std::chrono::system_clock::time_point::max(), + CompletionQueue::NextStatus expected_outcome = + CompletionQueue::GOT_EVENT) { + bool ok; + void* got_tag; + EXPECT_EQ(cq->AsyncNext(&got_tag, &ok, deadline), expected_outcome); + if (expected_outcome == CompletionQueue::GOT_EVENT) { + EXPECT_EQ(expect_ok, ok); + EXPECT_EQ(tag(i), got_tag); + } +} + class AsyncEnd2endTest : public ::testing::Test { protected: AsyncEnd2endTest() : service_(&srv_cq_) {} @@ -166,6 +180,50 @@ TEST_F(AsyncEnd2endTest, SequentialRpcs) { SendRpc(10); } +// Test a simple RPC using the async version of Next +TEST_F(AsyncEnd2endTest, AsyncNextRpc) { + ResetStub(); + + EchoRequest send_request; + EchoRequest recv_request; + EchoResponse send_response; + EchoResponse recv_response; + Status recv_status; + + ClientContext cli_ctx; + ServerContext srv_ctx; + grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx); + + send_request.set_message("Hello"); + std::unique_ptr<ClientAsyncResponseReader<EchoResponse> > + response_reader(stub_->AsyncEcho(&cli_ctx, send_request, + &cli_cq_, tag(1))); + + std::chrono::system_clock::time_point + time_now(std::chrono::system_clock::now()), + time_limit(std::chrono::system_clock::now()+std::chrono::seconds(5)); + verify_timed_ok(&srv_cq_, -1, true, time_now, CompletionQueue::TIMEOUT); + verify_timed_ok(&cli_cq_, -1, true, time_now, CompletionQueue::TIMEOUT); + + service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, &srv_cq_, + tag(2)); + + verify_timed_ok(&srv_cq_, 2, true, time_limit); + EXPECT_EQ(send_request.message(), recv_request.message()); + verify_timed_ok(&cli_cq_, 1, true, time_limit); + + send_response.set_message(recv_request.message()); + response_writer.Finish(send_response, Status::OK, tag(3)); + verify_timed_ok(&srv_cq_, 3, true); + + response_reader->Finish(&recv_response, &recv_status, tag(4)); + verify_timed_ok(&cli_cq_, 4, true); + + EXPECT_EQ(send_response.message(), recv_response.message()); + EXPECT_TRUE(recv_status.IsOk()); + +} + // Two pings and a final pong. TEST_F(AsyncEnd2endTest, SimpleClientStreaming) { ResetStub(); |