|
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,197 @@ 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) |
| 607 | + |
| 608 | + @launch_testing.markers.retry_on_failure(times=5) |
| 609 | + def test_hz_content_filter_no_match(self, launch_service, proc_info, proc_output): |
| 610 | + topic = '/clitest/topic/hz_cfilter_nomatch' |
| 611 | + publisher = self.node.create_publisher(String, topic, 10) |
| 612 | + assert publisher |
| 613 | + |
| 614 | + def publish_message(): |
| 615 | + publisher.publish(String(data='hello')) |
| 616 | + |
| 617 | + publish_timer = self.node.create_timer(0.5, publish_message) |
| 618 | + |
| 619 | + # Wait for the publisher to be discovered |
| 620 | + publisher_count = 0 |
| 621 | + timeout_count = 0 |
| 622 | + while publisher_count == 0 and timeout_count < 10: |
| 623 | + self.executor.spin_once(timeout_sec=0.1) |
| 624 | + publisher_count = self.node.count_publishers(topic) |
| 625 | + timeout_count += 1 |
| 626 | + assert publisher_count > 0, 'Publisher was not discovered' |
| 627 | + |
| 628 | + try: |
| 629 | + command_action = ExecuteProcess( |
| 630 | + cmd=['ros2', 'topic', 'hz', |
| 631 | + '--content-filter', "data = 'NOMATCH'", |
| 632 | + topic], |
| 633 | + additional_env={ |
| 634 | + 'PYTHONUNBUFFERED': '1' |
| 635 | + }, |
| 636 | + output='screen' |
| 637 | + ) |
| 638 | + with launch_testing.tools.launch_process( |
| 639 | + launch_service, command_action, proc_info, proc_output, |
| 640 | + output_filter=launch_testing_ros.tools.basic_output_filter( |
| 641 | + filtered_rmw_implementation=get_rmw_implementation_identifier() |
| 642 | + ) |
| 643 | + ) as command: |
| 644 | + self.executor.spin_until_future_complete( |
| 645 | + rclpy.task.Future(), timeout_sec=5 |
| 646 | + ) |
| 647 | + command.wait_for_shutdown(timeout=10) |
| 648 | + # No messages should match, so no rate should be reported |
| 649 | + assert not re.search( |
| 650 | + r'^average rate:', command.output, flags=re.MULTILINE |
| 651 | + ), 'hz should not report rate when content filter rejects all messages' |
| 652 | + finally: |
| 653 | + self.node.destroy_timer(publish_timer) |
| 654 | + self.node.destroy_publisher(publisher) |
| 655 | + |
| 656 | + @launch_testing.markers.retry_on_failure(times=5) |
| 657 | + def test_bw_content_filter_no_match(self, launch_service, proc_info, proc_output): |
| 658 | + topic = '/clitest/topic/bw_cfilter_nomatch' |
| 659 | + publisher = self.node.create_publisher(String, topic, 10) |
| 660 | + assert publisher |
| 661 | + |
| 662 | + def publish_message(): |
| 663 | + publisher.publish(String(data='hello')) |
| 664 | + |
| 665 | + publish_timer = self.node.create_timer(0.5, publish_message) |
| 666 | + |
| 667 | + # Wait for the publisher to be discovered |
| 668 | + publisher_count = 0 |
| 669 | + timeout_count = 0 |
| 670 | + while publisher_count == 0 and timeout_count < 10: |
| 671 | + self.executor.spin_once(timeout_sec=0.1) |
| 672 | + publisher_count = self.node.count_publishers(topic) |
| 673 | + timeout_count += 1 |
| 674 | + assert publisher_count > 0, 'Publisher was not discovered' |
| 675 | + |
| 676 | + try: |
| 677 | + command_action = ExecuteProcess( |
| 678 | + cmd=['ros2', 'topic', 'bw', |
| 679 | + '--content-filter', "data = 'NOMATCH'", |
| 680 | + topic], |
| 681 | + additional_env={ |
| 682 | + 'PYTHONUNBUFFERED': '1' |
| 683 | + }, |
| 684 | + output='screen' |
| 685 | + ) |
| 686 | + with launch_testing.tools.launch_process( |
| 687 | + launch_service, command_action, proc_info, proc_output, |
| 688 | + output_filter=launch_testing_ros.tools.basic_output_filter( |
| 689 | + filtered_rmw_implementation=get_rmw_implementation_identifier() |
| 690 | + ) |
| 691 | + ) as command: |
| 692 | + self.executor.spin_until_future_complete( |
| 693 | + rclpy.task.Future(), timeout_sec=5 |
| 694 | + ) |
| 695 | + command.wait_for_shutdown(timeout=10) |
| 696 | + # No messages should match, so no bandwidth should be reported |
| 697 | + assert not re.search( |
| 698 | + r'^[0-9]+ B/s', command.output, flags=re.MULTILINE |
| 699 | + ), 'bw should not report bandwidth when content filter rejects all messages' |
| 700 | + finally: |
| 701 | + self.node.destroy_timer(publish_timer) |
| 702 | + self.node.destroy_publisher(publisher) |
0 commit comments