Commit 71bbdc0f authored by zhujiashun's avatar zhujiashun

Fix stop_sleep ut in slow machine

parent 98654160
...@@ -170,7 +170,6 @@ int64_t ConvertGrpcTimeoutToUS(const std::string* grpc_timeout) { ...@@ -170,7 +170,6 @@ int64_t ConvertGrpcTimeoutToUS(const std::string* grpc_timeout) {
if (!grpc_timeout || grpc_timeout->empty()) { if (!grpc_timeout || grpc_timeout->empty()) {
return -1; return -1;
} }
const char timeout_unit = grpc_timeout->back();
char* endptr = NULL; char* endptr = NULL;
int64_t timeout_value = (int64_t)strtol(grpc_timeout->data(), &endptr, 10); 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) // Only the format that the digit number is equal to (timeout header size - 1)
...@@ -184,31 +183,24 @@ int64_t ConvertGrpcTimeoutToUS(const std::string* grpc_timeout) { ...@@ -184,31 +183,24 @@ int64_t ConvertGrpcTimeoutToUS(const std::string* grpc_timeout) {
if ((size_t)(endptr - grpc_timeout->data()) != grpc_timeout->size() - 1) { if ((size_t)(endptr - grpc_timeout->data()) != grpc_timeout->size() - 1) {
return -1; return -1;
} }
switch (timeout_unit) { switch (*endptr) {
case 'H': case 'H':
timeout_value *= (3600 * 1000000L); return timeout_value * 3600 * 1000000;
break;
case 'M': case 'M':
timeout_value *= (60 * 1000000L); return timeout_value * 60 * 1000000;
break;
case 'S': case 'S':
timeout_value *= 1000000L; return timeout_value * 1000000;
break;
case 'm': case 'm':
timeout_value *= 1000L; return timeout_value * 1000;
break;
case 'u': case 'u':
break; return timeout_value;
case 'n': case 'n':
timeout_value = (timeout_value + 500) / 1000; timeout_value = (timeout_value + 500) / 1000;
if (timeout_value == 0) { return (timeout_value == 0) ? 1 : timeout_value;
timeout_value = 1;
}
break;
default: default:
return -1; return -1;
} }
return timeout_value; LOG(FATAL) << "Impossible";
} }
} // namespace brpc } // namespace brpc
...@@ -407,7 +407,7 @@ TEST_F(BthreadTest, stop_sleep) { ...@@ -407,7 +407,7 @@ TEST_F(BthreadTest, stop_sleep) {
ASSERT_EQ(0, bthread_stop(th)); ASSERT_EQ(0, bthread_stop(th));
ASSERT_EQ(0, bthread_join(th, NULL)); ASSERT_EQ(0, bthread_join(th, NULL));
tm.stop(); tm.stop();
ASSERT_LE(labs(tm.m_elapsed() - 10), 5); ASSERT_LE(labs(tm.m_elapsed() - 10), 10);
} }
TEST_F(BthreadTest, bthread_exit) { TEST_F(BthreadTest, bthread_exit) {
......
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