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

Add timeout for ReadyToTest action #622

Closed
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
8 changes: 6 additions & 2 deletions launch_testing/launch_testing/launch_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ def add_arguments(parser):
'--junit-xml', action='store', dest='xmlpath', default=None,
help='Do write xUnit reports to specified path.'
)

parser.add_argument(
'--timeout', type=float, default=15.0,
help='timeout for ReadyToTest action'
deepanshubansal01 marked this conversation as resolved.
Show resolved Hide resolved
)

def parse_arguments():
parser = argparse.ArgumentParser(
Expand Down Expand Up @@ -92,7 +95,8 @@ def run(parser, args, test_runner_cls=LaunchTestRunner):
runner = test_runner_cls(
test_runs=test_runs,
launch_file_arguments=args.launch_arguments,
debug=args.verbose
debug=args.verbose,
timeout=args.timeout
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit (in this way, the diff will not show one deleted line next time):

Suggested change
timeout=args.timeout
timeout=args.timeout,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

)

_logger_.debug('Validating test configuration')
Expand Down
13 changes: 9 additions & 4 deletions launch_testing/launch_testing/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ def __init__(self,
test_run,
test_run_preamble,
launch_file_arguments=[],
debug=False):
debug=False,
timeout=15.0):
self._test_run = test_run
self._test_run_preamble = test_run_preamble
self._launch_service = LaunchService(debug=debug)
self._processes_launched = threading.Event() # To signal when all processes started
self._tests_completed = threading.Event() # To signal when all the tests have finished
self._launch_file_arguments = launch_file_arguments
self._timeout = timeout # timeout for ReadyToTest Action

# Can't run LaunchService.run on another thread :-(
# See https://github.com/ros2/launch/issues/126
Expand Down Expand Up @@ -181,7 +183,7 @@ def _run_test(self):
# Waits for the DUT processes to start (signaled by the _processes_launched
# event) and then runs the tests

if not self._processes_launched.wait(timeout=15):
if not self._processes_launched.wait(self._timeout):
# Timed out waiting for the processes to start
print('Timed out waiting for processes to start up')
self._launch_service.shutdown()
Expand Down Expand Up @@ -217,7 +219,8 @@ class LaunchTestRunner(object):
def __init__(self,
test_runs,
launch_file_arguments=[],
debug=False):
debug=False,
timeout=15):
"""
Create an LaunchTestRunner object.

Expand All @@ -229,6 +232,7 @@ def __init__(self,
self._test_runs = test_runs
self._launch_file_arguments = launch_file_arguments
self._debug = debug
self._timeout = timeout # timeout for ReadyToTest Action

def generate_preamble(self):
"""Generate a launch description preamble for a test to be run with."""
Expand All @@ -252,7 +256,8 @@ def run(self):
run,
self.generate_preamble(),
self._launch_file_arguments,
self._debug)
self._debug,
self._timeout)
results[run] = worker.run()
except unittest.case.SkipTest as skip_exception:
# If a 'skip' decorator was placed on the generate_test_description function,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,24 @@ def generate_test_description(my_param):

dut.validate() # Make sure this passes initial validation (probably redundant with above)
runs[0].normalized_test_description(ready_fn=lambda: None)

def test_launch_description_with_ready_action_changed_timeout(self):
deepanshubansal01 marked this conversation as resolved.
Show resolved Hide resolved

def generate_test_description():
return launch.LaunchDescription([
launch.actions.TimerAction(
period=17.0, # takes 17 sec for this action to startup
actions=[ReadyToTest()]
)
])

runs = make_test_run_for_dut(generate_test_description)
dut = LaunchTestRunner(
test_runs=runs,
launch_file_arguments=[],
debug=False,
timeout=20.0 # increase the timeout giving the time for process to startup
)

dut.validate() # Make sure this passes initial validation (probably redundant with above)
runs[0].normalized_test_description(ready_fn=lambda: None)
adityapande-1995 marked this conversation as resolved.
Show resolved Hide resolved