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
dbde032d
Commit
dbde032d
authored
Dec 11, 2019
by
zhujiashun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
redis_server_protocol: enhance redis ut
parent
cb3460be
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
11 deletions
+21
-11
brpc_redis_unittest.cpp
test/brpc_redis_unittest.cpp
+21
-11
No files found.
test/brpc_redis_unittest.cpp
View file @
dbde032d
...
...
@@ -564,17 +564,27 @@ TEST_F(RedisTest, command_parser) {
ASSERT_STREQ
(
command
.
c_str
(),
command_out
.
c_str
());
}
{
// parse from two consecutive buf
buf
.
append
(
"*3
\r\n
$3"
);
ASSERT_EQ
(
brpc
::
PARSE_ERROR_NOT_ENOUGH_DATA
,
parser
.
Parse
(
buf
));
ASSERT_EQ
((
int
)
buf
.
size
(),
2
);
// left "$3"
buf
.
append
(
"
\r\n
set
\r\n
$3
\r\n
abc
\r\n
$3
\r\n
def
\r\n
"
);
ASSERT_EQ
(
brpc
::
PARSE_OK
,
parser
.
Parse
(
buf
));
ASSERT_TRUE
(
buf
.
empty
());
std
::
string
command_out
;
parser
.
SwapCommandTo
(
&
command_out
);
ASSERT_STREQ
(
command_out
.
c_str
(),
"set abc def"
);
// simulate parsing from network
int
t
=
100
;
std
::
string
raw_string
(
"*3
\r\n
$3
\r\n
set
\r\n
$3
\r\n
abc
\r\n
$3
\r\n
def
\r\n
"
);
int
size
=
raw_string
.
size
();
while
(
t
--
)
{
for
(
int
i
=
0
;
i
<
size
;
++
i
)
{
buf
.
push_back
(
raw_string
[
i
]);
if
(
i
==
size
-
1
)
{
ASSERT_EQ
(
brpc
::
PARSE_OK
,
parser
.
Parse
(
buf
));
}
else
{
if
(
butil
::
fast_rand_less_than
(
2
)
==
0
)
{
ASSERT_EQ
(
brpc
::
PARSE_ERROR_NOT_ENOUGH_DATA
,
parser
.
Parse
(
buf
));
}
}
}
ASSERT_TRUE
(
buf
.
empty
());
std
::
string
command_out
;
parser
.
SwapCommandTo
(
&
command_out
);
ASSERT_STREQ
(
command_out
.
c_str
(),
"set abc def"
);
}
}
{
// there is a non-string message in command and parse should fail
...
...
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