-
Notifications
You must be signed in to change notification settings - Fork 190
[ros2component] Add tests for ros2component #390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
BMarchi
wants to merge
9
commits into
rolling
Choose a base branch
from
BMarchi/add_test_for_ros2component
base: rolling
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
fee00b5
Add tests for ros2component
BMarchi c848cd2
Add missing dependencies
BMarchi 2bff91b
Make use of the composition package and separate verbs in different t…
BMarchi 9c2dda2
Add examples repository for ros2component
BMarchi f1c21f3
Address PR comments
BMarchi 3a440c4
Modify talker
BMarchi 03f74e6
Increase retries for list and improve load verb test
BMarchi 1b0461a
Improve unload verb test
BMarchi e0b2e92
Address PR comments
BMarchi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,12 +9,13 @@ | |
| <maintainer email="[email protected]">Michel Hidalgo</maintainer> | ||
| <license>Apache License 2.0</license> | ||
|
|
||
| <depend>ros2cli</depend> | ||
|
|
||
| <exec_depend>ament_index_python</exec_depend> | ||
| <exec_depend>composition_interfaces</exec_depend> | ||
| <exec_depend>rcl_interfaces</exec_depend> | ||
| <exec_depend>rclcpp_components</exec_depend> | ||
| <exec_depend>rclpy</exec_depend> | ||
| <exec_depend>ros2cli</exec_depend> | ||
| <exec_depend>ros2node</exec_depend> | ||
| <exec_depend>ros2param</exec_depend> | ||
| <exec_depend>ros2pkg</exec_depend> | ||
|
|
@@ -24,6 +25,8 @@ | |
| <test_depend>ament_pep257</test_depend> | ||
| <test_depend>ament_xmllint</test_depend> | ||
| <test_depend>python3-pytest</test_depend> | ||
| <test_depend>ros2component_fixtures</test_depend> | ||
| <test_depend>ros_testing</test_depend> | ||
|
|
||
| <export> | ||
| <build_type>ament_python</build_type> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| # Copyright 2019 Open Source Robotics Foundation, Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import contextlib | ||
| import unittest | ||
|
|
||
| from launch import LaunchDescription | ||
| from launch.actions import ExecuteProcess | ||
| from launch.actions import OpaqueFunction | ||
|
|
||
| from launch_ros.actions import Node | ||
|
|
||
| import launch_testing | ||
| import launch_testing.asserts | ||
| import launch_testing.markers | ||
| import launch_testing.tools | ||
| import launch_testing_ros.tools | ||
|
|
||
| import pytest | ||
|
|
||
| from rmw_implementation import get_available_rmw_implementations | ||
|
|
||
| LIST_THREE_NODES = """\ | ||
| /ComponentManager | ||
| 1 /listener | ||
| 2 /talker | ||
| 3 /talker | ||
| """ | ||
BMarchi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| # TODO(BMarchi): Opensplice doesn't get along with running any cli command with ExecuteProcess, | ||
| # it just hangs there making `wait_for_timeout` fail. All tests should run fine with opensplice. | ||
| @pytest.mark.rostest | ||
| @launch_testing.parametrize( | ||
| 'rmw_implementation', | ||
| [v for v in get_available_rmw_implementations() if v != 'rmw_opensplice_cpp']) | ||
| def generate_test_description(rmw_implementation, ready_fn): | ||
| additional_env = {'RMW_IMPLEMENTATION': rmw_implementation} | ||
| component_node = Node( | ||
BMarchi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| package='rclcpp_components', node_executable='component_container', output='screen') | ||
| listener_command_action = ExecuteProcess( | ||
BMarchi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| cmd=['ros2', 'component', 'load', '/ComponentManager', | ||
| 'ros2component_fixtures', 'ros2component_fixtures::Listener'], | ||
| additional_env={ | ||
| 'RMW_IMPLEMENTATION': rmw_implementation, | ||
| 'PYTHONUNBUFFERED': '1' | ||
| }, | ||
| name='ros2component-cli', | ||
| output='screen', | ||
| on_exit=[ | ||
| ExecuteProcess( | ||
| cmd=['ros2', 'component', 'load', '/ComponentManager', | ||
| 'ros2component_fixtures', 'ros2component_fixtures::Talker'], | ||
| additional_env={ | ||
| 'RMW_IMPLEMENTATION': rmw_implementation, | ||
| 'PYTHONUNBUFFERED': '1' | ||
| }, | ||
| name='ros2component-cli', | ||
| output='screen', | ||
| on_exit=[ | ||
| ExecuteProcess( | ||
BMarchi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| cmd=['ros2', 'component', 'load', '/ComponentManager', | ||
| 'ros2component_fixtures', 'ros2component_fixtures::Talker'], | ||
| additional_env={ | ||
| 'RMW_IMPLEMENTATION': rmw_implementation, | ||
| 'PYTHONUNBUFFERED': '1' | ||
| }, | ||
| name='ros2component-cli', | ||
| output='screen' | ||
| ) | ||
| ] | ||
| ) | ||
| ] | ||
| ) | ||
| return LaunchDescription([ | ||
| # Always restart daemon to isolate tests. | ||
| ExecuteProcess( | ||
| cmd=['ros2', 'daemon', 'stop'], | ||
| name='daemon-stop', | ||
| on_exit=[ | ||
| ExecuteProcess( | ||
| cmd=['ros2', 'daemon', 'start'], | ||
| name='daemon-start', | ||
| on_exit=[ | ||
| component_node, | ||
| OpaqueFunction(function=lambda context: ready_fn()), | ||
BMarchi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| listener_command_action | ||
| ], | ||
| additional_env=additional_env | ||
| ) | ||
| ] | ||
| ), | ||
| ]), locals() | ||
|
|
||
|
|
||
| class TestROS2ComponentListCLI(unittest.TestCase): | ||
|
|
||
| @classmethod | ||
| def setUpClass( | ||
| cls, | ||
| launch_service, | ||
| proc_info, | ||
| proc_output, | ||
| rmw_implementation | ||
| ): | ||
| @contextlib.contextmanager | ||
| def launch_node_command(self, arguments): | ||
| node_command_action = ExecuteProcess( | ||
| cmd=['ros2', 'component', *arguments], | ||
| additional_env={ | ||
| 'RMW_IMPLEMENTATION': rmw_implementation, | ||
| 'PYTHONUNBUFFERED': '1' | ||
| }, | ||
| name='ros2component-cli', | ||
| output='screen' | ||
| ) | ||
| with launch_testing.tools.launch_process( | ||
| launch_service, node_command_action, proc_info, proc_output, | ||
| output_filter=launch_testing_ros.tools.basic_output_filter( | ||
| # ignore ros2cli daemon nodes | ||
| filtered_patterns=['.*ros2cli.*'], | ||
| filtered_rmw_implementation=rmw_implementation | ||
| ) | ||
| ) as node_command: | ||
| yield node_command | ||
| cls.launch_node_command = launch_node_command | ||
BMarchi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| cls.rmw_implementation = rmw_implementation | ||
BMarchi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @launch_testing.markers.retry_on_failure(times=5) | ||
| def test_list_verb(self): | ||
| with self.launch_node_command( | ||
| arguments=['list']) as list_command: | ||
| assert list_command.wait_for_shutdown(timeout=5) | ||
| assert list_command.exit_code == launch_testing.asserts.EXIT_OK | ||
| assert launch_testing.tools.expect_output( | ||
| expected_text=LIST_THREE_NODES, | ||
| text=list_command.output, | ||
| strict=True | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,196 @@ | ||
| # Copyright 2019 Open Source Robotics Foundation, Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import contextlib | ||
| import unittest | ||
|
|
||
| from launch import LaunchDescription | ||
| from launch.actions import ExecuteProcess | ||
| from launch.actions import OpaqueFunction | ||
|
|
||
| from launch_ros.actions import Node | ||
|
|
||
| import launch_testing | ||
| import launch_testing.asserts | ||
| import launch_testing.markers | ||
| import launch_testing.tools | ||
| import launch_testing_ros.tools | ||
|
|
||
| import pytest | ||
|
|
||
| from rmw_implementation import get_available_rmw_implementations | ||
|
|
||
|
|
||
| # TODO(BMarchi): Opensplice doesn't get along with running any cli command with ExecuteProcess, | ||
| # it just hangs there making `wait_for_timeout` fail. All tests should run fine with opensplice. | ||
| @pytest.mark.rostest | ||
| @launch_testing.parametrize( | ||
| 'rmw_implementation', | ||
| [v for v in get_available_rmw_implementations() if v != 'rmw_opensplice_cpp']) | ||
| def generate_test_description(rmw_implementation, ready_fn): | ||
| additional_env = {'RMW_IMPLEMENTATION': rmw_implementation} | ||
| component_node = Node( | ||
BMarchi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| package='rclcpp_components', node_executable='component_container', output='screen') | ||
| return LaunchDescription([ | ||
| # Always restart daemon to isolate tests. | ||
| ExecuteProcess( | ||
| cmd=['ros2', 'daemon', 'stop'], | ||
| name='daemon-stop', | ||
| on_exit=[ | ||
| ExecuteProcess( | ||
| cmd=['ros2', 'daemon', 'start'], | ||
| name='daemon-start', | ||
| on_exit=[ | ||
| component_node, | ||
| OpaqueFunction(function=lambda context: ready_fn()) | ||
| ], | ||
| additional_env=additional_env | ||
| ) | ||
| ] | ||
| ), | ||
| ]), locals() | ||
|
|
||
|
|
||
| class TestROS2ComponentLoadCLI(unittest.TestCase): | ||
|
|
||
| @classmethod | ||
| def setUpClass( | ||
| cls, | ||
| launch_service, | ||
| proc_info, | ||
| proc_output, | ||
| rmw_implementation | ||
| ): | ||
| @contextlib.contextmanager | ||
| def launch_node_command(self, arguments): | ||
| node_command_action = ExecuteProcess( | ||
| cmd=['ros2', 'component', *arguments], | ||
| additional_env={ | ||
| 'RMW_IMPLEMENTATION': rmw_implementation, | ||
| 'PYTHONUNBUFFERED': '1' | ||
| }, | ||
| name='ros2component-cli', | ||
| output='screen' | ||
| ) | ||
| with launch_testing.tools.launch_process( | ||
| launch_service, node_command_action, proc_info, proc_output, | ||
| output_filter=launch_testing_ros.tools.basic_output_filter( | ||
| # ignore ros2cli daemon nodes | ||
| filtered_patterns=['.*ros2cli.*'], | ||
| filtered_rmw_implementation=rmw_implementation | ||
| ) | ||
| ) as node_command: | ||
| yield node_command | ||
| cls.launch_node_command = launch_node_command | ||
|
|
||
| @launch_testing.markers.retry_on_failure(times=2) | ||
| def test_load_verb(self): | ||
| with self.launch_node_command( | ||
| arguments=[ | ||
| 'load', '/ComponentManager', | ||
| 'ros2component_fixtures', 'ros2component_fixtures::Talker']) as talker_node: | ||
BMarchi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| assert talker_node.wait_for_shutdown(timeout=20) | ||
| assert talker_node.exit_code == launch_testing.asserts.EXIT_OK | ||
| assert launch_testing.tools.expect_output( | ||
BMarchi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| expected_lines=[ | ||
| "Loaded component 1 into '/ComponentManager' " | ||
| "container node as '/talker'"], | ||
| text=talker_node.output, | ||
| strict=True | ||
| ) | ||
| with self.launch_node_command( | ||
| arguments=[ | ||
| 'load', '/ComponentManager', | ||
| 'ros2component_fixtures', | ||
| 'ros2component_fixtures::Listener']) as listener_node: | ||
| assert listener_node.wait_for_shutdown(timeout=20) | ||
| assert listener_node.exit_code == launch_testing.asserts.EXIT_OK | ||
| assert launch_testing.tools.expect_output( | ||
| expected_lines=[ | ||
| "Loaded component 2 into '/ComponentManager' " | ||
| "container node as '/listener'"], | ||
| text=listener_node.output, | ||
| strict=True | ||
| ) | ||
| with self.launch_node_command( | ||
BMarchi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| arguments=[ | ||
| 'unload', '/ComponentManager', '1']) as unload_command: | ||
| assert unload_command.wait_for_shutdown(timeout=20) | ||
| assert unload_command.exit_code == launch_testing.asserts.EXIT_OK | ||
| assert launch_testing.tools.expect_output( | ||
| expected_lines=["Unloaded component 1 from '/ComponentManager' container"], | ||
| text=unload_command.output, | ||
| strict=True | ||
| ) | ||
| # Test the unique id for loaded nodes. | ||
| with self.launch_node_command( | ||
| arguments=[ | ||
| 'load', '/ComponentManager', | ||
| 'ros2component_fixtures', 'ros2component_fixtures::Talker']) as talker_node: | ||
| assert talker_node.wait_for_shutdown(timeout=20) | ||
| assert talker_node.exit_code == launch_testing.asserts.EXIT_OK | ||
| assert launch_testing.tools.expect_output( | ||
| expected_lines=[ | ||
| "Loaded component 3 into '/ComponentManager' " | ||
| "container node as '/talker'"], | ||
| text=talker_node.output, | ||
| strict=True | ||
| ) | ||
| # Test we can load the same node more than once. | ||
| with self.launch_node_command( | ||
| arguments=[ | ||
| 'load', '/ComponentManager', | ||
| 'ros2component_fixtures', 'ros2component_fixtures::Talker']) as talker_node: | ||
| assert talker_node.wait_for_shutdown(timeout=20) | ||
| assert talker_node.exit_code == launch_testing.asserts.EXIT_OK | ||
| assert launch_testing.tools.expect_output( | ||
| expected_lines=[ | ||
| "Loaded component 4 into '/ComponentManager' " | ||
| "container node as '/talker'"], | ||
| text=talker_node.output, | ||
| strict=True | ||
| ) | ||
|
|
||
| @launch_testing.markers.retry_on_failure(times=2) | ||
| def test_load_verb_nonexistent_class(self): | ||
BMarchi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| with self.launch_node_command( | ||
| arguments=[ | ||
| 'load', '/ComponentManager', | ||
| 'ros2component_fixtures', | ||
| 'ros2component_fixtures::NonExistingPlugin']) as command: | ||
BMarchi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| assert command.wait_for_shutdown(timeout=20) | ||
| assert command.exit_code == 1 | ||
| assert launch_testing.tools.expect_output( | ||
| expected_lines=[ | ||
| 'Failed to load component: ' | ||
| 'Failed to find class with the requested plugin name.'], | ||
| text=command.output, | ||
| strict=True | ||
| ) | ||
|
|
||
| @launch_testing.markers.retry_on_failure(times=2) | ||
| def test_load_verb_nonexistent_plugin(self): | ||
BMarchi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| with self.launch_node_command( | ||
| arguments=[ | ||
| 'load', '/ComponentManager', | ||
| 'non_existent_plugin', 'non_existent_plugin::Test']) as command: | ||
| assert command.wait_for_shutdown(timeout=20) | ||
| assert command.exit_code == 1 | ||
| assert launch_testing.tools.expect_output( | ||
| expected_lines=[ | ||
| 'Failed to load component: ' | ||
| 'Could not find requested resource in ament index'], | ||
| text=command.output, | ||
| strict=True | ||
| ) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.