Skip to content

Commit

Permalink
Save method list via connection check to XMLRPC server. (#796)
Browse files Browse the repository at this point in the history
Signed-off-by: Tomoya Fujita <Tomoya.Fujita@sony.com>
  • Loading branch information
fujitatomoya authored and DLu committed Feb 1, 2023
1 parent 0c0b27e commit da368b4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
12 changes: 6 additions & 6 deletions ros2cli/ros2cli/node/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ def __init__(self, args):
@property
def connected(self):
try:
self._proxy.system.listMethods()
self._methods = [
method
for method in self._proxy.system.listMethods()
if not method.startswith('system.')
]
except ConnectionRefusedError:
return False
return True

@property
def methods(self):
return [
method
for method in self._proxy.system.listMethods()
if not method.startswith('system.')
]
return self._methods

def __enter__(self):
self._proxy.__enter__()
Expand Down
3 changes: 3 additions & 0 deletions ros2cli/ros2cli/node/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ def __init__(self, args):
if use_daemon and is_daemon_running(args):
self._daemon_node = DaemonNode(args)
self._direct_node = None
if not self._daemon_node.connected:
self._direct_node = DirectNode(args)
self._daemon_node = None
else:
if use_daemon:
spawn_daemon(args)
Expand Down
4 changes: 4 additions & 0 deletions ros2cli/test/test_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ def daemon_node():
assert shutdown_daemon(args=[], timeout=5.0)
assert spawn_daemon(args=[], timeout=5.0)
with DaemonNode(args=[]) as node:
if not node.connected:
pytest.fail(
f'failed to connect daemon {TEST_NODE_NAMESPACE}/{TEST_NODE_NAME}'
)
attempts = 3
delay_between_attempts = 2 # seconds
for _ in range(attempts):
Expand Down
10 changes: 10 additions & 0 deletions ros2cli/test/test_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ def test_with_daemon_running(enforce_daemon_is_running):
assert direct is not None


def test_with_daemon_spawn(enforce_no_daemon_is_running):
with NodeStrategy(args=[]) as node:
assert node._daemon_node is None
assert node._direct_node is not None
# Daemon should be spawned by NodeStrategy call above
with NodeStrategy(args=[]) as node:
assert node._daemon_node is not None
assert node._direct_node is None


def test_with_no_daemon_running(enforce_no_daemon_is_running):
with NodeStrategy(args=[]) as node:
assert node._daemon_node is None
Expand Down

0 comments on commit da368b4

Please sign in to comment.