From bb84a30f07518dca4ebd772415e43e0346e552db Mon Sep 17 00:00:00 2001 From: Yang Gao Date: Thu, 12 Feb 2015 23:30:12 -0800 Subject: [PATCH] let the client/server use their own cq and pretty the test --- test/cpp/end2end/async_end2end_test.cc | 38 ++++++++++++-------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc index 52fb80e8db3..25f8111ca80 100644 --- a/test/cpp/end2end/async_end2end_test.cc +++ b/test/cpp/end2end/async_end2end_test.cc @@ -66,7 +66,7 @@ namespace { class End2endTest : public ::testing::Test { protected: - End2endTest() : service_(&cq_) {} + End2endTest() : service_(&srv_cq_) {} void SetUp() override { int port = grpc_pick_unused_port_or_die(); @@ -86,7 +86,8 @@ class End2endTest : public ::testing::Test { stub_.reset(grpc::cpp::test::util::TestService::NewStub(channel)); } - CompletionQueue cq_; + CompletionQueue cli_cq_; + CompletionQueue srv_cq_; std::unique_ptr stub_; std::unique_ptr server_; grpc::cpp::test::util::TestService::AsyncService service_; @@ -99,7 +100,7 @@ void* tag(int i) { TEST_F(End2endTest, SimpleRpc) { ResetStub(); - + EchoRequest send_request; EchoRequest recv_request; EchoResponse send_response; @@ -110,34 +111,31 @@ TEST_F(End2endTest, SimpleRpc) { grpc::ServerAsyncResponseWriter response_writer(&srv_ctx); send_request.set_message("Hello"); - stub_->Echo(&cli_ctx, send_request, &recv_response, &recv_status, &cq_, tag(1)); + stub_->Echo( + &cli_ctx, send_request, &recv_response, &recv_status, &cli_cq_, tag(1)); - service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, &cq_, tag(2)); + service_.RequestEcho( + &srv_ctx, &recv_request, &response_writer, &srv_cq_, tag(2)); void *got_tag; bool ok; - EXPECT_TRUE(cq_.Next(&got_tag, &ok)); + EXPECT_TRUE(srv_cq_.Next(&got_tag, &ok)); EXPECT_TRUE(ok); - EXPECT_EQ(got_tag, tag(2)); - EXPECT_EQ(recv_request.message(), "Hello"); + EXPECT_EQ(tag(2), got_tag); + EXPECT_EQ(send_request.message(), recv_request.message()); send_response.set_message(recv_request.message()); response_writer.Finish(send_response, Status::OK, tag(3)); - EXPECT_TRUE(cq_.Next(&got_tag, &ok)); + EXPECT_TRUE(srv_cq_.Next(&got_tag, &ok)); EXPECT_TRUE(ok); - if (got_tag == tag(3)) { - EXPECT_TRUE(cq_.Next(&got_tag, &ok)); - EXPECT_TRUE(ok); - EXPECT_EQ(got_tag, tag(1)); - } else { - EXPECT_EQ(got_tag, tag(1)); - EXPECT_TRUE(cq_.Next(&got_tag, &ok)); - EXPECT_TRUE(ok); - EXPECT_EQ(got_tag, tag(3)); - } + EXPECT_EQ(tag(3), got_tag); + + EXPECT_TRUE(cli_cq_.Next(&got_tag, &ok)); + EXPECT_TRUE(ok); + EXPECT_EQ(tag(1), got_tag); - EXPECT_EQ(recv_response.message(), "Hello"); + EXPECT_EQ(send_response.message(), recv_response.message()); EXPECT_TRUE(recv_status.IsOk()); }