Commit 211915d2 authored by zhujiashun's avatar zhujiashun

add invalid grpc timeout case to UT

parent 6881c5bf
......@@ -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);
......
......@@ -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) {
......
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