optimal
This commit is contained in:
@@ -939,6 +939,120 @@ TEST(NavigationServerFeedback, NothingIsLatchedBeforeTheFirstRequest)
|
||||
<< "a freshly booted runtime reports a terminal result although no goal has ever been sent";
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
// executeInstantAction() — cửa duy nhất nhận một action lẻ
|
||||
//
|
||||
// Điểm cần khoá: hàm này KHÔNG có đường rơi xuống lõi như `moveTo(goal)` có. Một instantAction chỉ
|
||||
// có nghĩa sau khi mission layer nở nó theo bảng compound — `PickUp` mà đi thẳng xuống lõi sẽ thành
|
||||
// một chặng chỉ-action, tức robot báo "đã nâng kệ" trong khi càng còn chưa tới gần kệ.
|
||||
//
|
||||
// Fixture ở đây không dựng NavigationRuntime, nên nó mô phỏng đúng cấu hình có mission layer tắt.
|
||||
// ================================================================================================
|
||||
|
||||
namespace
|
||||
{
|
||||
robot_protocol_msgs::Action makeInstantAction(const std::string& type = "PickUp")
|
||||
{
|
||||
robot_protocol_msgs::Action action;
|
||||
action.actionType = type;
|
||||
action.actionId = type + "_1";
|
||||
action.blockingType = "HARD";
|
||||
return action;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST(NavigationServerInstantAction, IsRefusedWhenThereIsNoMissionLayer)
|
||||
{
|
||||
Fixture fixture;
|
||||
fixture.configure();
|
||||
|
||||
EXPECT_FALSE(fixture.server_.executeInstantActions({makeInstantAction()}))
|
||||
<< "nhận rồi không làm gì là fleet chờ tới hết giờ — nó đang chặn mọi lệnh khác để đợi";
|
||||
}
|
||||
|
||||
TEST(NavigationServerInstantAction, AnEmptyMessageIsRefused)
|
||||
{
|
||||
// Message rỗng không phải lệnh huỷ. Nhận nó thì host ngồi chờ một kết quả không bao giờ tới.
|
||||
Fixture fixture;
|
||||
fixture.configure();
|
||||
|
||||
EXPECT_FALSE(fixture.server_.executeInstantActions({}));
|
||||
}
|
||||
|
||||
TEST(NavigationServerInstantAction, AMultiActionMessageGoesDownAsOneCall)
|
||||
{
|
||||
// Chữ ký nhận CẢ danh sách chính là thứ ngăn action `HARD` thứ hai preempt chặng của action thứ
|
||||
// nhất trong cùng message. Test này khoá chữ ký đó lại: biên dịch được với nhiều action là đủ,
|
||||
// cộng với việc nó vẫn bị từ chối gọn gàng khi không có mission layer.
|
||||
Fixture fixture;
|
||||
fixture.configure();
|
||||
|
||||
const std::vector<robot_protocol_msgs::Action> message = {
|
||||
makeInstantAction("MutedOn"), makeInstantAction("PickUp"), makeInstantAction("MutedOff")
|
||||
};
|
||||
|
||||
EXPECT_FALSE(fixture.server_.executeInstantActions(message));
|
||||
EXPECT_EQ(0u, fixture.action_.startCount());
|
||||
}
|
||||
|
||||
TEST(NavigationServerInstantAction, ARefusalSaysWhichActionAndWhy)
|
||||
{
|
||||
Fixture fixture;
|
||||
fixture.configure();
|
||||
|
||||
ASSERT_FALSE(fixture.server_.executeInstantActions({makeInstantAction("charge")}));
|
||||
|
||||
// Host chép chuỗi này vào `resultDescription` gửi lên fleet. "rejected" trơ trọi không giúp được
|
||||
// ai; phải nói được là action NÀO và vì SAO.
|
||||
const std::string reason = fixture.server_.getFeedback()->feed_back_str;
|
||||
EXPECT_NE(reason.find("charge"), std::string::npos) << "reason: " << reason;
|
||||
EXPECT_NE(reason.find("instant action"), std::string::npos) << "reason: " << reason;
|
||||
}
|
||||
|
||||
TEST(NavigationServerInstantAction, ARefusedActionNeverReachesTheCore)
|
||||
{
|
||||
// Bất biến quan trọng nhất của hàm này: KHÔNG có nhánh fallback. `moveTo(goal)` có — layer tắt thì
|
||||
// nó submit thẳng, và đúng như vậy vì một goal đơn vẫn còn nguyên nghĩa. Một instantAction thì
|
||||
// không: bỏ qua bước nở là bỏ qua bước dò và bước tiến vào.
|
||||
Fixture fixture;
|
||||
fixture.configure();
|
||||
|
||||
ASSERT_FALSE(fixture.server_.executeInstantActions({makeInstantAction()}));
|
||||
fixture.spin(10);
|
||||
|
||||
EXPECT_EQ(0u, fixture.planner_.makePlanCount()) << "không được lập plan cho một action bị từ chối";
|
||||
EXPECT_EQ(0u, fixture.action_.startCount()) << "và không được chạy action nào";
|
||||
EXPECT_EQ(fixture.server_.getFeedback()->navigation_state,
|
||||
robot::move_base_core::State::PENDING)
|
||||
<< "lõi phải đứng yên — báo ACTIVE ở đây là fleet tưởng robot đang làm việc";
|
||||
}
|
||||
|
||||
TEST(NavigationServerInstantAction, RefusingDoesNotDisturbAGoalAlreadyRunning)
|
||||
{
|
||||
// Từ chối phải là no-op với việc đang chạy. Nếu nó đụng vào `pending_request_` hay cờ cancel thì
|
||||
// một action lạ do fleet gửi nhầm sẽ dừng cả tuyến đường đang đi.
|
||||
Fixture fixture;
|
||||
fixture.configure();
|
||||
|
||||
NavigationRequest request;
|
||||
request.profile = MotionProfile::kPosition;
|
||||
request.goal.header.frame_id = "map";
|
||||
request.goal.pose.position.x = 2.0; // [m]
|
||||
request.goal.pose.orientation.w = 1.0;
|
||||
ASSERT_TRUE(fixture.server_.moveTo(request.goal, 0.0, 0.0));
|
||||
|
||||
fixture.spin(5);
|
||||
const auto state_before = fixture.server_.getFeedback()->navigation_state;
|
||||
const std::size_t plans_before = fixture.planner_.makePlanCount();
|
||||
|
||||
EXPECT_FALSE(fixture.server_.executeInstantActions({makeInstantAction("NotSupported")}));
|
||||
fixture.spin(5);
|
||||
|
||||
EXPECT_EQ(fixture.server_.getFeedback()->navigation_state, state_before)
|
||||
<< "một action bị từ chối không được đổi trạng thái của goal đang chạy";
|
||||
EXPECT_GE(fixture.planner_.makePlanCount(), plans_before);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
Reference in New Issue
Block a user