Skip to content

Commit 4ca2a36

Browse files
committed
Test the two remaining shutdown transitions. Correct error handling when shutdown transition is not possible
Signed-off-by: Ivan Santiago Paunovic <[email protected]>
1 parent c31b4f6 commit 4ca2a36

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

rclpy/rclpy/lifecycle/node.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ def trigger_shutdown(self):
163163
lifecycle_msgs.msg.Transition.TRANSITION_INACTIVE_SHUTDOWN)
164164
if current_state == 'active':
165165
return self.__change_state(lifecycle_msgs.msg.Transition.TRANSITION_ACTIVE_SHUTDOWN)
166+
raise _rclpy.RCLError('Shutdown transtion not possible')
166167

167168
def trigger_activate(self):
168169
return self.__change_state(lifecycle_msgs.msg.Transition.TRANSITION_ACTIVATE)

rclpy/test/test_lifecycle.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,19 @@ def test_lifecycle_state_transitions():
6969
with pytest.raises(_rclpy.RCLError):
7070
node.trigger_deactivate()
7171
assert node.trigger_shutdown() == TransitionCallbackReturn.SUCCESS
72+
with pytest.raises(_rclpy.RCLError):
73+
node.trigger_shutdown()
7274
node.destroy_node()
75+
# Again but trigger shutdown from 'inactive' instead of 'unconfigured'
76+
node = LifecycleNode(
77+
'test_lifecycle_state_transitions_2', enable_communication_interface=False)
78+
assert node.trigger_shutdown() == TransitionCallbackReturn.SUCCESS
79+
# Again but trigger shutdown from 'active'
80+
node = LifecycleNode(
81+
'test_lifecycle_state_transitions_3', enable_communication_interface=False)
82+
assert node.trigger_configure() == TransitionCallbackReturn.SUCCESS
83+
assert node.trigger_activate() == TransitionCallbackReturn.SUCCESS
84+
assert node.trigger_shutdown() == TransitionCallbackReturn.SUCCESS
7385

7486
class ErrorOnConfigureHandledCorrectlyNode(LifecycleNode):
7587

0 commit comments

Comments
 (0)