File: test_unload_called_twice.py

package info (click to toggle)
ros-nodelet-core 1.11.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 596 kB
  • sloc: cpp: 2,473; python: 367; xml: 171; makefile: 7
file content (62 lines) | stat: -rwxr-xr-x 2,260 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python3

import roslib; roslib.load_manifest('test_nodelet')
import rospy
import unittest
import rostest
import signal
import subprocess
import time

from nodelet.srv import *

class TestUnloadCalledTwice(unittest.TestCase):
    def test_unload_called_twice(self):
        '''
        Test that when a nodelet loader is stopped and requests unloading,
        the unload() call in LoaderROS is not run twice (#50).
        '''

        # start nodelet manager
        proc_manager = subprocess.Popen(["rosrun", "nodelet", "nodelet", "manager", "__name:=nodelet_manager"],
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            bufsize=-1
        )

        # wait for nodelet manager to be ready
        try:
            rospy.wait_for_service('/nodelet_manager/load_nodelet', timeout=2)
        except:
            self.fail("Could not determine that nodelet manager has started")

        # load nodelet
        proc_nodelet = subprocess.Popen(["rosrun", "nodelet", "nodelet", "load", "test_nodelet/Plus", "nodelet_manager", "__name:=test"],
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE
        )

        # wait for nodelet to be ready
        try:
            rospy.wait_for_service('test/get_loggers', timeout=2)
        except:
            self.fail("Could not determine that nodelet has started")
        time.sleep(1)

        # stop the nodelet loader via signal (similar to roslaunch killing it)
        proc_nodelet.send_signal(signal.SIGINT)
        (n_out, n_err) = proc_nodelet.communicate()

        # stop the nodelet manager, too
        proc_manager.send_signal(signal.SIGINT)
        (m_out, m_err) = proc_manager.communicate()

        # check that nodelet unloaded and that LoaderROS::unload() does not
        # complain about nodelet not being found (an indication that it was called
        # again after the nodelet was already unloaded)
        self.assertIn('Unloading nodelet /test from manager nodelet_manager', n_out)
        self.assertNotIn('Failed to find nodelet with name', m_err)

if __name__ == '__main__':
    rospy.init_node('test_unload_called_twice')
    rostest.rosrun('test_unload_called_twice', 'test_unload_called_twice', TestUnloadCalledTwice)