Skip to content

Commit f350134

Browse files
authored
Fujitatomoya/clearup isolated ros2daemon (#1098)
* Enable RMW isolation for ros2doctor.test_report. Signed-off-by: Tomoya Fujita <[email protected]> * ResetEnvironment on shutdown is missing. Signed-off-by: Tomoya Fujita <[email protected]> * Clean up isolated ros2 daemon process when tests complete. Signed-off-by: Tomoya Fujita <[email protected]> * Clean up isolated ros2 daemon process for ros2topic. Signed-off-by: Tomoya Fujita <[email protected]> * Clean up isolated ros2 daemon process for ros2action. Signed-off-by: Tomoya Fujita <[email protected]> * Clean up isolated ros2 daemon process for ros2doctor. Signed-off-by: Tomoya Fujita <[email protected]> * Clean up isolated ros2 daemon process for ros2lifecycle and ros2node. Signed-off-by: Tomoya Fujita <[email protected]> * Clean up isolated ros2 daemon process for ros2param. Signed-off-by: Tomoya Fujita <[email protected]> --------- Signed-off-by: Tomoya Fujita <[email protected]>
1 parent b032efe commit f350134

File tree

17 files changed

+202
-22
lines changed

17 files changed

+202
-22
lines changed

ros2action/test/test_cli.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,19 @@ def generate_test_description(rmw_implementation):
6363
cmd=['ros2', 'daemon', 'stop'],
6464
name='daemon-stop',
6565
on_exit=[
66-
RegisterEventHandler(OnShutdown(on_shutdown=ResetEnvironment())),
6766
*set_env_actions,
6867
EnableRmwIsolation(),
68+
RegisterEventHandler(OnShutdown(on_shutdown=[
69+
# Stop daemon in isolated environment with proper ROS_DOMAIN_ID
70+
ExecuteProcess(
71+
cmd=['ros2', 'daemon', 'stop'],
72+
name='daemon-stop-isolated',
73+
# Use the same isolated environment
74+
additional_env=dict(additional_env),
75+
),
76+
# This must be done after stopping the daemon in the isolated environment
77+
ResetEnvironment(),
78+
])),
6979
ExecuteProcess(
7080
cmd=['ros2', 'daemon', 'start'],
7181
name='daemon-start',

ros2action/test/test_echo.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,19 @@ def generate_test_description(rmw_implementation):
233233
cmd=['ros2', 'daemon', 'stop'],
234234
name='daemon-stop',
235235
on_exit=[
236-
RegisterEventHandler(OnShutdown(on_shutdown=ResetEnvironment())),
237236
*set_env_actions,
238237
EnableRmwIsolation(),
238+
RegisterEventHandler(OnShutdown(on_shutdown=[
239+
# Stop daemon in isolated environment with proper ROS_DOMAIN_ID
240+
ExecuteProcess(
241+
cmd=['ros2', 'daemon', 'stop'],
242+
name='daemon-stop-isolated',
243+
# Use the same isolated environment
244+
additional_env=dict(additional_env),
245+
),
246+
# This must be done after stopping the daemon in the isolated environment
247+
ResetEnvironment(),
248+
])),
239249
ExecuteProcess(
240250
cmd=['ros2', 'daemon', 'start'],
241251
name='daemon-start',

ros2doctor/test/test_environment_report.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@
2222
from launch import LaunchDescription
2323
from launch import LaunchService
2424
from launch.actions import ExecuteProcess
25+
from launch.actions import RegisterEventHandler
26+
from launch.actions import ResetEnvironment
2527
from launch.actions import SetEnvironmentVariable
28+
from launch.event_handlers import OnShutdown
29+
2630
import launch_testing
2731
import launch_testing.actions
2832
import launch_testing.asserts
@@ -63,6 +67,17 @@ def generate_test_description(rmw_implementation: str) -> tuple[LaunchDescriptio
6367
on_exit=[
6468
*set_env_actions,
6569
EnableRmwIsolation(),
70+
RegisterEventHandler(OnShutdown(on_shutdown=[
71+
# Stop daemon in isolated environment with proper ROS_DOMAIN_ID
72+
ExecuteProcess(
73+
cmd=['ros2', 'daemon', 'stop'],
74+
name='daemon-stop-isolated',
75+
# Use the same isolated environment
76+
additional_env=dict(additional_env),
77+
),
78+
# This must be done after stopping the daemon in the isolated environment
79+
ResetEnvironment(),
80+
])),
6681
ExecuteProcess(
6782
cmd=['ros2', 'daemon', 'start'],
6883
name='daemon-start',

ros2doctor/test/test_qos_compatibility.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,19 @@ def generate_test_description(rmw_implementation):
9191
cmd=['ros2', 'daemon', 'stop'],
9292
name='daemon-stop',
9393
on_exit=[
94-
RegisterEventHandler(OnShutdown(on_shutdown=ResetEnvironment())),
9594
*set_env_actions,
9695
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+
])),
97107
ExecuteProcess(
98108
cmd=['ros2', 'daemon', 'start'],
99109
name='daemon-start',

ros2doctor/test/test_report.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
from launch import LaunchDescription
2525
from launch import LaunchService
2626
from 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

2832
from launch_ros.actions import Node
2933

@@ -32,6 +36,7 @@
3236
import launch_testing.asserts
3337
import launch_testing.markers
3438
import launch_testing.tools
39+
from launch_testing_ros.actions import EnableRmwIsolation
3540
import launch_testing_ros.tools
3641

3742
import 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]

ros2lifecycle/test/test_cli.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,19 @@ def generate_test_description(rmw_implementation):
136136
cmd=['ros2', 'daemon', 'stop'],
137137
name='daemon-stop',
138138
on_exit=[
139-
RegisterEventHandler(OnShutdown(on_shutdown=ResetEnvironment())),
140139
*set_env_actions,
141140
EnableRmwIsolation(),
141+
RegisterEventHandler(OnShutdown(on_shutdown=[
142+
# Stop daemon in isolated environment with proper ROS_DOMAIN_ID
143+
ExecuteProcess(
144+
cmd=['ros2', 'daemon', 'stop'],
145+
name='daemon-stop-isolated',
146+
# Use the same isolated environment
147+
additional_env=dict(additional_env),
148+
),
149+
# This must be done after stopping the daemon in the isolated environment
150+
ResetEnvironment(),
151+
])),
142152
ExecuteProcess(
143153
cmd=['ros2', 'daemon', 'start'],
144154
name='daemon-start',

ros2node/test/test_cli.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,19 @@ def generate_test_description(rmw_implementation):
6464
cmd=['ros2', 'daemon', 'stop'],
6565
name='daemon-stop',
6666
on_exit=[
67-
RegisterEventHandler(OnShutdown(on_shutdown=ResetEnvironment())),
6867
*set_env_actions,
6968
EnableRmwIsolation(),
69+
RegisterEventHandler(OnShutdown(on_shutdown=[
70+
# Stop daemon in isolated environment with proper ROS_DOMAIN_ID
71+
ExecuteProcess(
72+
cmd=['ros2', 'daemon', 'stop'],
73+
name='daemon-stop-isolated',
74+
# Use the same isolated environment
75+
additional_env=dict(additional_env),
76+
),
77+
# This must be done after stopping the daemon in the isolated environment
78+
ResetEnvironment(),
79+
])),
7080
ExecuteProcess(
7181
cmd=['ros2', 'daemon', 'start'],
7282
name='daemon-start',

ros2node/test/test_cli_duplicate_node_names.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,19 @@ def generate_test_description(rmw_implementation):
6363
cmd=['ros2', 'daemon', 'stop'],
6464
name='daemon-stop',
6565
on_exit=[
66-
RegisterEventHandler(OnShutdown(on_shutdown=ResetEnvironment())),
6766
*set_env_actions,
6867
EnableRmwIsolation(),
68+
RegisterEventHandler(OnShutdown(on_shutdown=[
69+
# Stop daemon in isolated environment with proper ROS_DOMAIN_ID
70+
ExecuteProcess(
71+
cmd=['ros2', 'daemon', 'stop'],
72+
name='daemon-stop-isolated',
73+
# Use the same isolated environment
74+
additional_env=dict(additional_env),
75+
),
76+
# This must be done after stopping the daemon in the isolated environment
77+
ResetEnvironment(),
78+
])),
6979
ExecuteProcess(
7080
cmd=['ros2', 'daemon', 'start'],
7181
name='daemon-start',

ros2param/test/test_verb_dump.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,19 @@ def generate_test_description(rmw_implementation):
108108
cmd=['ros2', 'daemon', 'stop'],
109109
name='daemon-stop',
110110
on_exit=[
111-
RegisterEventHandler(OnShutdown(on_shutdown=ResetEnvironment())),
112111
*set_env_actions,
113112
EnableRmwIsolation(),
113+
RegisterEventHandler(OnShutdown(on_shutdown=[
114+
# Stop daemon in isolated environment with proper ROS_DOMAIN_ID
115+
ExecuteProcess(
116+
cmd=['ros2', 'daemon', 'stop'],
117+
name='daemon-stop-isolated',
118+
# Use the same isolated environment
119+
additional_env=dict(additional_env),
120+
),
121+
# This must be done after stopping the daemon in the isolated environment
122+
ResetEnvironment(),
123+
])),
114124
ExecuteProcess(
115125
cmd=['ros2', 'daemon', 'start'],
116126
name='daemon-start',

ros2param/test/test_verb_list.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,19 @@ def generate_test_description(rmw_implementation):
7878
cmd=['ros2', 'daemon', 'stop'],
7979
name='daemon-stop',
8080
on_exit=[
81-
RegisterEventHandler(OnShutdown(on_shutdown=ResetEnvironment())),
8281
*set_env_actions,
8382
EnableRmwIsolation(),
83+
RegisterEventHandler(OnShutdown(on_shutdown=[
84+
# Stop daemon in isolated environment with proper ROS_DOMAIN_ID
85+
ExecuteProcess(
86+
cmd=['ros2', 'daemon', 'stop'],
87+
name='daemon-stop-isolated',
88+
# Use the same isolated environment
89+
additional_env=dict(additional_env),
90+
),
91+
# This must be done after stopping the daemon in the isolated environment
92+
ResetEnvironment(),
93+
])),
8494
ExecuteProcess(
8595
cmd=['ros2', 'daemon', 'start'],
8696
name='daemon-start',

0 commit comments

Comments
 (0)