1919
2020from launch import LaunchDescription
2121from launch .actions import ExecuteProcess
22+ from launch .actions import RegisterEventHandler
23+ from launch .actions import ResetEnvironment
24+ from launch .actions import SetEnvironmentVariable
25+ from launch .event_handlers import OnShutdown
2226
2327from launch_ros .actions import Node
2428
2731import launch_testing .asserts
2832import launch_testing .markers
2933import launch_testing .tools
34+ from launch_testing_ros .actions import EnableRmwIsolation
3035import launch_testing_ros .tools
3136
3237import pytest
@@ -49,6 +54,7 @@ def generate_test_description(rmw_implementation):
4954 path_to_fixtures = os .path .join (os .path .dirname (__file__ ), 'fixtures' )
5055 additional_env = get_rmw_additional_env (rmw_implementation )
5156 additional_env ['PYTHONUNBUFFERED' ] = '1'
57+ set_env_actions = [SetEnvironmentVariable (k , v ) for k , v in additional_env .items ()]
5258
5359 path_to_incompatible_talker_node_script = os .path .join (
5460 path_to_fixtures , 'talker_node_with_best_effort_qos.py' )
@@ -62,25 +68,21 @@ def generate_test_description(rmw_implementation):
6268 executable = sys .executable ,
6369 arguments = [path_to_compatible_talker_node_script ],
6470 remappings = [('chatter' , 'compatible_chatter' )],
65- additional_env = additional_env
6671 )
6772 listener_node_compatible = Node (
6873 executable = sys .executable ,
6974 arguments = [path_to_listener_node_script ],
7075 remappings = [('chatter' , 'compatible_chatter' )],
71- additional_env = additional_env
7276 )
7377 talker_node_incompatible = Node (
7478 executable = sys .executable ,
7579 arguments = [path_to_incompatible_talker_node_script ],
7680 remappings = [('chatter' , 'incompatible_chatter' )],
77- additional_env = additional_env
7881 )
7982 listener_node_incompatible = Node (
8083 executable = sys .executable ,
8184 arguments = [path_to_listener_node_script ],
8285 remappings = [('chatter' , 'incompatible_chatter' )],
83- additional_env = additional_env
8486 )
8587
8688 return LaunchDescription ([
@@ -89,6 +91,19 @@ def generate_test_description(rmw_implementation):
8991 cmd = ['ros2' , 'daemon' , 'stop' ],
9092 name = 'daemon-stop' ,
9193 on_exit = [
94+ * set_env_actions ,
95+ EnableRmwIsolation (),
96+ RegisterEventHandler (OnShutdown (on_shutdown = [
97+ # Stop daemon in isolated environment with proper ROS_DOMAIN_ID
98+ ExecuteProcess (
99+ cmd = ['ros2' , 'daemon' , 'stop' ],
100+ name = 'daemon-stop-isolated' ,
101+ # Use the same isolated environment
102+ additional_env = dict (additional_env ),
103+ ),
104+ # This must be done after stopping the daemon in the isolated environment
105+ ResetEnvironment (),
106+ ])),
92107 ExecuteProcess (
93108 cmd = ['ros2' , 'daemon' , 'start' ],
94109 name = 'daemon-start' ,
@@ -100,7 +115,6 @@ def generate_test_description(rmw_implementation):
100115 listener_node_compatible ,
101116 launch_testing .actions .ReadyToTest ()
102117 ],
103- additional_env = additional_env
104118 )
105119 ]
106120 ),
@@ -128,11 +142,8 @@ def setUpClass(
128142
129143 @contextlib .contextmanager
130144 def launch_doctor_command (self , arguments ):
131- additional_env = get_rmw_additional_env (rmw_implementation )
132- additional_env ['PYTHONUNBUFFERED' ] = '1'
133145 doctor_command_action = ExecuteProcess (
134146 cmd = ['ros2' , 'doctor' , * arguments ],
135- additional_env = additional_env ,
136147 name = 'ros2doctor-cli' ,
137148 output = 'screen'
138149 )
0 commit comments