Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ros2param] Wait for discovery before running tests #481

Merged
merged 2 commits into from
Apr 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion ros2param/test/test_verb_dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,22 @@
import os
import tempfile
import threading
import time
import unittest
from unittest.mock import patch
import xmlrpc

import rclpy
from rclpy.executors import MultiThreadedExecutor
from rclpy.parameter import PARAMETER_SEPARATOR_STRING

from ros2cli import cli
from ros2cli.node.strategy import NodeStrategy

TEST_NODE = 'test_node'
TEST_NAMESPACE = 'foo'
TEST_NAMESPACE = '/foo'
jacobperron marked this conversation as resolved.
Show resolved Hide resolved

TEST_TIMEOUT = 5.0

EXPECTED_PARAMETER_FILE = """\
test_node:
Expand Down Expand Up @@ -77,6 +82,32 @@ def tearDownClass(cls):
rclpy.shutdown(context=cls.context)
cls.exec_thread.join()

def setUp(self):
# Ensure the daemon node is running and discovers the test node
start_time = time.time()
timed_out = True
with NodeStrategy(None) as node:
while (time.time() - start_time) < TEST_TIMEOUT:
# TODO(jacobperron): Create a generic 'CliNodeError' so we can treat errors
# from DirectNode and DaemonNode the same
try:
services = node.get_service_names_and_types_by_node(TEST_NODE, TEST_NAMESPACE)
except rclpy.node.NodeNameNonExistentError:
continue
except xmlrpc.client.Fault as e:
if 'NodeNameNonExistentError' in e.faultString:
continue
raise

service_names = [name_type_tuple[0] for name_type_tuple in services]
if (
len(service_names) > 0
and f'{TEST_NAMESPACE}/{TEST_NODE}/get_parameters' in service_names
):
timed_out = False
jacobperron marked this conversation as resolved.
Show resolved Hide resolved
if timed_out:
self.fail(f'CLI daemon failed to find test node after {TEST_TIMEOUT} seconds')

def _output_file(self):

ns = self.node.get_namespace()
Expand Down