test_bond_break_on_shutdown.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import roslib; roslib.load_manifest('test_nodelet')
4 import rospy
5 import unittest
6 import rostest
7 import signal
8 import subprocess
9 import time
10 
11 from nodelet.srv import *
12 
13 class TestBondBreakOnShutdown(unittest.TestCase):
15  '''
16  Test that the bond is broken cleanly when closing a nodelet loader (#50).
17  This relies on a debug message printed by the bondcpp package in case
18  of error.
19  '''
20 
21  # start nodelet manager
22  proc_manager = subprocess.Popen(["rosrun", "nodelet", "nodelet", "manager", "__name:=nodelet_manager"],
23  stdout=subprocess.PIPE,
24  stderr=subprocess.PIPE,
25  bufsize=-1
26  )
27 
28  # wait for nodelet manager to be ready
29  try:
30  rospy.wait_for_service('/nodelet_manager/load_nodelet', timeout=2)
31  except:
32  self.fail("Could not determine that nodelet manager has started")
33 
34  # load a nodelet
35  proc_nodelet = subprocess.Popen(["rosrun", "nodelet", "nodelet", "load", "test_nodelet/Plus", "nodelet_manager", "__name:=test"],
36  stdout=subprocess.PIPE,
37  stderr=subprocess.PIPE,
38  bufsize=-1
39  )
40 
41  # wait for it to be ready
42  try:
43  rospy.wait_for_service('test/get_loggers', timeout=2)
44  except:
45  self.fail("Could not determine that nodelet has started")
46  time.sleep(1)
47 
48  # stop the nodelet loader via signal (similar to roslaunch killing it)
49  proc_nodelet.send_signal(signal.SIGINT)
50  (n_out, n_err) = proc_nodelet.communicate()
51 
52  # stop the nodelet manager, too
53  proc_manager.send_signal(signal.SIGINT)
54  (m_out, m_err) = proc_manager.communicate()
55 
56  # check that nodelet unloaded and there was no error with bond breaking
57  self.assertIn('Unloading nodelet /test from manager nodelet_manager', n_out)
58  self.assertNotIn('Bond failed to break on destruction', m_out)
59  self.assertNotIn('Bond failed to break on destruction', n_out)
60 
61 if __name__ == '__main__':
62  rospy.init_node('test_bond_break_on_shutdown')
63  rostest.unitrun('test_bond_break_on_shutdown', 'test_bond_break_on_shutdown', TestBondBreakOnShutdown)
64 


test_nodelet
Author(s): Tully Foote
autogenerated on Sat Jul 18 2020 03:17:57