Exemple #1
0
    def test_publish_transition(self):
        ROSINIT()
        lm = LifecycleManager(NODE_NAME)
        lm.start()

        state_sub = rospy.Subscriber(NODE_NAME + '/' + LIFECYCLE_STATE_TOPIC,
                                     Lifecycle, self.subscriber_cb)
        spin_thread = SpinThread(2, "SubscriberCB_Thread", 2)
        spin_thread.setDaemon(True)
        spin_thread.start()

        lm.configure()
        self.assertEquals(State.INACTIVE, lm.get_current_state())
        rospy.sleep(1.0)
        lm.cleanup()
        self.assertEquals(State.UNCONFIGURED, lm.get_current_state())
        rospy.sleep(1.0)
        lm.configure()
        rospy.sleep(1.0)
        lm.activate()
        self.assertEquals(State.ACTIVE, lm.get_current_state())
        rospy.sleep(1.0)
        lm.shutdown()
        self.assertEquals(State.FINALIZED, lm.get_current_state())
        rospy.sleep(3.0)
        self.assertEquals(5, self.Count)

        spin_thread.join(1.0)

        lm.__del__()
Exemple #2
0
 def test_simulate_failure_during_activating(self):
     ROSINIT()
     lm = LifecycleManager(NODE_NAME)
     lm.set_transition_callback(Transition.ACTIVATE, return_false)
     self.assertTrue(lm.configure())
     self.assertEquals(State.INACTIVE, lm.get_current_state())
     self.assertFalse(lm.activate())
     self.assertEquals(State.INACTIVE, lm.get_current_state())
Exemple #3
0
 def test_internal(self):
     ROSINIT()
     lm = LifecycleManager(NODE_NAME)
     lm.configure()
     self.assertEquals(State.INACTIVE, lm.get_current_state())
     lm.cleanup()
     self.assertEquals(State.UNCONFIGURED, lm.get_current_state())
     lm.configure()
     lm.activate()
     self.assertEquals(State.ACTIVE, lm.get_current_state())
     lm.shutdown()
     self.assertEquals(State.FINALIZED, lm.get_current_state())
Exemple #4
0
    def test_simulate_error_in_secondary_state(self):
        ROSINIT()
        lm = LifecycleManager(NODE_NAME)
        lm.set_error_cb(lambda ex: True)
        lm.set_transition_callback(Transition.CONFIGURE,
                                   lambda: lm.raise_error(Exception('Test')))

        lm.configure()
        self.assertEquals(State.UNCONFIGURED, lm.get_current_state())

        lm.set_error_cb(lambda ex: False)

        lm.configure()
        self.assertEquals(State.FINALIZED, lm.get_current_state())
Exemple #5
0
    def test_transitions_for_inactive(self):
        ROSINIT()
        lm = LifecycleManager(NODE_NAME)

        lm.configure()
        self.assertEquals(State.INACTIVE, lm.get_current_state())
        # make sure these are not accepted
        with self.assertRaises(IllegalTransitionException):
            lm.configure()
        self.assertEquals(State.INACTIVE, lm.get_current_state())
        with self.assertRaises(IllegalTransitionException):
            lm.deactivate()
        self.assertEquals(State.INACTIVE, lm.get_current_state())
        # now make sure all the valid ones are accepted
        self.assertTrue(lm.activate())
        self.assertEquals(State.ACTIVE, lm.get_current_state())

        # go back
        lm.deactivate()
        self.assertEquals(State.INACTIVE, lm.get_current_state())

        self.assertTrue(lm.cleanup())
        self.assertEquals(State.UNCONFIGURED, lm.get_current_state())

        # go back
        self.assertTrue(lm.configure())
        self.assertEquals(State.INACTIVE, lm.get_current_state())

        self.assertTrue(lm.shutdown())
        self.assertEquals(State.FINALIZED, lm.get_current_state())
Exemple #6
0
    def test_simulate_error_in_inactive(self):
        ROSINIT()
        lm = LifecycleManager(NODE_NAME)
        lm.set_error_cb(lambda ex: True)

        lm.configure()
        self.assertEquals(State.INACTIVE, lm.get_current_state())
        lm.raise_error(Exception('Test'))
        self.assertEquals(State.UNCONFIGURED, lm.get_current_state())

        lm.set_error_cb(lambda ex: False)

        lm.configure()
        self.assertEquals(State.INACTIVE, lm.get_current_state())
        lm.raise_error(Exception('Test'))
        self.assertEquals(State.FINALIZED, lm.get_current_state())
Exemple #7
0
    def test_simulate_failure_during_configuring(self):
        ROSINIT()
        lm = LifecycleManager(NODE_NAME)
        lm.set_transition_callback(Transition.CONFIGURE, return_false)

        self.assertFalse(lm.configure())
        self.assertEquals(State.UNCONFIGURED, lm.get_current_state())