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
211915d2
Commit
211915d2
authored
Oct 30, 2018
by
zhujiashun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add invalid grpc timeout case to UT
parent
6881c5bf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
6 deletions
+18
-6
http_rpc_protocol.cpp
src/brpc/policy/http_rpc_protocol.cpp
+3
-3
brpc_grpc_protocol_unittest.cpp
test/brpc_grpc_protocol_unittest.cpp
+15
-3
No files found.
src/brpc/policy/http_rpc_protocol.cpp
View file @
211915d2
...
...
@@ -1454,16 +1454,16 @@ void ProcessHttpRequest(InputMessageBase *msg) {
char
*
endptr
=
NULL
;
int64_t
timeout_value
=
(
int64_t
)
strtol
(
grpc_timeout
->
data
(),
&
endptr
,
10
);
// Only the format that the digit number is equal to (timeout header size - 1) is valid.
// Otherwise the format is not valid and
the
is treated as no deadline.
// Otherwise the format is not valid and is treated as no deadline.
// For example:
// 1H, 2993S, 82m is valid.
// 30A is also valid, but the following ConvertGrpcTimeoutToUS would return -1 since 'A'
// is not a valid time unit.
// 123ASH is not vaid since the digit number is 3, while the size is 6.
// HHH is not valid since the dight number is 0, while the size is 3.
if
(
endptr
-
grpc_timeout
->
data
(
)
==
grpc_timeout
->
size
()
-
1
)
{
if
(
(
size_t
)(
endptr
-
grpc_timeout
->
data
()
)
==
grpc_timeout
->
size
()
-
1
)
{
int64_t
timeout_value_us
=
ConvertGrpcTimeoutToUS
(
timeout_unit
);
ConvertGrpcTimeoutToUS
(
timeout_value
,
timeout_unit
);
if
(
timeout_value_us
>=
0
)
{
accessor
.
set_deadline_us
(
butil
::
gettimeofday_us
()
+
timeout_value_us
);
...
...
test/brpc_grpc_protocol_unittest.cpp
View file @
211915d2
...
...
@@ -66,8 +66,12 @@ public:
return
;
}
if
(
req
->
has_timeout_us
())
{
EXPECT_NEAR
(
cntl
->
deadline_us
(),
butil
::
gettimeofday_us
()
+
req
->
timeout_us
(),
30
);
if
(
req
->
timeout_us
()
<
0
)
{
EXPECT_EQ
(
-
1
,
cntl
->
deadline_us
());
}
else
{
EXPECT_NEAR
(
cntl
->
deadline_us
(),
butil
::
gettimeofday_us
()
+
req
->
timeout_us
(),
30
);
}
}
}
...
...
@@ -204,12 +208,20 @@ TEST_F(GrpcTest, MethodNotExist) {
TEST_F
(
GrpcTest
,
GrpcTimeOut
)
{
const
char
*
timeouts
[]
=
{
// valid case
"2H"
,
"7200000000"
,
"3M"
,
"180000000"
,
"+1S"
,
"1000000"
,
"4m"
,
"4000"
,
"5u"
,
"5"
,
"6n"
,
"1"
"6n"
,
"1"
,
// invalid case
"30A"
,
"-1"
,
"123ASH"
,
"-1"
,
"HHHH"
,
"-1"
,
"112"
,
"-1"
,
"H999m"
,
"-1"
,
""
,
"-1"
};
for
(
size_t
i
=
0
;
i
<
arraysize
(
timeouts
);
i
=
i
+
2
)
{
...
...
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