Commit 9f166e85 authored by zyearn's avatar zyearn Committed by zhujiashun

Improve grpc UT

parent ef39fdd2
......@@ -63,7 +63,7 @@ GrpcStatus ErrorCode2GrpcStatus(int error_code) {
case ETIMEDOUT:
return GRPC_INTERNAL;
default:
return GRPC_UNKNOWN;
return GRPC_INTERNAL;
}
}
......
......@@ -47,9 +47,9 @@ const std::string g_protocol = "grpc";
class MyGrpcService : public ::test::GrpcService {
public:
void Method(::google::protobuf::RpcController* cntl_base,
const ::test::GrpcRequest* req,
::test::GrpcResponse* res,
::google::protobuf::Closure* done) {
const ::test::GrpcRequest* req,
::test::GrpcResponse* res,
::google::protobuf::Closure* done) {
brpc::Controller* cntl =
static_cast<brpc::Controller*>(cntl_base);
brpc::ClosureGuard done_guard(done);
......@@ -67,6 +67,15 @@ public:
return;
}
}
void MethodTimeOut(::google::protobuf::RpcController* cntl_base,
const ::test::GrpcRequest* req,
::test::GrpcResponse* res,
::google::protobuf::Closure* done) {
brpc::ClosureGuard done_guard(done);
bthread_usleep(6 * 1000000L);
return;
}
};
......@@ -158,4 +167,34 @@ TEST_F(GrpcTest, return_error) {
}
}
TEST_F(GrpcTest, RpcTimedOut) {
brpc::Channel channel;
brpc::ChannelOptions options;
options.protocol = g_protocol;
options.timeout_ms = g_timeout_ms;
EXPECT_EQ(0, channel.Init(g_server_addr.c_str(), "", &options));
test::GrpcRequest req;
test::GrpcResponse res;
brpc::Controller cntl;
req.set_message(g_req);
test::GrpcService_Stub stub(&_channel);
stub.MethodTimeOut(&cntl, &req, &res, NULL);
EXPECT_TRUE(cntl.Failed());
EXPECT_EQ(cntl.ErrorCode(), brpc::ERPCTIMEDOUT);
}
TEST_F(GrpcTest, MethodNotExist) {
test::GrpcRequest req;
test::GrpcResponse res;
brpc::Controller cntl;
req.set_message(g_req);
test::GrpcService_Stub stub(&_channel);
stub.MethodNotExist(&cntl, &req, &res, NULL);
EXPECT_TRUE(cntl.Failed());
EXPECT_EQ(cntl.ErrorCode(), brpc::EGRPC);
EXPECT_EQ((int)cntl.grpc_status(), brpc::GRPC_INTERNAL);
ASSERT_TRUE(butil::StringPiece(cntl.grpc_message()).ends_with("Method MethodNotExist() not implemented."));
}
} // namespace
......@@ -15,4 +15,8 @@ message GrpcResponse {
service GrpcService {
rpc Method(GrpcRequest) returns (GrpcResponse);
rpc MethodTimeOut(GrpcRequest) returns (GrpcResponse);
rpc MethodNotExist(GrpcRequest) returns (GrpcResponse);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment