Exemplo n.º 1
0
    def test_ChildRoslaunchProcess(self):
        # test that constructor is wired up correctly
        from roslaunch.server import ChildROSLaunchProcess
        name = 'foo-%s'%time.time()
        args = [time.time(), time.time()]
        env = { 'key-%s'%time.time() : str(time.time()) }
        cp = ChildROSLaunchProcess(name, args, env)
        self.assertEquals(name, cp.name)
        self.assertEquals(args, cp.args)
        self.assertEquals(env, cp.env)
        self.assertEquals(None, cp.uri)

        uri = 'http://foo:1234'
        cp.set_uri(uri)
        self.assertEquals(uri, cp.uri)
    def test_ChildRoslaunchProcess(self):
        # test that constructor is wired up correctly
        from roslaunch.server import ChildROSLaunchProcess
        name = 'foo-%s' % time.time()
        args = [time.time(), time.time()]
        env = {'key-%s' % time.time(): str(time.time())}
        cp = ChildROSLaunchProcess(name, args, env)
        self.assertEquals(name, cp.name)
        self.assertEquals(args, cp.args)
        self.assertEquals(env, cp.env)
        self.assertEquals(None, cp.uri)

        uri = 'http://foo:1234'
        cp.set_uri(uri)
        self.assertEquals(uri, cp.uri)
Exemplo n.º 3
0
    def test_ROSLaunchChildNode(self):
        from roslaunch.server import ROSLaunchChildNode
        from roslaunch.server import ChildROSLaunchProcess
        pmon = self.pmon
        import roslib.params
        try:
            # if there is a core up, we have to use its run id
            run_id = roslib.params.get_param('/run_id')
        except:
            run_id = 'foo-%s' % time.time()
        name = 'foo-bob'
        server_uri = 'http://localhost:12345'
        try:
            ROSLaunchChildNode(run_id, name, server_uri, None)
            self.fail("should not allow pm as None")
        except:
            pass
        try:
            ROSLaunchChildNode(run_id, name, 'http://bad_uri:0', pmon)
            self.fail("should not allow bad uri")
        except:
            pass

        n = ROSLaunchChildNode(run_id, name, server_uri, pmon)
        self.assertEquals(run_id, n.run_id)
        self.assertEquals(name, n.name)
        self.assertEquals(server_uri, n.server_uri)

        # tests for actual registration with server
        import roslaunch.config
        server = roslaunch.server.ROSLaunchParentNode(
            roslaunch.config.ROSLaunchConfig(), self.pmon)
        # - register a fake child with the server so that it accepts registration from ROSLaunchChild
        child_proc = ChildROSLaunchProcess('foo', [], {})
        server.add_child(name, child_proc)

        try:
            server.start()
            self.assert_(server.uri, "server URI did not initialize")
            s = ServerProxy(server.uri)

            print "SERVER STARTED"

            # start the child
            n = ROSLaunchChildNode(run_id, name, server.uri, pmon)
            n.start()
            print "CHILD STARTED"
            self.assert_(n.uri, "child URI did not initialize")

            # verify registration
            print "VERIFYING REGISTRATION"
            self.assertEquals(child_proc.uri, n.uri)
            child_uri = 'http://fake-unroutable:1324'
            # - list children
            val = self._succeed(s.list_children())
            self.assertEquals([n.uri], val)
        finally:
            print "SHUTTING DOWN"
            n.shutdown('test done')
            server.shutdown('test done')
    def test_ROSLaunchParentNode(self):
        from roslaunch.server import ROSLaunchParentNode
        from roslaunch.server import ChildROSLaunchProcess
        from roslaunch.config import ROSLaunchConfig
        from roslaunch.pmon import ProcessListener
        rosconfig = ROSLaunchConfig()
        try:
            ROSLaunchParentNode(rosconfig, None)
            self.fail("should not allow pm as None")
        except:
            pass
        pmon = self.pmon
        n = ROSLaunchParentNode(rosconfig, pmon)
        self.assertEquals(rosconfig, n.rosconfig)
        self.assertEquals([], n.listeners)
        self.assertEquals({}, n.child_processes)
        self.assertEquals(n.handler.listeners, n.listeners)
        self.assertEquals(n.handler.child_processes, n.child_processes)

        # test add listener
        self.assertEquals(n.handler.listeners, n.listeners)
        l = ProcessListener()
        n.add_process_listener(l)
        self.assertEquals([l], n.listeners)
        self.assertEquals(n.handler.listeners, n.listeners)

        # now, lets make some xmlrpc calls against it
        import roslaunch.config
        server = roslaunch.server.ROSLaunchParentNode(
            roslaunch.config.ROSLaunchConfig(), self.pmon)

        # it's really dangerous for logging when both a parent and a
        # child are in the same process, so out of paranoia, clear the
        # logging handlers
        roslaunch.core.clear_printlog_handlers()
        roslaunch.core.clear_printerrlog_handlers()

        # - register a fake child with the server so that it accepts registration from ROSLaunchChild
        child_name = 'child-%s' % time.time()
        child_proc = ChildROSLaunchProcess('foo', [], {})
        server.add_child(child_name, child_proc)

        try:
            server.start()
            self.assert_(server.uri, "server URI did not initialize")
            s = ServerProxy(server.uri)
            child_uri = 'http://fake-unroutable:1324'
            # - list children should be empty
            val = self._succeed(s.list_children())
            self.assertEquals([], val)
            # - register
            val = self._succeed(s.register(child_name, child_uri))
            self.assertEquals(1, val)
            # - list children
            val = self._succeed(s.list_children())
            self.assertEquals([child_uri], val)
        finally:
            server.shutdown('test done')
    def test_ROSLaunchParentHandler(self):
        from roslaunch.server import ROSLaunchParentHandler
        from roslaunch.server import ChildROSLaunchProcess
        try:
            ROSLaunchParentHandler(None, {}, [])
            self.fail("should not allow pm as None")
        except:
            pass

        pmon = self.pmon
        child_processes = {}
        listeners = []
        h = ROSLaunchParentHandler(pmon, child_processes, listeners)
        self.assertEquals(child_processes, h.child_processes)
        self.assertEquals(listeners, h.listeners)
        self._test_ROSLaunchBaseHandler(h)

        from rosgraph_msgs.msg import Log
        h.log('client-1', Log.FATAL, "message")
        h.log('client-1', Log.ERROR, "message")
        h.log('client-1', Log.DEBUG, "message")
        h.log('client-1', Log.INFO, "started with pid 1234")

        # test process_died
        # - no listeners
        self._succeed(h.process_died('dead1', -1))
        # - well-behaved listener
        l = roslaunch.pmon.ProcessListener()
        listeners.append(l)
        self._succeed(h.process_died('dead2', -1))

        # - bad listener with exception
        def bad():
            raise Exception("haha")

        l.process_died = bad
        self._succeed(h.process_died('dead3', -1))

        # test register

        # - verify clean slate with list_children
        self.assertEquals([], self._succeed(h.list_children()))

        # - first register with unknown
        code, msg, val = h.register('client-unknown', 'http://unroutable:1234')
        self.assertEquals(-1, code)
        self.assertEquals([], self._succeed(h.list_children()))

        # - now register with known
        uri = 'http://unroutable:1324'
        child_processes['client-1'] = ChildROSLaunchProcess('foo', [], {})
        val = self._succeed(h.register('client-1', uri))
        self.assert_(type(val) == int)
        self.assertEquals([uri], self._succeed(h.list_children()))