Skip to content

Commit

Permalink
add timeout arg for ReadyToTest action
Browse files Browse the repository at this point in the history
Signed-off-by: deepanshu <[email protected]>
  • Loading branch information
deepanshubansal01 committed Jun 21, 2022
1 parent 841e5b0 commit af24670
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
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'
)

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
)

_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):

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)

0 comments on commit af24670

Please sign in to comment.