Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
9f166e85
Commit
9f166e85
authored
Sep 07, 2018
by
zyearn
Committed by
zhujiashun
Sep 27, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve grpc UT
parent
ef39fdd2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
4 deletions
+47
-4
grpc.cpp
src/brpc/grpc.cpp
+1
-1
brpc_grpc_protocol_unittest.cpp
test/brpc_grpc_protocol_unittest.cpp
+42
-3
grpc.proto
test/grpc.proto
+4
-0
No files found.
src/brpc/grpc.cpp
View file @
9f166e85
...
...
@@ -63,7 +63,7 @@ GrpcStatus ErrorCode2GrpcStatus(int error_code) {
case
ETIMEDOUT
:
return
GRPC_INTERNAL
;
default
:
return
GRPC_
UNKNOWN
;
return
GRPC_
INTERNAL
;
}
}
...
...
test/brpc_grpc_protocol_unittest.cpp
View file @
9f166e85
...
...
@@ -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
test/grpc.proto
View file @
9f166e85
...
...
@@ -15,4 +15,8 @@ message GrpcResponse {
service
GrpcService
{
rpc
Method
(
GrpcRequest
)
returns
(
GrpcResponse
);
rpc
MethodTimeOut
(
GrpcRequest
)
returns
(
GrpcResponse
);
rpc
MethodNotExist
(
GrpcRequest
)
returns
(
GrpcResponse
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment