[bugfix] Compatible with old error code
This commit is contained in:
parent
c453c065e6
commit
c36cf095e6
28
deps/oblib/src/lib/task/ob_timer.cpp
vendored
28
deps/oblib/src/lib/task/ob_timer.cpp
vendored
@ -137,15 +137,15 @@ int ObTimer::schedule(ObTimerTask &task, const int64_t delay, const bool repeate
|
||||
int ret = OB_SUCCESS;
|
||||
if (!is_inited_) {
|
||||
ret = OB_NOT_INIT;
|
||||
OB_LOG(WARN, "timer is not yet initialized", K(ret));
|
||||
OB_LOG(WARN, "timer is not yet initialized", K(ret), K(task));
|
||||
} else if (is_stopped_) {
|
||||
ret = OB_NOT_RUNNING;
|
||||
OB_LOG(WARN, "timer has been stopped", K(ret));
|
||||
ret = OB_CANCELED;
|
||||
OB_LOG(WARN, "schedule task on stopped timer", K(ret), K(task));
|
||||
} else if (nullptr == timer_service_) {
|
||||
ret = OB_ERR_NULL_VALUE;
|
||||
OB_LOG(WARN, "timer_service is NULL", K(ret));
|
||||
OB_LOG(WARN, "timer_service is NULL", K(ret), K(task));
|
||||
} else if (OB_FAIL(timer_service_->schedule_task(this, task, delay, repeate, immediate))) {
|
||||
OB_LOG(WARN, "timer_service_.schedule_task failed", K(ret));
|
||||
OB_LOG(WARN, "timer_service_.schedule_task failed", K(ret), K(task));
|
||||
} else {}
|
||||
return ret;
|
||||
}
|
||||
@ -160,12 +160,12 @@ int ObTimer::cancel_task(const ObTimerTask &task)
|
||||
int ret = OB_SUCCESS;
|
||||
if (!is_inited_) {
|
||||
ret = OB_NOT_INIT;
|
||||
OB_LOG(WARN, "timer is not yet initialized", K(ret));
|
||||
OB_LOG(WARN, "timer is not yet initialized", K(ret), K(task));
|
||||
} else if (nullptr == timer_service_) {
|
||||
ret = OB_ERR_NULL_VALUE;
|
||||
OB_LOG(WARN, "timer_service is NULL", K(ret));
|
||||
OB_LOG(WARN, "timer_service is NULL", K(ret), K(task));
|
||||
} else if (OB_FAIL(timer_service_->cancel_task(this, &task))) {
|
||||
OB_LOG(WARN, "timer_service_.cancel_task failed", K(ret));
|
||||
OB_LOG(WARN, "timer_service_.cancel_task failed", K(ret), K(task));
|
||||
} else {}
|
||||
return ret;
|
||||
}
|
||||
@ -177,12 +177,12 @@ int ObTimer::wait_task(const ObTimerTask &task)
|
||||
|
||||
if (!is_inited_) {
|
||||
ret = OB_NOT_INIT;
|
||||
OB_LOG(WARN, "timer is not yet initialized", K(ret));
|
||||
OB_LOG(WARN, "timer is not yet initialized", K(ret), K(task));
|
||||
} else if (nullptr == timer_service_) {
|
||||
ret = OB_ERR_NULL_VALUE;
|
||||
OB_LOG(WARN, "timer_service is NULL", K(ret));
|
||||
OB_LOG(WARN, "timer_service is NULL", K(ret), K(task));
|
||||
} else if (OB_FAIL(timer_service_->wait_task(this, &task))) {
|
||||
OB_LOG(WARN, "timer_service_.wait_task failed", K(ret));
|
||||
OB_LOG(WARN, "timer_service_.wait_task failed", K(ret), K(task));
|
||||
} else {}
|
||||
return ret;
|
||||
}
|
||||
@ -192,12 +192,12 @@ int ObTimer::cancel(const ObTimerTask &task)
|
||||
int ret = OB_SUCCESS;
|
||||
if (!is_inited_) {
|
||||
ret = OB_NOT_INIT;
|
||||
OB_LOG(WARN, "timer is not yet initialized", K(ret));
|
||||
OB_LOG(WARN, "timer is not yet initialized", K(ret), K(task));
|
||||
} else if (nullptr == timer_service_) {
|
||||
ret = OB_ERR_NULL_VALUE;
|
||||
OB_LOG(WARN, "timer_service is NULL", K(ret));
|
||||
OB_LOG(WARN, "timer_service is NULL", K(ret), K(task));
|
||||
} else if (OB_FAIL(timer_service_->cancel_task(this, &task))) {
|
||||
OB_LOG(WARN, "timer_service_.cancel_task failed", K(ret));
|
||||
OB_LOG(WARN, "timer_service_.cancel_task failed", K(ret), K(task));
|
||||
} else {}
|
||||
return ret;
|
||||
}
|
||||
|
44
deps/oblib/unittest/lib/task/test_timer.cpp
vendored
44
deps/oblib/unittest/lib/task/test_timer.cpp
vendored
@ -221,6 +221,50 @@ TEST_F(TestTimer, task_service_stop)
|
||||
ASSERT_EQ(0, task2.task_run_count_);
|
||||
}
|
||||
|
||||
TEST_F(TestTimer, task_run1_wait)
|
||||
{
|
||||
TestTimerTask task1;
|
||||
TestTimerTask task2;
|
||||
TestTimerTask task3;
|
||||
task1.exec_time_ = 1000000; // 1s
|
||||
task2.exec_time_ = 10000; // 10ms
|
||||
task3.exec_time_ = 10000; // 10ms
|
||||
ObTimer timer1;
|
||||
ObTimer timer2;
|
||||
ASSERT_EQ(OB_SUCCESS, timer1.init());
|
||||
ASSERT_EQ(OB_SUCCESS, timer1.start());
|
||||
ASSERT_EQ(OB_SUCCESS, timer2.init());
|
||||
ASSERT_EQ(OB_SUCCESS, timer2.start());
|
||||
ASSERT_EQ(OB_SUCCESS, timer1.schedule(task1, 0, false, false));
|
||||
ASSERT_EQ(OB_SUCCESS, timer1.schedule(task2, 50000, false, false));
|
||||
ASSERT_EQ(OB_SUCCESS, timer2.schedule(task3, 200000, false, false)); // delay 200ms
|
||||
usleep(400000); // 400ms
|
||||
ASSERT_EQ(1, task3.task_run_count_); // ensure that task2 is not delayed by task1
|
||||
timer1.cancel_all();
|
||||
timer1.stop();
|
||||
timer1.wait();
|
||||
timer1.destroy();
|
||||
timer2.stop();
|
||||
timer2.wait();
|
||||
timer2.destroy();
|
||||
}
|
||||
|
||||
TEST_F(TestTimer, schedule_after_stop)
|
||||
{
|
||||
ObTimer timer;
|
||||
TestTimerTask task;
|
||||
task.exec_time_ = 10000; // 10ms
|
||||
ASSERT_EQ(OB_SUCCESS, timer.init());
|
||||
ASSERT_EQ(OB_SUCCESS, timer.start());
|
||||
ASSERT_EQ(OB_SUCCESS, timer.schedule(task, 0, false, false));
|
||||
usleep(100000); // 100ms
|
||||
ASSERT_EQ(1, task.task_run_count_);
|
||||
timer.stop();
|
||||
ASSERT_EQ(OB_CANCELED, timer.schedule(task, 0, false, false));
|
||||
timer.wait();
|
||||
timer.destroy();
|
||||
}
|
||||
|
||||
} // end namespace common
|
||||
} // end namespace oceanbase
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user