[CP] [bugfix] fix the bug that the task be scheduled after being canceled

This commit is contained in:
obdev
2024-07-09 14:59:57 +00:00
committed by ob-robot
parent 1c005383a2
commit 301b1128d6
3 changed files with 33 additions and 0 deletions

View File

@ -184,6 +184,26 @@ TEST(TestCancelTask, reschedule_self_and_cancel)
timer.destroy();
}
// case6: cancel-->wait_task
TEST(TestCancelTask, cancel_and_wait_task)
{
ObTimer timer;
ASSERT_EQ(OB_SUCCESS, timer.init());
ASSERT_TRUE(timer.inited());
ASSERT_EQ(OB_SUCCESS, timer.start());
TaskCommon task;
task.exec_time_ = 10000; // 10ms
ASSERT_EQ(OB_SUCCESS, timer.schedule(task, 500000, true)); // 500ms true
::usleep(800000); // 800ms
ASSERT_EQ(1, task.task_run_count_);
timer.cancel_task(task);
timer.wait_task(task);
::usleep(1000000); // 1s
ASSERT_EQ(1, task.task_run_count_);
timer.destroy();
}
} // end namespace common
} // end namespace oceanbase