|
30 | 30 |
|
31 | 31 | import os |
32 | 32 | import pytest |
| 33 | +import psutil |
| 34 | +import subprocess |
| 35 | +import time |
33 | 36 | import unittest |
34 | 37 |
|
35 | 38 | from ament_index_python.packages import get_package_share_directory |
|
39 | 42 | from launch_testing.actions import ReadyToTest |
40 | 43 |
|
41 | 44 | import launch_testing.markers |
42 | | -import rclpy |
43 | 45 | from controller_manager.test_utils import ( |
44 | 46 | check_controllers_running, |
45 | 47 | check_if_js_published, |
46 | 48 | check_node_running, |
47 | 49 | ) |
| 50 | +import rclpy |
48 | 51 |
|
49 | 52 |
|
50 | 53 | # Executes the given launch file and checks if all nodes can be started |
@@ -94,6 +97,30 @@ def test_check_if_msgs_published(self): |
94 | 97 | "/joint_states", ["joint_1", "joint_2", "joint_3", "joint_4", "joint_5", "joint_6"] |
95 | 98 | ) |
96 | 99 |
|
| 100 | + def test_check_if_trajectory_published(self, proc_output): |
| 101 | + |
| 102 | + topic = "/r6bot_controller/joint_trajectory" |
| 103 | + |
| 104 | + command = [ |
| 105 | + "ros2", |
| 106 | + "launch", |
| 107 | + "ros2_control_demo_example_7", |
| 108 | + "send_trajectory.launch.py", |
| 109 | + ] |
| 110 | + subprocess.Popen(command) # the process won't finish |
| 111 | + time.sleep(1) |
| 112 | + pubs = self.node.get_publishers_info_by_topic(topic) |
| 113 | + assert len(pubs) > 0, f"No publisher for topic '{topic}' not found!" |
| 114 | + |
| 115 | + # message will be published only once, so WaitForTopics is not suitable here. |
| 116 | + # let's just check if the controller received and processed the message |
| 117 | + proc_output.assertWaitFor("Trajectory execution complete", timeout=10, stream="stderr") |
| 118 | + |
| 119 | + for proc in psutil.process_iter(): |
| 120 | + if "send_trajectory" in proc.name(): |
| 121 | + proc.kill() |
| 122 | + print(f"Process {proc.name()} killed") |
| 123 | + |
97 | 124 |
|
98 | 125 | @launch_testing.post_shutdown_test() |
99 | 126 | # These tests are run after the processes in generate_test_description() have shutdown. |
|
0 commit comments