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__()
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())
def test_transitions_for_active(self): ROSINIT() lm = LifecycleManager(NODE_NAME) lm.configure() lm.activate() self.assertEquals(State.ACTIVE, lm.get_current_state()) # make sure these are not accepted with self.assertRaises(IllegalTransitionException): lm.configure() self.assertEquals(State.ACTIVE, lm.get_current_state()) with self.assertRaises(IllegalTransitionException): lm.activate() self.assertEquals(State.ACTIVE, lm.get_current_state()) with self.assertRaises(IllegalTransitionException): lm.cleanup() self.assertEquals(State.ACTIVE, lm.get_current_state()) # now make sure all the valid ones are accepted self.assertTrue(lm.deactivate()) self.assertEquals(State.INACTIVE, lm.get_current_state()) # go back lm.activate() self.assertEquals(State.ACTIVE, lm.get_current_state()) self.assertTrue(lm.shutdown()) self.assertEquals(State.FINALIZED, lm.get_current_state())