def setup(): global async_launcher default_launcher = DefaultLauncher() launch_file = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'launch_counter.py') launch_descriptor = LaunchDescriptor() load_launch_file(launch_file, launch_descriptor, {}) default_launcher.add_launch_descriptor(launch_descriptor) async_launcher = AsynchronousLauncher(default_launcher) async_launcher.start()
def test_interrupt_asynchronous_launcher(): desc = LaunchDescriptor() desc.add_process( cmd=[sys.executable, '-c', 'import time', 'time.sleep(30)'], name='test_interrupt_asynchronous_launcher__python_blocking' ) launcher = DefaultLauncher() launcher.add_launch_descriptor(desc) async_launcher = AsynchronousLauncher(launcher) async_launcher.start() # wait up to 10 seconds to get to the point where at least all of the # asyncio-subprocess coroutines have been run (the processes are still # not guaranteed to be running yet) launcher.wait_on_processes_to_spawn(10) if not launcher.are_processes_spawned(): # if the processes didn't launch after 10 seconds, fail the test assert False, 'launcher never reported processes launched' async_launcher.terminate() # now wait for the launcher to finish and error if if doesn't async_launcher.join(60) if async_launcher.is_alive(): # if still running fail the test assert False, 'async launcher failed to shutdown'
def test_talker_listener(): launch_desc = LaunchDescriptor() launch_desc.add_process( cmd=[sys.executable, os.path.join(this_dir, 'talker.py')], name='test_talker_listener__talker' ) launcher = DefaultLauncher() launcher.add_launch_descriptor(launch_desc) async_launcher = AsynchronousLauncher(launcher) async_launcher.start() import rclpy rclpy.init([]) from rclpy.qos import qos_profile_default from std_msgs.msg import String assert String.__class__._TYPE_SUPPORT is not None node = rclpy.create_node('listener') received_messages = [] chatter_callback = functools.partial( listener_callback, received_messages=received_messages) # TODO(wjwwood): should the subscription object hang around? node.create_subscription(String, 'chatter', chatter_callback, qos_profile_default) spin_count = 0 while len(received_messages) == 0 and spin_count < 10 and launcher.is_launch_running(): rclpy.spin_once(node) # This will wait 1 second or until something has been done. spin_count += 1 async_launcher.terminate() async_launcher.join() assert len(received_messages) > 0, "Should have received a message from talker"