Skip to content

Commit ec69724

Browse files
committed
[test] preempt stages for early stop
1 parent 7631486 commit ec69724

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

core/test/test_container.cpp

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -674,21 +674,20 @@ TEST(Task, timeout) {
674674
}
675675

676676
// https://github.com/moveit/moveit_task_constructor/pull/597
677+
// https://github.com/moveit/moveit_task_constructor/pull/598
677678
// start planning in another thread, then preempt it in this thread
678-
TEST(Task, preempt) {
679+
TEST_F(TaskTestBase, preempt) {
679680
moveit::core::MoveItErrorCode ec;
680681
resetMockupIds();
681682

682-
Task t;
683-
t.setRobotModel(getModel());
684-
685683
auto timeout = std::chrono::milliseconds(10);
686-
t.add(std::make_unique<GeneratorMockup>(PredefinedCosts::constant(0.0)));
687-
t.add(std::make_unique<TimedForwardMockup>(timeout));
684+
auto gen1 = add(t, new GeneratorMockup(PredefinedCosts::constant(0.0)));
685+
auto fwd1 = add(t, new TimedForwardMockup(timeout));
686+
auto fwd2 = add(t, new TimedForwardMockup(timeout));
688687

689688
// preempt before preempt_request_ is reset in plan()
690689
{
691-
std::thread thread{ [&ec, &t, timeout] {
690+
std::thread thread{ [&ec, this, timeout] {
692691
std::this_thread::sleep_for(timeout);
693692
ec = t.plan(1);
694693
} };
@@ -698,5 +697,30 @@ TEST(Task, preempt) {
698697

699698
EXPECT_EQ(ec, moveit::core::MoveItErrorCode::PREEMPTED);
700699
EXPECT_EQ(t.solutions().size(), 0u);
700+
EXPECT_EQ(gen1->runs_, 0u);
701+
EXPECT_EQ(fwd1->runs_, 0u);
702+
EXPECT_EQ(fwd2->runs_, 0u);
703+
EXPECT_TRUE(t.plan(1)); // make sure the preempt request has been resetted on the previous call to plan()
704+
705+
// prempt in between stage computation
706+
// Failing stage(s):
707+
// 0 - ← 0 → - 0 / task pipeline
708+
// 1 - ← 1 → - 0 / GEN1
709+
// - 0 → 1 → - 1 / FWD1
710+
// - 1 → 0 → - 0 / FWD2
711+
t.reset();
712+
resetMockupIds();
713+
{
714+
std::thread thread{ [&ec, this] { ec = t.plan(1); } };
715+
std::this_thread::sleep_for(timeout);
716+
t.preempt();
717+
thread.join();
718+
}
719+
720+
EXPECT_EQ(ec, moveit::core::MoveItErrorCode::PREEMPTED);
721+
EXPECT_EQ(t.solutions().size(), 0u);
722+
EXPECT_EQ(gen1->runs_, 2u);
723+
EXPECT_EQ(fwd1->runs_, 2u);
724+
EXPECT_EQ(fwd2->runs_, 1u);
701725
EXPECT_TRUE(t.plan(1)); // make sure the preempt request has been resetted on the previous call to plan()
702726
}

0 commit comments

Comments
 (0)