Skip to content
12 changes: 11 additions & 1 deletion ros2action/test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,19 @@ def generate_test_description(rmw_implementation):
cmd=['ros2', 'daemon', 'stop'],
name='daemon-stop',
on_exit=[
RegisterEventHandler(OnShutdown(on_shutdown=ResetEnvironment())),
*set_env_actions,
EnableRmwIsolation(),
RegisterEventHandler(OnShutdown(on_shutdown=[
# Stop daemon in isolated environment with proper ROS_DOMAIN_ID
ExecuteProcess(
cmd=['ros2', 'daemon', 'stop'],
name='daemon-stop-isolated',
# Use the same isolated environment
additional_env=dict(additional_env),
),
# This must be done after stopping the daemon in the isolated environment
ResetEnvironment(),
])),
Comment on lines +68 to +78
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fix to avoid leaving the ros2 daemon processes with different ROS_DOMAIN_ID.
Right after the test, it makes sure clean up the ros2 daemon process in isolated environment, in this way we can only shut down the ros2 daemon instantiated by this isolated environment.
ros2 daemon stop above can stay there to stop the ros2 daemon with default ROS_DOMAIN_ID if that is online.

ExecuteProcess(
cmd=['ros2', 'daemon', 'start'],
name='daemon-start',
Expand Down
12 changes: 11 additions & 1 deletion ros2action/test/test_echo.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,19 @@ def generate_test_description(rmw_implementation):
cmd=['ros2', 'daemon', 'stop'],
name='daemon-stop',
on_exit=[
RegisterEventHandler(OnShutdown(on_shutdown=ResetEnvironment())),
*set_env_actions,
EnableRmwIsolation(),
RegisterEventHandler(OnShutdown(on_shutdown=[
# Stop daemon in isolated environment with proper ROS_DOMAIN_ID
ExecuteProcess(
cmd=['ros2', 'daemon', 'stop'],
name='daemon-stop-isolated',
# Use the same isolated environment
additional_env=dict(additional_env),
),
# This must be done after stopping the daemon in the isolated environment
ResetEnvironment(),
])),
ExecuteProcess(
cmd=['ros2', 'daemon', 'start'],
name='daemon-start',
Expand Down
15 changes: 15 additions & 0 deletions ros2doctor/test/test_environment_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
from launch import LaunchDescription
from launch import LaunchService
from launch.actions import ExecuteProcess
from launch.actions import RegisterEventHandler
from launch.actions import ResetEnvironment
from launch.actions import SetEnvironmentVariable
from launch.event_handlers import OnShutdown

import launch_testing
import launch_testing.actions
import launch_testing.asserts
Expand Down Expand Up @@ -63,6 +67,17 @@ def generate_test_description(rmw_implementation: str) -> tuple[LaunchDescriptio
on_exit=[
*set_env_actions,
EnableRmwIsolation(),
RegisterEventHandler(OnShutdown(on_shutdown=[
# Stop daemon in isolated environment with proper ROS_DOMAIN_ID
ExecuteProcess(
cmd=['ros2', 'daemon', 'stop'],
name='daemon-stop-isolated',
# Use the same isolated environment
additional_env=dict(additional_env),
),
# This must be done after stopping the daemon in the isolated environment
ResetEnvironment(),
])),
ExecuteProcess(
cmd=['ros2', 'daemon', 'start'],
name='daemon-start',
Expand Down
12 changes: 11 additions & 1 deletion ros2doctor/test/test_qos_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,19 @@ def generate_test_description(rmw_implementation):
cmd=['ros2', 'daemon', 'stop'],
name='daemon-stop',
on_exit=[
RegisterEventHandler(OnShutdown(on_shutdown=ResetEnvironment())),
*set_env_actions,
EnableRmwIsolation(),
RegisterEventHandler(OnShutdown(on_shutdown=[
# Stop daemon in isolated environment with proper ROS_DOMAIN_ID
ExecuteProcess(
cmd=['ros2', 'daemon', 'stop'],
name='daemon-stop-isolated',
# Use the same isolated environment
additional_env=dict(additional_env),
),
# This must be done after stopping the daemon in the isolated environment
ResetEnvironment(),
])),
ExecuteProcess(
cmd=['ros2', 'daemon', 'start'],
name='daemon-start',
Expand Down
29 changes: 19 additions & 10 deletions ros2doctor/test/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
from launch import LaunchDescription
from launch import LaunchService
from launch.actions import ExecuteProcess
from launch.actions import RegisterEventHandler
from launch.actions import ResetEnvironment
from launch.actions import SetEnvironmentVariable
from launch.event_handlers import OnShutdown

from launch_ros.actions import Node

Expand All @@ -32,6 +36,7 @@
import launch_testing.asserts
import launch_testing.markers
import launch_testing.tools
from launch_testing_ros.actions import EnableRmwIsolation
import launch_testing_ros.tools

import pytest
Expand All @@ -55,21 +60,33 @@ def generate_test_description(rmw_implementation: str) -> Tuple[LaunchDescriptio
path_to_fixtures = os.path.join(os.path.dirname(__file__), 'fixtures')
additional_env = get_rmw_additional_env(rmw_implementation)
additional_env['PYTHONUNBUFFERED'] = '1'
set_env_actions = [SetEnvironmentVariable(k, v) for k, v in additional_env.items()]

return LaunchDescription([
ExecuteProcess(
cmd=['ros2', 'daemon', 'stop'],
name='daemon-stop',
on_exit=[
*set_env_actions,
EnableRmwIsolation(),
RegisterEventHandler(OnShutdown(on_shutdown=[
# Stop daemon in isolated environment with proper ROS_DOMAIN_ID
ExecuteProcess(
cmd=['ros2', 'daemon', 'stop'],
name='daemon-stop-isolated',
# Use the same isolated environment
additional_env=dict(additional_env),
),
# This must be done after stopping the daemon in the isolated environment
ResetEnvironment(),
])),
ExecuteProcess(
cmd=['ros2', 'daemon', 'start'],
name='daemon-start',
additional_env=additional_env,
on_exit=[
Node(
executable=sys.executable,
arguments=[os.path.join(path_to_fixtures, 'report_node.py')],
additional_env=additional_env
),
launch_testing.actions.ReadyToTest()
]
Expand Down Expand Up @@ -100,11 +117,8 @@ def launch_doctor_command(
self,
arguments
) -> Generator[launch_testing.tools.process.ProcessProxy, None, None]:
additional_env = get_rmw_additional_env(rmw_implementation)
additional_env['PYTHONUNBUFFERED'] = '1'
doctor_command_action = ExecuteProcess(
cmd=['ros2', 'doctor', *arguments],
additional_env=additional_env,
name='ros2doctor-cli',
output='screen'
)
Expand All @@ -130,11 +144,6 @@ def test_check(self) -> None:

@launch_testing.markers.retry_on_failure(times=5, delay=1)
def test_report(self) -> None:
# TODO(@fujitatomoya): rmw_zenoh_cpp is instable to find the endpoints, it does not
# matter if DaemonNode or DirectNode is used. For now, skip the test for rmw_zenoh_cpp.
if self.rmw_implementation == 'rmw_zenoh_cpp':
raise unittest.SkipTest()

Comment on lines -133 to -137
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is another fix to support zenoh here. It now uses rmw isolated environment for the test, that will call rmw_zenoh specific setup for the isolation.

for argument in ['-r', '--report']:
with self.launch_doctor_command(
arguments=[argument]
Expand Down
12 changes: 11 additions & 1 deletion ros2lifecycle/test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,19 @@ def generate_test_description(rmw_implementation):
cmd=['ros2', 'daemon', 'stop'],
name='daemon-stop',
on_exit=[
RegisterEventHandler(OnShutdown(on_shutdown=ResetEnvironment())),
*set_env_actions,
EnableRmwIsolation(),
RegisterEventHandler(OnShutdown(on_shutdown=[
# Stop daemon in isolated environment with proper ROS_DOMAIN_ID
ExecuteProcess(
cmd=['ros2', 'daemon', 'stop'],
name='daemon-stop-isolated',
# Use the same isolated environment
additional_env=dict(additional_env),
),
# This must be done after stopping the daemon in the isolated environment
ResetEnvironment(),
])),
ExecuteProcess(
cmd=['ros2', 'daemon', 'start'],
name='daemon-start',
Expand Down
12 changes: 11 additions & 1 deletion ros2node/test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,19 @@ def generate_test_description(rmw_implementation):
cmd=['ros2', 'daemon', 'stop'],
name='daemon-stop',
on_exit=[
RegisterEventHandler(OnShutdown(on_shutdown=ResetEnvironment())),
*set_env_actions,
EnableRmwIsolation(),
RegisterEventHandler(OnShutdown(on_shutdown=[
# Stop daemon in isolated environment with proper ROS_DOMAIN_ID
ExecuteProcess(
cmd=['ros2', 'daemon', 'stop'],
name='daemon-stop-isolated',
# Use the same isolated environment
additional_env=dict(additional_env),
),
# This must be done after stopping the daemon in the isolated environment
ResetEnvironment(),
])),
ExecuteProcess(
cmd=['ros2', 'daemon', 'start'],
name='daemon-start',
Expand Down
12 changes: 11 additions & 1 deletion ros2node/test/test_cli_duplicate_node_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,19 @@ def generate_test_description(rmw_implementation):
cmd=['ros2', 'daemon', 'stop'],
name='daemon-stop',
on_exit=[
RegisterEventHandler(OnShutdown(on_shutdown=ResetEnvironment())),
*set_env_actions,
EnableRmwIsolation(),
RegisterEventHandler(OnShutdown(on_shutdown=[
# Stop daemon in isolated environment with proper ROS_DOMAIN_ID
ExecuteProcess(
cmd=['ros2', 'daemon', 'stop'],
name='daemon-stop-isolated',
# Use the same isolated environment
additional_env=dict(additional_env),
),
# This must be done after stopping the daemon in the isolated environment
ResetEnvironment(),
])),
ExecuteProcess(
cmd=['ros2', 'daemon', 'start'],
name='daemon-start',
Expand Down
12 changes: 11 additions & 1 deletion ros2param/test/test_verb_dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,19 @@ def generate_test_description(rmw_implementation):
cmd=['ros2', 'daemon', 'stop'],
name='daemon-stop',
on_exit=[
RegisterEventHandler(OnShutdown(on_shutdown=ResetEnvironment())),
*set_env_actions,
EnableRmwIsolation(),
RegisterEventHandler(OnShutdown(on_shutdown=[
# Stop daemon in isolated environment with proper ROS_DOMAIN_ID
ExecuteProcess(
cmd=['ros2', 'daemon', 'stop'],
name='daemon-stop-isolated',
# Use the same isolated environment
additional_env=dict(additional_env),
),
# This must be done after stopping the daemon in the isolated environment
ResetEnvironment(),
])),
ExecuteProcess(
cmd=['ros2', 'daemon', 'start'],
name='daemon-start',
Expand Down
12 changes: 11 additions & 1 deletion ros2param/test/test_verb_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,19 @@ def generate_test_description(rmw_implementation):
cmd=['ros2', 'daemon', 'stop'],
name='daemon-stop',
on_exit=[
RegisterEventHandler(OnShutdown(on_shutdown=ResetEnvironment())),
*set_env_actions,
EnableRmwIsolation(),
RegisterEventHandler(OnShutdown(on_shutdown=[
# Stop daemon in isolated environment with proper ROS_DOMAIN_ID
ExecuteProcess(
cmd=['ros2', 'daemon', 'stop'],
name='daemon-stop-isolated',
# Use the same isolated environment
additional_env=dict(additional_env),
),
# This must be done after stopping the daemon in the isolated environment
ResetEnvironment(),
])),
ExecuteProcess(
cmd=['ros2', 'daemon', 'start'],
name='daemon-start',
Expand Down
12 changes: 11 additions & 1 deletion ros2param/test/test_verb_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,19 @@ def generate_test_description(rmw_implementation):
cmd=['ros2', 'daemon', 'stop'],
name='daemon-stop',
on_exit=[
RegisterEventHandler(OnShutdown(on_shutdown=ResetEnvironment())),
*set_env_actions,
EnableRmwIsolation(),
RegisterEventHandler(OnShutdown(on_shutdown=[
# Stop daemon in isolated environment with proper ROS_DOMAIN_ID
ExecuteProcess(
cmd=['ros2', 'daemon', 'stop'],
name='daemon-stop-isolated',
# Use the same isolated environment
additional_env=dict(additional_env),
),
# This must be done after stopping the daemon in the isolated environment
ResetEnvironment(),
])),
ExecuteProcess(
cmd=['ros2', 'daemon', 'start'],
name='daemon-start',
Expand Down
12 changes: 11 additions & 1 deletion ros2service/test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,19 @@ def generate_test_description(rmw_implementation):
cmd=['ros2', 'daemon', 'stop'],
name='daemon-stop',
on_exit=[
RegisterEventHandler(OnShutdown(on_shutdown=ResetEnvironment())),
*set_env_actions,
EnableRmwIsolation(),
RegisterEventHandler(OnShutdown(on_shutdown=[
# Stop daemon in isolated environment with proper ROS_DOMAIN_ID
ExecuteProcess(
cmd=['ros2', 'daemon', 'stop'],
name='daemon-stop-isolated',
# Use the same isolated environment
additional_env=dict(additional_env),
),
# This must be done after stopping the daemon in the isolated environment
ResetEnvironment(),
])),
ExecuteProcess(
cmd=['ros2', 'daemon', 'start'],
name='daemon-start',
Expand Down
12 changes: 11 additions & 1 deletion ros2service/test/test_echo.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,19 @@ def generate_test_description(rmw_implementation):
cmd=['ros2', 'daemon', 'stop'],
name='daemon-stop',
on_exit=[
RegisterEventHandler(OnShutdown(on_shutdown=ResetEnvironment())),
*set_env_actions,
EnableRmwIsolation(),
RegisterEventHandler(OnShutdown(on_shutdown=[
# Stop daemon in isolated environment with proper ROS_DOMAIN_ID
ExecuteProcess(
cmd=['ros2', 'daemon', 'stop'],
name='daemon-stop-isolated',
# Use the same isolated environment
additional_env=dict(additional_env),
),
# This must be done after stopping the daemon in the isolated environment
ResetEnvironment(),
])),
ExecuteProcess(
cmd=['ros2', 'daemon', 'start'],
name='daemon-start',
Expand Down
12 changes: 12 additions & 0 deletions ros2topic/test/test_bw_delay_hz.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

from launch import LaunchDescription
from launch.actions import ExecuteProcess
from launch.actions import RegisterEventHandler
from launch.actions import ResetEnvironment
from launch.event_handlers import OnShutdown

import launch_testing
import launch_testing.actions
Expand Down Expand Up @@ -63,6 +66,15 @@ def generate_test_description():
name='daemon-stop',
on_exit=[
EnableRmwIsolation(),
RegisterEventHandler(OnShutdown(on_shutdown=[
# Stop daemon in isolated environment with proper ROS_DOMAIN_ID
ExecuteProcess(
cmd=['ros2', 'daemon', 'stop'],
name='daemon-stop-isolated',
),
# This must be done after stopping the daemon in the isolated environment
ResetEnvironment(),
])),
ExecuteProcess(
cmd=['ros2', 'daemon', 'start'],
name='daemon-start',
Expand Down
12 changes: 11 additions & 1 deletion ros2topic/test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,19 @@ def generate_test_description(rmw_implementation):
cmd=['ros2', 'daemon', 'stop'],
name='daemon-stop',
on_exit=[
RegisterEventHandler(OnShutdown(on_shutdown=ResetEnvironment())),
*set_env_actions,
EnableRmwIsolation(),
RegisterEventHandler(OnShutdown(on_shutdown=[
# Stop daemon in isolated environment with proper ROS_DOMAIN_ID
ExecuteProcess(
cmd=['ros2', 'daemon', 'stop'],
name='daemon-stop-isolated',
# Use the same isolated environment
additional_env=dict(additional_env),
),
# This must be done after stopping the daemon in the isolated environment
ResetEnvironment(),
])),
ExecuteProcess(
cmd=['ros2', 'daemon', 'start'],
name='daemon-start',
Expand Down
Loading