Check output node using launch_test

asked 2019-09-02 09:51:55 -0500

hect1995 gravatar image

updated 2019-09-06 06:00:21 -0500

I have a launch file for executing a certain test called sm_process_test.launch.py. The test consists on launching a node called simulation_node and check that this node outputs something from self.get_logger().info('...'). For doing that I have followed the tutorial in https://github.com/ros2/launch/tree/m....

My files look like this:

sm_process_test.launch.py:

import os
import unittest

import pytest
from ament_index_python import get_package_prefix
# ROS imports
from launch import LaunchDescription
from launch.actions import ExecuteProcess, DeclareLaunchArgument, OpaqueFunction

TEST_PROC_PATH = os.path.join(
    get_package_prefix('simulation_pkg'),
    'lib/simulation_pkg',
    'simulation_node'
)

proc_env = os.environ.copy()
proc_env['PYTHONUNBUFFERED'] = '1'
MAP = 'T2'

simulation_process = ExecuteProcess(
    cmd=[TEST_PROC_PATH, '{0}'.format(MAP)],
    env=proc_env
)


@pytest.mark.rostest
def generate_test_description(ready_fn):
    ld = LaunchDescription([
        simulation_process,
    ])
    OpaqueFunction(function=lambda context: ready_fn()),
    return ld


class TestGoodProcess(unittest.TestCase):

    def test_receive_coordinates(self):
        # This will match stdout from any process.  In this example there is only one process
        # running
        self.proc_output.assertWaitFor('Simulation Server Initialized..!', timeout=10)

simulation_node.py

class SimulationServer(Node):

    def __init__(self, track='T2'):
        super().__init__('simulation_server')
        self.get_logger().info('Simulation Server Initialized..!')

def main(argv=sys.argv[1:]):
    rclpy.init(args=None)
    minimal_action_server = SimulationServer(argv)
    rclpy.spin(minimal_action_server)
    minimal_action_server.destroy()
    rclpy.shutdown()


if __name__ == '__main__':
    main()

The output I get from terminal is the following:

    [INFO] [launch]: All log files can be found below /home/developer/.ros/log/2019-09-06-12-08-27-672629-bionic-base-13375
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [simulation_node-1]: process started with pid [13380]
Timed out waiting for processes to start up
[INFO] [simulation_node-1]: sending signal 'SIGINT' to process[simulation_node-1]
[simulation_node-1] Traceback (most recent call last):
[simulation_node-1]   File "/home/developer/task-manager/ros2_ws/install/simulation_pkg/lib/simulation_pkg/simulation_node", line 11, in <module>
[simulation_node-1]     load_entry_point('simulation-pkg', 'console_scripts', 'simulation_node')()
[simulation_node-1]   File "/home/developer/task-manager/ros2_ws/build/simulation_pkg/simulation_pkg/simulation_node.py", line 110, in main
[simulation_node-1]     rclpy.spin(minimal_action_server)
[simulation_node-1]   File "/opt/ros/dashing/lib/python3.6/site-packages/rclpy/__init__.py", line 189, in spin
[simulation_node-1]     executor.spin_once()
[simulation_node-1]   File "/opt/ros/dashing/lib/python3.6/site-packages/rclpy/executors.py", line 663, in spin_once
[simulation_node-1]     handler, entity, node = self.wait_for_ready_callbacks(timeout_sec=timeout_sec)
[simulation_node-1]   File "/opt/ros/dashing/lib/python3.6/site-packages/rclpy/executors.py", line 649, in wait_for_ready_callbacks
[simulation_node-1]     return next(self._cb_iter)
[simulation_node-1]   File "/opt/ros/dashing/lib/python3.6/site-packages/rclpy/executors.py", line 549, in _wait_for_ready_callbacks
[simulation_node-1]     _rclpy.rclpy_wait(wait_set, timeout_nsec)
[simulation_node-1] KeyboardInterrupt
[ERROR] [simulation_node-1]: process has died [pid 13380, exit code 1, cmd '/home/developer/task-manager/ros2_ws/install/simulation_pkg/lib/simulation_pkg/simulation_node T2'].
Processes under test stopped before tests completed
Process 'simulation_node-1' exited with 1
##### 'simulation_node-1' output #####
[INFO] [simulation_server]: Simulation Server Initialized..!
Simulation Server Initialized..!

Result directory - /home/developer/task-manager/ros2_ws/src/simulation/simulation_pkg/../../../results - already exist, removed and created it again!

Traceback (most recent call last):
  File "/home/developer/task-manager/ros2_ws/install/simulation_pkg/lib/simulation_pkg/simulation_node", line 11, in <module>

    load_entry_point('simulation-pkg', 'console_scripts', 'simulation_node')()
  File "/home/developer/task-manager/ros2_ws/build/simulation_pkg/simulation_pkg/simulation_node.py", line 110, in main
    rclpy.spin(minimal_action_server)
  File "/opt/ros/dashing/lib/python3.6/site-packages/rclpy/__init__.py", line 189, in spin ...
(more)
edit retag flag offensive close merge delete