|
43 | 43 | from rclpy.qos import ReliabilityPolicy |
44 | 44 | from rclpy.utilities import get_rmw_implementation_identifier |
45 | 45 |
|
| 46 | +from std_msgs.msg import String |
| 47 | + |
46 | 48 |
|
47 | 49 | # Skip cli tests on Windows while they exhibit pathological behavior |
48 | 50 | # https://github.com/ros2/build_farmer/issues/248 |
@@ -504,3 +506,101 @@ def test_bw_both_all_and_topics_error(self, launch_service, proc_info, proc_outp |
504 | 506 | assert 'Cannot specify both --all/-a and topic names' in command.output, ( |
505 | 507 | 'bw command did not print expected error message' |
506 | 508 | ) |
| 509 | + |
| 510 | + @launch_testing.markers.retry_on_failure(times=5) |
| 511 | + def test_hz_content_filter(self, launch_service, proc_info, proc_output): |
| 512 | + topic = '/clitest/topic/hz_content_filter' |
| 513 | + publisher = self.node.create_publisher(String, topic, 10) |
| 514 | + assert publisher |
| 515 | + |
| 516 | + def publish_message(): |
| 517 | + publisher.publish(String(data='hello')) |
| 518 | + |
| 519 | + publish_timer = self.node.create_timer(0.5, publish_message) |
| 520 | + |
| 521 | + # Wait for the publisher to be discovered |
| 522 | + publisher_count = 0 |
| 523 | + timeout_count = 0 |
| 524 | + while publisher_count == 0 and timeout_count < 10: |
| 525 | + self.executor.spin_once(timeout_sec=0.1) |
| 526 | + publisher_count = self.node.count_publishers(topic) |
| 527 | + timeout_count += 1 |
| 528 | + assert publisher_count > 0, 'Publisher was not discovered' |
| 529 | + |
| 530 | + try: |
| 531 | + command_action = ExecuteProcess( |
| 532 | + cmd=['ros2', 'topic', 'hz', |
| 533 | + '--content-filter', "data = 'hello'", |
| 534 | + topic], |
| 535 | + additional_env={ |
| 536 | + 'PYTHONUNBUFFERED': '1' |
| 537 | + }, |
| 538 | + output='screen' |
| 539 | + ) |
| 540 | + with launch_testing.tools.launch_process( |
| 541 | + launch_service, command_action, proc_info, proc_output, |
| 542 | + output_filter=launch_testing_ros.tools.basic_output_filter( |
| 543 | + filtered_rmw_implementation=get_rmw_implementation_identifier() |
| 544 | + ) |
| 545 | + ) as command: |
| 546 | + # The future won't complete - we will hit the timeout |
| 547 | + self.executor.spin_until_future_complete( |
| 548 | + rclpy.task.Future(), timeout_sec=5 |
| 549 | + ) |
| 550 | + command.wait_for_shutdown(timeout=10) |
| 551 | + assert command.output, 'hz with content filter printed no output' |
| 552 | + assert re.search( |
| 553 | + r'^average rate: [0-9\.]+$', command.output, flags=re.MULTILINE |
| 554 | + ), 'hz with content filter did not print expected rate' |
| 555 | + finally: |
| 556 | + self.node.destroy_timer(publish_timer) |
| 557 | + self.node.destroy_publisher(publisher) |
| 558 | + |
| 559 | + @launch_testing.markers.retry_on_failure(times=5) |
| 560 | + def test_bw_content_filter(self, launch_service, proc_info, proc_output): |
| 561 | + topic = '/clitest/topic/bw_content_filter' |
| 562 | + publisher = self.node.create_publisher(String, topic, 10) |
| 563 | + assert publisher |
| 564 | + |
| 565 | + def publish_message(): |
| 566 | + publisher.publish(String(data='hello')) |
| 567 | + |
| 568 | + publish_timer = self.node.create_timer(0.5, publish_message) |
| 569 | + |
| 570 | + # Wait for the publisher to be discovered |
| 571 | + publisher_count = 0 |
| 572 | + timeout_count = 0 |
| 573 | + while publisher_count == 0 and timeout_count < 10: |
| 574 | + self.executor.spin_once(timeout_sec=0.1) |
| 575 | + publisher_count = self.node.count_publishers(topic) |
| 576 | + timeout_count += 1 |
| 577 | + assert publisher_count > 0, 'Publisher was not discovered' |
| 578 | + |
| 579 | + try: |
| 580 | + command_action = ExecuteProcess( |
| 581 | + cmd=['ros2', 'topic', 'bw', |
| 582 | + '--content-filter', "data = 'hello'", |
| 583 | + topic], |
| 584 | + additional_env={ |
| 585 | + 'PYTHONUNBUFFERED': '1' |
| 586 | + }, |
| 587 | + output='screen' |
| 588 | + ) |
| 589 | + with launch_testing.tools.launch_process( |
| 590 | + launch_service, command_action, proc_info, proc_output, |
| 591 | + output_filter=launch_testing_ros.tools.basic_output_filter( |
| 592 | + filtered_rmw_implementation=get_rmw_implementation_identifier() |
| 593 | + ) |
| 594 | + ) as command: |
| 595 | + # The future won't complete - we will hit the timeout |
| 596 | + self.executor.spin_until_future_complete( |
| 597 | + rclpy.task.Future(), timeout_sec=5 |
| 598 | + ) |
| 599 | + command.wait_for_shutdown(timeout=10) |
| 600 | + assert command.output, 'bw with content filter printed no output' |
| 601 | + assert re.search( |
| 602 | + r'^[0-9]+ B/s from [0-9]+ messages$', command.output, flags=re.MULTILINE |
| 603 | + ), 'bw with content filter did not print expected bandwidth' |
| 604 | + finally: |
| 605 | + self.node.destroy_timer(publish_timer) |
| 606 | + self.node.destroy_publisher(publisher) |
0 commit comments