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

Wait for daemon shutdown before testing NodeStrategy #620

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 19 additions & 0 deletions ros2cli/ros2cli/node/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,24 @@ def __exit__(self, exc_type, exc_value, traceback):
self._proxy.__exit__(exc_type, exc_value, traceback)


def shutdown_daemon(args, wait_until_shutdown=None):
with DaemonNode(args) as node:
node.system.shutdown()

if wait_until_shutdown is None:
return True

if wait_until_shutdown > 0.0:
timeout = time.time() + wait_until_shutdown
else:
timeout = None

while is_daemon_running(args):
time.sleep(0.1)
if timeout and time.time() >= timeout:
return False
return True


def add_arguments(parser):
pass
7 changes: 2 additions & 5 deletions ros2cli/test/test_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@

import pytest

from ros2cli.node.daemon import DaemonNode
from ros2cli.node.daemon import is_daemon_running
from ros2cli.node.daemon import shutdown_daemon
from ros2cli.node.daemon import spawn_daemon
from ros2cli.node.strategy import NodeStrategy


@pytest.fixture
def enforce_no_daemon_is_running():
if is_daemon_running(args=[]):
with DaemonNode(args=[]) as node:
node.system.shutdown()
assert shutdown_daemon(args=[], wait_until_shutdown=5.0)
yield


Expand All @@ -53,8 +52,6 @@ def test_with_no_daemon_running(enforce_no_daemon_is_running):


def test_enforce_no_daemon(enforce_daemon_is_running):
if not is_daemon_running(args=[]):
assert spawn_daemon(args=[], wait_until_spawned=5.0)
args = argparse.Namespace(no_daemon=True)
with NodeStrategy(args=args) as node:
assert node._daemon_node is None
Expand Down