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
0f9d7878
Commit
0f9d7878
authored
Oct 31, 2018
by
zhujiashun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support grpc client setting timeout in cntl or channel
parent
211915d2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
1 deletion
+35
-1
http_rpc_protocol.cpp
src/brpc/policy/http_rpc_protocol.cpp
+4
-1
brpc_grpc_protocol_unittest.cpp
test/brpc_grpc_protocol_unittest.cpp
+31
-0
No files found.
src/brpc/policy/http_rpc_protocol.cpp
View file @
0f9d7878
...
...
@@ -576,7 +576,10 @@ void SerializeHttpRequest(butil::IOBuf* /*not used*/,
*/
// TODO: do we need this?
hreq
.
SetHeader
(
common
->
TE
,
common
->
TRAILERS
);
if
(
cntl
->
timeout_ms
()
>=
0
)
{
hreq
.
SetHeader
(
common
->
GRPC_TIMEOUT
,
butil
::
string_printf
(
"%ldm"
,
cntl
->
timeout_ms
()));
}
// Append compressed and length before body
AddGrpcPrefix
(
&
cntl
->
request_attachment
(),
grpc_compressed
);
}
...
...
test/brpc_grpc_protocol_unittest.cpp
View file @
0f9d7878
...
...
@@ -224,6 +224,7 @@ TEST_F(GrpcTest, GrpcTimeOut) {
""
,
"-1"
};
// test all timeout format
for
(
size_t
i
=
0
;
i
<
arraysize
(
timeouts
);
i
=
i
+
2
)
{
test
::
GrpcRequest
req
;
test
::
GrpcResponse
res
;
...
...
@@ -232,11 +233,41 @@ TEST_F(GrpcTest, GrpcTimeOut) {
req
.
set_gzip
(
false
);
req
.
set_return_error
(
false
);
req
.
set_timeout_us
((
int64_t
)(
strtol
(
timeouts
[
i
+
1
],
NULL
,
10
)));
cntl
.
set_timeout_ms
(
-
1
);
cntl
.
http_request
().
SetHeader
(
"grpc-timeout"
,
timeouts
[
i
]);
test
::
GrpcService_Stub
stub
(
&
_channel
);
stub
.
Method
(
&
cntl
,
&
req
,
&
res
,
NULL
);
EXPECT_FALSE
(
cntl
.
Failed
());
}
// test timeout by using timeout_ms in cntl
{
test
::
GrpcRequest
req
;
test
::
GrpcResponse
res
;
brpc
::
Controller
cntl
;
req
.
set_message
(
g_req
);
req
.
set_gzip
(
false
);
req
.
set_return_error
(
false
);
req
.
set_timeout_us
(
9876000
);
cntl
.
set_timeout_ms
(
9876
);
test
::
GrpcService_Stub
stub
(
&
_channel
);
stub
.
Method
(
&
cntl
,
&
req
,
&
res
,
NULL
);
EXPECT_FALSE
(
cntl
.
Failed
());
}
// test timeout by using timeout_ms in channel
{
test
::
GrpcRequest
req
;
test
::
GrpcResponse
res
;
brpc
::
Controller
cntl
;
req
.
set_message
(
g_req
);
req
.
set_gzip
(
false
);
req
.
set_return_error
(
false
);
req
.
set_timeout_us
(
g_timeout_ms
*
1000
);
test
::
GrpcService_Stub
stub
(
&
_channel
);
stub
.
Method
(
&
cntl
,
&
req
,
&
res
,
NULL
);
EXPECT_FALSE
(
cntl
.
Failed
());
}
}
}
// namespace
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