Commit dbde032d authored by zhujiashun's avatar zhujiashun

redis_server_protocol: enhance redis ut

parent cb3460be
...@@ -564,17 +564,27 @@ TEST_F(RedisTest, command_parser) { ...@@ -564,17 +564,27 @@ TEST_F(RedisTest, command_parser) {
ASSERT_STREQ(command.c_str(), command_out.c_str()); ASSERT_STREQ(command.c_str(), command_out.c_str());
} }
{ {
// parse from two consecutive buf // simulate parsing from network
buf.append("*3\r\n$3"); int t = 100;
ASSERT_EQ(brpc::PARSE_ERROR_NOT_ENOUGH_DATA, std::string raw_string("*3\r\n$3\r\nset\r\n$3\r\nabc\r\n$3\r\ndef\r\n");
parser.Parse(buf)); int size = raw_string.size();
ASSERT_EQ((int)buf.size(), 2); // left "$3" while (t--) {
buf.append("\r\nset\r\n$3\r\nabc\r\n$3\r\ndef\r\n"); for (int i = 0; i < size; ++i) {
ASSERT_EQ(brpc::PARSE_OK, parser.Parse(buf)); buf.push_back(raw_string[i]);
ASSERT_TRUE(buf.empty()); if (i == size - 1) {
std::string command_out; ASSERT_EQ(brpc::PARSE_OK, parser.Parse(buf));
parser.SwapCommandTo(&command_out); } else {
ASSERT_STREQ(command_out.c_str(), "set abc def"); 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 // there is a non-string message in command and parse should fail
......
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