|
51 | 51 | from rclpy.qos import QoSProfile
|
52 | 52 | from rclpy.qos import QoSReliabilityPolicy
|
53 | 53 | from rclpy.time_source import USE_SIM_TIME_NAME
|
| 54 | +from rclpy.topic_endpoint_info import TopicEndpointTypeEnum |
54 | 55 | from rclpy.type_description_service import START_TYPE_DESCRIPTION_SERVICE_PARAM
|
55 | 56 | from rclpy.utilities import get_rmw_implementation_identifier
|
56 | 57 | from test_msgs.msg import BasicTypes
|
| 58 | +from test_msgs.srv import Empty |
57 | 59 |
|
58 | 60 | TEST_NODE = 'my_node'
|
59 | 61 | TEST_NAMESPACE = '/my_ns'
|
@@ -311,6 +313,86 @@ def test_get_publishers_subscriptions_info_by_topic(self):
|
311 | 313 | self.node.get_subscriptions_info_by_topic('13')
|
312 | 314 | self.node.get_publishers_info_by_topic('13')
|
313 | 315 |
|
| 316 | + def test_get_clients_servers_info_by_service(self): |
| 317 | + service_name = 'test_service_endpoint_info' |
| 318 | + fq_service_name = '{namespace}/{name}'.format(namespace=TEST_NAMESPACE, name=service_name) |
| 319 | + # Lists should be empty |
| 320 | + self.assertFalse(self.node.get_clients_info_by_service(fq_service_name)) |
| 321 | + self.assertFalse(self.node.get_servers_info_by_service(fq_service_name)) |
| 322 | + |
| 323 | + # Add a client |
| 324 | + qos_profile = QoSProfile( |
| 325 | + depth=10, |
| 326 | + history=QoSHistoryPolicy.KEEP_ALL, |
| 327 | + deadline=Duration(seconds=1, nanoseconds=12345), |
| 328 | + lifespan=Duration(seconds=20, nanoseconds=9887665), |
| 329 | + reliability=QoSReliabilityPolicy.BEST_EFFORT, |
| 330 | + durability=QoSDurabilityPolicy.TRANSIENT_LOCAL, |
| 331 | + liveliness_lease_duration=Duration(seconds=5, nanoseconds=23456), |
| 332 | + liveliness=QoSLivelinessPolicy.MANUAL_BY_TOPIC) |
| 333 | + self.node.create_client(Empty, service_name, qos_profile=qos_profile) |
| 334 | + # List should have at least one item |
| 335 | + client_list = self.node.get_clients_info_by_service(fq_service_name) |
| 336 | + self.assertGreaterEqual(len(client_list), 1) |
| 337 | + # Server list should be empty |
| 338 | + self.assertFalse(self.node.get_servers_info_by_service(fq_service_name)) |
| 339 | + # Verify client list has the right data |
| 340 | + for client in client_list: |
| 341 | + self.assertEqual(self.node.get_name(), client.node_name) |
| 342 | + self.assertEqual(self.node.get_namespace(), client.node_namespace) |
| 343 | + assert 'test_msgs/srv/Empty' in client.topic_type |
| 344 | + if 'test_msgs/srv/Empty_Request' == client.topic_type: |
| 345 | + actual_qos_profile = client.qos_profile |
| 346 | + assert client.endpoint_type == TopicEndpointTypeEnum.PUBLISHER |
| 347 | + self.assert_qos_equal(qos_profile, actual_qos_profile, is_publisher=True) |
| 348 | + elif 'test_msgs/srv/Empty_Response' == client.topic_type: |
| 349 | + actual_qos_profile = client.qos_profile |
| 350 | + assert client.endpoint_type == TopicEndpointTypeEnum.SUBSCRIPTION |
| 351 | + self.assert_qos_equal(qos_profile, actual_qos_profile, is_publisher=False) |
| 352 | + |
| 353 | + # Add a server |
| 354 | + qos_profile2 = QoSProfile( |
| 355 | + depth=1, |
| 356 | + history=QoSHistoryPolicy.KEEP_LAST, |
| 357 | + deadline=Duration(seconds=15, nanoseconds=1678), |
| 358 | + lifespan=Duration(seconds=29, nanoseconds=2345), |
| 359 | + reliability=QoSReliabilityPolicy.RELIABLE, |
| 360 | + durability=QoSDurabilityPolicy.VOLATILE, |
| 361 | + liveliness_lease_duration=Duration(seconds=5, nanoseconds=23456), |
| 362 | + liveliness=QoSLivelinessPolicy.AUTOMATIC) |
| 363 | + self.node.create_service( |
| 364 | + Empty, |
| 365 | + service_name, |
| 366 | + lambda msg: print(msg), |
| 367 | + qos_profile=qos_profile2 |
| 368 | + ) |
| 369 | + # Both lists should have at least one item |
| 370 | + client_list = self.node.get_clients_info_by_service(fq_service_name) |
| 371 | + server_list = self.node.get_servers_info_by_service(fq_service_name) |
| 372 | + self.assertGreaterEqual(len(client_list), 1) |
| 373 | + self.assertGreaterEqual(len(server_list), 1) |
| 374 | + # Verify server list has the right data |
| 375 | + for server in server_list: |
| 376 | + self.assertEqual(self.node.get_name(), server.node_name) |
| 377 | + self.assertEqual(self.node.get_namespace(), server.node_namespace) |
| 378 | + assert 'test_msgs/srv/Empty' in server.topic_type |
| 379 | + if 'test_msgs/srv/Empty_Request' == server.topic_type: |
| 380 | + actual_qos_profile = server.qos_profile |
| 381 | + assert server.endpoint_type == TopicEndpointTypeEnum.SUBSCRIPTION |
| 382 | + self.assert_qos_equal(qos_profile2, actual_qos_profile, is_publisher=False) |
| 383 | + elif 'test_msgs/srv/Empty_Response' == server.topic_type: |
| 384 | + actual_qos_profile = server.qos_profile |
| 385 | + assert server.endpoint_type == TopicEndpointTypeEnum.PUBLISHER |
| 386 | + self.assert_qos_equal(qos_profile2, actual_qos_profile, is_publisher=True) |
| 387 | + |
| 388 | + # Error cases |
| 389 | + with self.assertRaises(TypeError): |
| 390 | + self.node.get_clients_info_by_service(1) |
| 391 | + self.node.get_servers_info_by_service(1) |
| 392 | + with self.assertRaisesRegex(ValueError, 'is invalid'): |
| 393 | + self.node.get_clients_info_by_service('13') |
| 394 | + self.node.get_servers_info_by_service('13') |
| 395 | + |
314 | 396 | def test_count_publishers_subscribers(self):
|
315 | 397 | short_topic_name = 'chatter'
|
316 | 398 | fq_topic_name = '%s/%s' % (TEST_NAMESPACE, short_topic_name)
|
|
0 commit comments