Skip to content

Commit b677df5

Browse files
mjcarrollYadunund
andauthored
Allow zenoh tests to run with multicast (#992)
Signed-off-by: Michael Carroll <[email protected]> Signed-off-by: Yadunund <[email protected]> Co-authored-by: Yadunund <[email protected]>
1 parent 31d814d commit b677df5

File tree

13 files changed

+85
-68
lines changed

13 files changed

+85
-68
lines changed

ros2action/test/test_cli.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import pytest
3232

3333
from rclpy.utilities import get_available_rmw_implementations
34+
from ros2cli.helpers import get_rmw_additional_env
3435

3536
import yaml
3637

@@ -49,6 +50,7 @@ def generate_test_description(rmw_implementation):
4950
path_to_action_server_executable = os.path.join(
5051
os.path.dirname(__file__), 'fixtures', 'fibonacci_action_server.py'
5152
)
53+
additional_env = get_rmw_additional_env(rmw_implementation)
5254
return LaunchDescription([
5355
# Always restart daemon to isolate tests.
5456
ExecuteProcess(
@@ -61,11 +63,11 @@ def generate_test_description(rmw_implementation):
6163
on_exit=[
6264
ExecuteProcess(
6365
cmd=[sys.executable, path_to_action_server_executable],
64-
additional_env={'RMW_IMPLEMENTATION': rmw_implementation}
66+
additional_env=additional_env,
6567
),
6668
launch_testing.actions.ReadyToTest()
6769
],
68-
additional_env={'RMW_IMPLEMENTATION': rmw_implementation}
70+
additional_env=additional_env,
6971
)
7072
]
7173
),
@@ -113,13 +115,13 @@ def setUpClass(
113115
):
114116
@contextlib.contextmanager
115117
def launch_action_command(self, arguments):
118+
additional_env = get_rmw_additional_env(rmw_implementation)
119+
additional_env['PYTHONUNBUFFERED'] = '1'
120+
116121
action_command_action = ExecuteProcess(
117122
cmd=['ros2', 'action', *arguments],
118123
name='ros2action-cli', output='screen',
119-
additional_env={
120-
'RMW_IMPLEMENTATION': rmw_implementation,
121-
'PYTHONUNBUFFERED': '1'
122-
}
124+
additional_env=additional_env
123125
)
124126
with launch_testing.tools.launch_process(
125127
launch_service, action_command_action, proc_info, proc_output,

ros2action/test/test_echo.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import pytest
3636

3737
from rclpy.utilities import get_available_rmw_implementations
38+
from ros2cli.helpers import get_rmw_additional_env
3839

3940

4041
# Skip cli tests on Windows while they exhibit pathological behavior
@@ -51,6 +52,7 @@ def generate_test_description(rmw_implementation):
5152
path_to_action_server_executable = os.path.join(
5253
os.path.dirname(__file__), 'fixtures', 'fibonacci_action_introspection.py'
5354
)
55+
additional_env = get_rmw_additional_env(rmw_implementation)
5456
return LaunchDescription([
5557
# Always restart daemon to isolate tests.
5658
ExecuteProcess(
@@ -63,11 +65,11 @@ def generate_test_description(rmw_implementation):
6365
on_exit=[
6466
ExecuteProcess(
6567
cmd=[sys.executable, path_to_action_server_executable],
66-
additional_env={'RMW_IMPLEMENTATION': rmw_implementation}
68+
additional_env=additional_env
6769
),
6870
launch_testing.actions.ReadyToTest()
6971
],
70-
additional_env={'RMW_IMPLEMENTATION': rmw_implementation}
72+
additional_env=additional_env
7173
)
7274
]
7375
),
@@ -86,13 +88,12 @@ def setUpClass(
8688
):
8789
@contextlib.contextmanager
8890
def launch_action_command(self, arguments):
91+
additional_env = get_rmw_additional_env(rmw_implementation)
92+
additional_env['PYTHONUNBUFFERED'] = '1'
8993
action_command_action = ExecuteProcess(
9094
cmd=['ros2', 'action', *arguments],
9195
name='ros2action-cli', output='screen',
92-
additional_env={
93-
'RMW_IMPLEMENTATION': rmw_implementation,
94-
'PYTHONUNBUFFERED': '1'
95-
}
96+
additional_env=additional_env
9697
)
9798
with launch_testing.tools.launch_process(
9899
launch_service, action_command_action, proc_info, proc_output,

ros2cli/ros2cli/helpers.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import sys
2020
import time
2121

22+
from typing import Dict
23+
2224

2325
def get_ros_domain_id():
2426
return int(os.environ.get('ROS_DOMAIN_ID', 0))
@@ -118,3 +120,18 @@ def collect_stdin():
118120
break
119121
lines += line
120122
return lines
123+
124+
125+
def get_rmw_additional_env(rmw_implementation: str) -> Dict[str, str]:
126+
"""Get a dictionary of additional environment variables based on rmw."""
127+
if rmw_implementation == 'rmw_zenoh_cpp':
128+
return {
129+
'RMW_IMPLEMENTATION': rmw_implementation,
130+
'ZENOH_ROUTER_CHECK_ATTEMPTS': '-1',
131+
'ZENOH_CONFIG_OVERRIDE': 'scouting/multicast/enabled=true',
132+
'RUST_LOG': 'z=error'
133+
}
134+
else:
135+
return {
136+
'RMW_IMPLEMENTATION': rmw_implementation,
137+
}

ros2doctor/test/test_qos_compatibility.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import pytest
3333

3434
from rclpy.utilities import get_available_rmw_implementations
35+
from ros2cli.helpers import get_rmw_additional_env
3536

3637

3738
# Skip cli tests on Windows while they exhibit pathological behavior
@@ -46,9 +47,8 @@
4647
@launch_testing.parametrize('rmw_implementation', get_available_rmw_implementations())
4748
def generate_test_description(rmw_implementation):
4849
path_to_fixtures = os.path.join(os.path.dirname(__file__), 'fixtures')
49-
additional_env = {
50-
'RMW_IMPLEMENTATION': rmw_implementation, 'PYTHONUNBUFFERED': '1'
51-
}
50+
additional_env = get_rmw_additional_env(rmw_implementation)
51+
additional_env['PYTHONUNBUFFERED'] = '1'
5252

5353
path_to_incompatible_talker_node_script = os.path.join(
5454
path_to_fixtures, 'talker_node_with_best_effort_qos.py')
@@ -128,12 +128,11 @@ def setUpClass(
128128

129129
@contextlib.contextmanager
130130
def launch_doctor_command(self, arguments):
131+
additional_env = get_rmw_additional_env(rmw_implementation)
132+
additional_env['PYTHONUNBUFFERED'] = '1'
131133
doctor_command_action = ExecuteProcess(
132134
cmd=['ros2', 'doctor', *arguments],
133-
additional_env={
134-
'RMW_IMPLEMENTATION': rmw_implementation,
135-
'PYTHONUNBUFFERED': '1'
136-
},
135+
additional_env=additional_env,
137136
name='ros2doctor-cli',
138137
output='screen'
139138
)

ros2lifecycle/test/test_cli.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import pytest
3131

3232
from rclpy.utilities import get_available_rmw_implementations
33+
from ros2cli.helpers import get_rmw_additional_env
3334

3435

3536
# Skip cli tests on Windows while they exhibit pathological behavior
@@ -122,7 +123,7 @@
122123
@pytest.mark.rostest
123124
@launch_testing.parametrize('rmw_implementation', get_available_rmw_implementations())
124125
def generate_test_description(rmw_implementation):
125-
additional_env = {'RMW_IMPLEMENTATION': rmw_implementation}
126+
additional_env = get_rmw_additional_env(rmw_implementation)
126127
return LaunchDescription([
127128
# Always restart daemon to isolate tests.
128129
ExecuteProcess(
@@ -169,12 +170,11 @@ def setUpClass(
169170
):
170171
@contextlib.contextmanager
171172
def launch_lifecycle_command(self, arguments):
173+
additional_env = get_rmw_additional_env(rmw_implementation)
174+
additional_env['PYTHONUNBUFFERED'] = '1'
172175
lifecycle_command_action = ExecuteProcess(
173176
cmd=['ros2', 'lifecycle', *arguments],
174-
additional_env={
175-
'RMW_IMPLEMENTATION': rmw_implementation,
176-
'PYTHONUNBUFFERED': '1'
177-
},
177+
additional_env=additional_env,
178178
name='ros2lifecycle-cli',
179179
output='screen'
180180
)

ros2node/test/test_cli.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import pytest
3535

3636
from rclpy.utilities import get_available_rmw_implementations
37+
from ros2cli.helpers import get_rmw_additional_env
3738

3839

3940
# Skip cli tests on Windows while they exhibit pathological behavior
@@ -50,7 +51,7 @@ def generate_test_description(rmw_implementation):
5051
path_to_complex_node_script = os.path.join(
5152
os.path.dirname(__file__), 'fixtures', 'complex_node.py'
5253
)
53-
additional_env = {'RMW_IMPLEMENTATION': rmw_implementation}
54+
additional_env = get_rmw_additional_env(rmw_implementation)
5455
return LaunchDescription([
5556
# Always restart daemon to isolate tests.
5657
ExecuteProcess(
@@ -95,12 +96,12 @@ def setUpClass(
9596
):
9697
@contextlib.contextmanager
9798
def launch_node_command(self, arguments):
99+
additional_env = get_rmw_additional_env(rmw_implementation)
100+
additional_env['PYTHONUNBUFFERED'] = '1'
101+
98102
node_command_action = ExecuteProcess(
99103
cmd=['ros2', 'node', *arguments],
100-
additional_env={
101-
'RMW_IMPLEMENTATION': rmw_implementation,
102-
'PYTHONUNBUFFERED': '1'
103-
},
104+
additional_env=additional_env,
104105
name='ros2node-cli',
105106
output='screen'
106107
)

ros2node/test/test_cli_duplicate_node_names.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import pytest
3333

3434
from rclpy.utilities import get_available_rmw_implementations
35+
from ros2cli.helpers import get_rmw_additional_env
3536
from ros2node.api import INFO_NONUNIQUE_WARNING_TEMPLATE
3637

3738

@@ -49,7 +50,7 @@ def generate_test_description(rmw_implementation):
4950
path_to_complex_node_script = os.path.join(
5051
os.path.dirname(__file__), 'fixtures', 'complex_node.py'
5152
)
52-
additional_env = {'RMW_IMPLEMENTATION': rmw_implementation}
53+
additional_env = get_rmw_additional_env(rmw_implementation)
5354
return LaunchDescription([
5455
# Always restart daemon to isolate tests.
5556
ExecuteProcess(
@@ -100,12 +101,11 @@ def setUpClass(
100101
):
101102
@contextlib.contextmanager
102103
def launch_node_command(self, arguments):
104+
additional_env = get_rmw_additional_env(rmw_implementation)
105+
additional_env['PYTHONUNBUFFERED'] = '1'
103106
node_command_action = ExecuteProcess(
104107
cmd=['ros2', 'node', *arguments],
105-
additional_env={
106-
'RMW_IMPLEMENTATION': rmw_implementation,
107-
'PYTHONUNBUFFERED': '1'
108-
},
108+
additional_env=additional_env,
109109
name='ros2node-cli',
110110
output='screen'
111111
)

ros2param/test/test_verb_dump.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
import rclpy
3535
from rclpy.utilities import get_available_rmw_implementations
36+
from ros2cli.helpers import get_rmw_additional_env
3637

3738
from ros2cli.node.strategy import NodeStrategy
3839

@@ -84,7 +85,7 @@
8485
@launch_testing.parametrize('rmw_implementation', get_available_rmw_implementations())
8586
def generate_test_description(rmw_implementation):
8687
path_to_fixtures = os.path.join(os.path.dirname(__file__), 'fixtures')
87-
additional_env = {'RMW_IMPLEMENTATION': rmw_implementation}
88+
additional_env = get_rmw_additional_env(rmw_implementation)
8889

8990
# Parameter node test fixture
9091
path_to_parameter_node_script = os.path.join(path_to_fixtures, 'parameter_node.py')
@@ -134,9 +135,7 @@ def setUpClass(
134135
def launch_param_dump_command(self, arguments):
135136
param_dump_command_action = ExecuteProcess(
136137
cmd=['ros2', 'param', 'dump', *arguments],
137-
additional_env={
138-
'RMW_IMPLEMENTATION': rmw_implementation,
139-
},
138+
additional_env=get_rmw_additional_env(rmw_implementation),
140139
name='ros2param-dump-cli',
141140
output='screen'
142141
)

ros2param/test/test_verb_list.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@
3434
import rclpy
3535
from rclpy.utilities import get_available_rmw_implementations
3636

37+
from ros2cli.helpers import get_rmw_additional_env
3738
from ros2cli.node.strategy import NodeStrategy
3839

40+
3941
TEST_NODE = 'test_node'
4042
TEST_NAMESPACE = '/foo'
4143

@@ -53,7 +55,7 @@
5355
@launch_testing.parametrize('rmw_implementation', get_available_rmw_implementations())
5456
def generate_test_description(rmw_implementation):
5557
path_to_fixtures = Path(__file__).parent / 'fixtures'
56-
additional_env = {'RMW_IMPLEMENTATION': rmw_implementation}
58+
additional_env = get_rmw_additional_env(rmw_implementation)
5759

5860
# Parameter node test fixture
5961
path_to_parameter_node_script = path_to_fixtures / 'parameter_node.py'
@@ -101,11 +103,10 @@ def setUpClass(
101103

102104
@contextlib.contextmanager
103105
def launch_param_list_command(self, arguments):
106+
additional_env = get_rmw_additional_env(rmw_implementation)
104107
param_list_command_action = ExecuteProcess(
105108
cmd=['ros2', 'param', 'list', *arguments],
106-
additional_env={
107-
'RMW_IMPLEMENTATION': rmw_implementation,
108-
},
109+
additional_env=additional_env,
109110
name='ros2param-list-cli',
110111
output='screen'
111112
)

ros2param/test/test_verb_load.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import rclpy
3636
from rclpy.utilities import get_available_rmw_implementations
3737

38+
from ros2cli.helpers import get_rmw_additional_env
3839
from ros2cli.node.strategy import NodeStrategy
3940

4041
import yaml
@@ -98,7 +99,7 @@
9899
@launch_testing.parametrize('rmw_implementation', get_available_rmw_implementations())
99100
def generate_test_description(rmw_implementation):
100101
path_to_fixtures = os.path.join(os.path.dirname(__file__), 'fixtures')
101-
additional_env = {'RMW_IMPLEMENTATION': rmw_implementation}
102+
additional_env = get_rmw_additional_env(rmw_implementation)
102103

103104
# Parameter node test fixture
104105
path_to_parameter_node_script = os.path.join(path_to_fixtures, 'parameter_node.py')
@@ -107,7 +108,7 @@ def generate_test_description(rmw_implementation):
107108
name=TEST_NODE,
108109
namespace=TEST_NAMESPACE,
109110
arguments=[path_to_parameter_node_script],
110-
additional_env=additional_env
111+
additional_env=additional_env,
111112
)
112113

113114
return LaunchDescription([
@@ -146,11 +147,10 @@ def setUpClass(
146147

147148
@contextlib.contextmanager
148149
def launch_param_load_command(self, arguments):
150+
additional_env = get_rmw_additional_env(rmw_implementation)
149151
param_load_command_action = ExecuteProcess(
150152
cmd=['ros2', 'param', 'load', *arguments],
151-
additional_env={
152-
'RMW_IMPLEMENTATION': rmw_implementation,
153-
},
153+
additional_env=additional_env,
154154
name='ros2param-load-cli',
155155
output='screen'
156156
)
@@ -163,11 +163,10 @@ def launch_param_load_command(self, arguments):
163163

164164
@contextlib.contextmanager
165165
def launch_param_dump_command(self, arguments):
166+
additional_env = get_rmw_additional_env(rmw_implementation)
166167
param_dump_command_action = ExecuteProcess(
167168
cmd=['ros2', 'param', 'dump', *arguments],
168-
additional_env={
169-
'RMW_IMPLEMENTATION': rmw_implementation,
170-
},
169+
additional_env=additional_env,
171170
name='ros2param-dump-cli',
172171
output='screen'
173172
)

0 commit comments

Comments
 (0)