|
43 | 43 |
|
44 | 44 |
|
45 | 45 | TEST_TOPIC = '/dynamic_param_topic' |
| 46 | +NEW_TOPIC = '/new_param_topic' |
46 | 47 | TEST_FREQUENCY = 30.0 |
47 | 48 |
|
48 | 49 |
|
@@ -89,20 +90,23 @@ def make_tol_param(topic: str) -> str: |
89 | 90 | def generate_test_description(): |
90 | 91 | """Test dynamic parameter changes via ros2 param set.""" |
91 | 92 | ros2_monitor_node = create_monitor_node( |
92 | | - namespace=MONITOR_NODE_NAMESPACE, |
93 | | - node_name=MONITOR_NODE_NAME, |
94 | | - topics=[TEST_TOPIC], # Topic exists but no expected frequency |
95 | | - topic_configs={} |
| 93 | + topics=[TEST_TOPIC] # Topic exists but no expected frequency |
96 | 94 | ) |
97 | 95 |
|
98 | 96 | publisher = create_minimal_publisher( |
99 | 97 | TEST_TOPIC, TEST_FREQUENCY, 'imu', '_dynamic' |
100 | 98 | ) |
101 | 99 |
|
| 100 | + # Publisher for topic not initially monitored |
| 101 | + new_topic_publisher = create_minimal_publisher( |
| 102 | + NEW_TOPIC, TEST_FREQUENCY, 'imu', '_new_dynamic' |
| 103 | + ) |
| 104 | + |
102 | 105 | return ( |
103 | 106 | launch.LaunchDescription([ |
104 | 107 | ros2_monitor_node, |
105 | 108 | publisher, |
| 109 | + new_topic_publisher, |
106 | 110 | launch_testing.actions.ReadyToTest() |
107 | 111 | ]), {} |
108 | 112 | ) |
@@ -194,6 +198,36 @@ def test_verify_params_with_get(self): |
194 | 198 | msg=f'Tolerance mismatch: expected {expected_tol}, got {actual_tol}' |
195 | 199 | ) |
196 | 200 |
|
| 201 | + def test_add_new_topic_via_param(self): |
| 202 | + """Test that setting frequency param for unmonitored topic starts monitoring.""" |
| 203 | + time.sleep(1.0) |
| 204 | + |
| 205 | + # Verify topic is not initially monitored |
| 206 | + initial_diagnostics = collect_diagnostics_for_topic( |
| 207 | + self.test_node, NEW_TOPIC, expected_count=1, timeout_sec=2.0 |
| 208 | + ) |
| 209 | + self.assertEqual( |
| 210 | + len(initial_diagnostics), 0, |
| 211 | + f'{NEW_TOPIC} should not be monitored initially' |
| 212 | + ) |
| 213 | + |
| 214 | + # Set expected frequency for the new topic |
| 215 | + freq_param = make_freq_param(NEW_TOPIC) |
| 216 | + success = run_ros2_param_set(MONITOR_NODE_NAME, freq_param, TEST_FREQUENCY) |
| 217 | + self.assertTrue(success, f'Failed to set {freq_param}') |
| 218 | + |
| 219 | + time.sleep(2.0) |
| 220 | + |
| 221 | + # Verify topic is now monitored |
| 222 | + received_diagnostics = collect_diagnostics_for_topic( |
| 223 | + self.test_node, NEW_TOPIC, expected_count=3, timeout_sec=10.0 |
| 224 | + ) |
| 225 | + |
| 226 | + self.assertGreaterEqual( |
| 227 | + len(received_diagnostics), 3, |
| 228 | + f'{NEW_TOPIC} should be monitored after setting frequency param' |
| 229 | + ) |
| 230 | + |
197 | 231 |
|
198 | 232 | if __name__ == '__main__': |
199 | 233 | unittest.main() |
0 commit comments