expose error handling for state changes (#344)

* remove fprintf, use logging

* expose lifecycle error code

* address comments
This commit is contained in:
Karsten Knese 2017-07-27 07:55:15 -07:00 committed by GitHub
parent 40b09b5b14
commit 0c26dd99b6
5 changed files with 160 additions and 31 deletions

View file

@ -69,6 +69,15 @@ TEST_F(TestCallbackExceptions, positive_on_error) {
EXPECT_EQ(static_cast<size_t>(2), test_node->number_of_callbacks);
}
TEST_F(TestCallbackExceptions, positive_on_error_with_code) {
auto test_node = std::make_shared<PositiveCallbackExceptionNode>("testnode");
EXPECT_EQ(State::PRIMARY_STATE_UNCONFIGURED, test_node->get_current_state().id());
rcl_lifecycle_ret_t ret = RCL_LIFECYCLE_RET_OK;
test_node->configure(ret);
EXPECT_EQ(RCL_LIFECYCLE_RET_ERROR, ret);
}
class NegativeCallbackExceptionNode : public rclcpp_lifecycle::LifecycleNode
{
public:
@ -91,6 +100,7 @@ protected:
return RCL_LIFECYCLE_RET_FAILURE;
}
};
TEST_F(TestCallbackExceptions, negative_on_error) {
auto test_node = std::make_shared<NegativeCallbackExceptionNode>("testnode");
@ -100,3 +110,12 @@ TEST_F(TestCallbackExceptions, negative_on_error) {
// check if all callbacks were successfully overwritten
EXPECT_EQ(static_cast<size_t>(2), test_node->number_of_callbacks);
}
TEST_F(TestCallbackExceptions, negative_on_error_with_code) {
auto test_node = std::make_shared<NegativeCallbackExceptionNode>("testnode");
EXPECT_EQ(State::PRIMARY_STATE_UNCONFIGURED, test_node->get_current_state().id());
rcl_lifecycle_ret_t ret = RCL_RET_OK;
test_node->configure(ret);
EXPECT_EQ(RCL_LIFECYCLE_RET_ERROR, ret);
}

View file

@ -35,10 +35,6 @@ struct BadMood
{
static constexpr rcl_lifecycle_ret_t cb_ret = RCL_LIFECYCLE_RET_FAILURE;
};
struct VeryBadMood
{
static constexpr rcl_lifecycle_ret_t cb_ret = RCL_LIFECYCLE_RET_ERROR;
};
class TestDefaultStateMachine : public ::testing::Test
{
@ -144,6 +140,30 @@ TEST_F(TestDefaultStateMachine, trigger_transition) {
rclcpp_lifecycle::Transition(Transition::TRANSITION_SHUTDOWN)).id());
}
TEST_F(TestDefaultStateMachine, trigger_transition_with_error_code) {
auto test_node = std::make_shared<EmptyLifecycleNode>("testnode");
rcl_lifecycle_ret_t ret = RCL_LIFECYCLE_RET_ERROR;
test_node->configure(ret);
EXPECT_EQ(RCL_LIFECYCLE_RET_OK, ret);
ret = RCL_LIFECYCLE_RET_ERROR;
test_node->activate(ret);
EXPECT_EQ(RCL_LIFECYCLE_RET_OK, ret);
ret = RCL_LIFECYCLE_RET_ERROR;
test_node->deactivate(ret);
EXPECT_EQ(RCL_LIFECYCLE_RET_OK, ret);
ret = RCL_LIFECYCLE_RET_ERROR;
test_node->cleanup(ret);
EXPECT_EQ(RCL_LIFECYCLE_RET_OK, ret);
ret = RCL_LIFECYCLE_RET_ERROR;
test_node->shutdown(ret);
EXPECT_EQ(RCL_LIFECYCLE_RET_OK, ret);
}
TEST_F(TestDefaultStateMachine, good_mood) {
auto test_node = std::make_shared<MoodyLifecycleNode<GoodMood>>("testnode");