2424from launch import LaunchDescription
2525from launch import LaunchService
2626from launch .actions import ExecuteProcess
27+ from launch .actions import RegisterEventHandler
28+ from launch .actions import ResetEnvironment
29+ from launch .actions import SetEnvironmentVariable
30+ from launch .event_handlers import OnShutdown
2731
2832from launch_ros .actions import Node
2933
3236import launch_testing .asserts
3337import launch_testing .markers
3438import launch_testing .tools
39+ from launch_testing_ros .actions import EnableRmwIsolation
3540import launch_testing_ros .tools
3641
3742import pytest
@@ -55,21 +60,33 @@ def generate_test_description(rmw_implementation: str) -> Tuple[LaunchDescriptio
5560 path_to_fixtures = os .path .join (os .path .dirname (__file__ ), 'fixtures' )
5661 additional_env = get_rmw_additional_env (rmw_implementation )
5762 additional_env ['PYTHONUNBUFFERED' ] = '1'
63+ set_env_actions = [SetEnvironmentVariable (k , v ) for k , v in additional_env .items ()]
5864
5965 return LaunchDescription ([
6066 ExecuteProcess (
6167 cmd = ['ros2' , 'daemon' , 'stop' ],
6268 name = 'daemon-stop' ,
6369 on_exit = [
70+ * set_env_actions ,
71+ EnableRmwIsolation (),
72+ RegisterEventHandler (OnShutdown (on_shutdown = [
73+ # Stop daemon in isolated environment with proper ROS_DOMAIN_ID
74+ ExecuteProcess (
75+ cmd = ['ros2' , 'daemon' , 'stop' ],
76+ name = 'daemon-stop-isolated' ,
77+ # Use the same isolated environment
78+ additional_env = dict (additional_env ),
79+ ),
80+ # This must be done after stopping the daemon in the isolated environment
81+ ResetEnvironment (),
82+ ])),
6483 ExecuteProcess (
6584 cmd = ['ros2' , 'daemon' , 'start' ],
6685 name = 'daemon-start' ,
67- additional_env = additional_env ,
6886 on_exit = [
6987 Node (
7088 executable = sys .executable ,
7189 arguments = [os .path .join (path_to_fixtures , 'report_node.py' )],
72- additional_env = additional_env
7390 ),
7491 launch_testing .actions .ReadyToTest ()
7592 ]
@@ -100,11 +117,8 @@ def launch_doctor_command(
100117 self ,
101118 arguments
102119 ) -> Generator [launch_testing .tools .process .ProcessProxy , None , None ]:
103- additional_env = get_rmw_additional_env (rmw_implementation )
104- additional_env ['PYTHONUNBUFFERED' ] = '1'
105120 doctor_command_action = ExecuteProcess (
106121 cmd = ['ros2' , 'doctor' , * arguments ],
107- additional_env = additional_env ,
108122 name = 'ros2doctor-cli' ,
109123 output = 'screen'
110124 )
@@ -130,11 +144,6 @@ def test_check(self) -> None:
130144
131145 @launch_testing .markers .retry_on_failure (times = 5 , delay = 1 )
132146 def test_report (self ) -> None :
133- # TODO(@fujitatomoya): rmw_zenoh_cpp is instable to find the endpoints, it does not
134- # matter if DaemonNode or DirectNode is used. For now, skip the test for rmw_zenoh_cpp.
135- if self .rmw_implementation == 'rmw_zenoh_cpp' :
136- raise unittest .SkipTest ()
137-
138147 for argument in ['-r' , '--report' ]:
139148 with self .launch_doctor_command (
140149 arguments = [argument ]
0 commit comments