Skip to content

Commit

Permalink
Check all launched nodes have exited
Browse files Browse the repository at this point in the history
And check they exit code to decide success/fail of launch file
  • Loading branch information
LoyVanBeek committed Oct 26, 2020
1 parent ea218cc commit 76881b6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
19 changes: 17 additions & 2 deletions flexbe_testing/src/flexbe_testing/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def spin_once(self):
def __exit__(self, exception_type, exception_value, traceback):
pass

def wait_for_finishing(self):
pass

@property
def success(self):
return True
Expand All @@ -51,7 +54,8 @@ def __init__(self, launch_config, wait_cond="True"):
launchpath = None
launchcontent = None

self._exit_codes = []
self._launched_proc_names = []
self._exit_codes = {}

# load from system path
if launch_config.startswith('~') or launch_config.startswith('/'):
Expand All @@ -72,7 +76,10 @@ def __init__(self, launch_config, wait_cond="True"):
else:
loader.load_string(launchcontent, launchconfig, verbose=False)
self._launchrunner = roslaunch.launch.ROSLaunchRunner(self._run_id, launchconfig)
self._launchrunner.add_process_listener(Callback(lambda process_name, exit_code: self._exit_codes.append(exit_code)))

def store(process_name, exit_code):
self._exit_codes[process_name] = exit_code
self._launchrunner.add_process_listener(Callback(store))
self._wait_cond = wait_cond
self._valid = True

Expand All @@ -82,6 +89,8 @@ def __enter__(self):
Logger.print_positive('launchfile running')
self._valid = True

self._launched_proc_names = [p.name for p in self._launchrunner.pm.procs]

try:
check_running_rate = rospy.Rate(10)
is_running = False
Expand All @@ -99,6 +108,12 @@ def verify(self):
def spin_once(self):
self._launchrunner.spin_once()

def wait_for_finishing(self):
check_exited_rate = rospy.Rate(10)
rospy.loginfo("Waiting for all launched nodes to exit")
while not all(name in self._exit_codes for name in self._launched_proc_names):
check_exited_rate.sleep()

def __exit__(self, exception_type, exception_value, traceback):
self._launchrunner.stop()
Logger.print_positive('launchfile stopped')
Expand Down
3 changes: 3 additions & 0 deletions flexbe_testing/src/flexbe_testing/tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ def run_test(self, name, config):
self._tests['test_%s_pass' % name] = self._test_pass(False)
return 0

if config.get('require_launch_success', False):
context.wait_for_finishing()

# evaluate outcome
self._tests['test_%s_outcome' % name] = self._test_outcome(outcome, config['outcome'])
outcome_ok = outcome == config['outcome']
Expand Down

0 comments on commit 76881b6

Please sign in to comment.