示例#1
0
 def setUp(self):
     logging.basicConfig(level=logging.DEBUG)
     self.engine = TaskEngine()
     self.ctx = Context(None)
     self.ctx.bind('taskengine', self.engine)
     self.engine.start(self.ctx)
     self.logger = logging.getLogger(__name__)
示例#2
0
 def setUp(self):
     logging.basicConfig(level=logging.DEBUG)
     self.engine = TaskEngine()
     self.ctx = Context(None)
     self.ctx.bind('taskengine', self.engine)
     self.engine.start(self.ctx)
     self.logger = logging.getLogger(__name__)
示例#3
0
class TestTaskEngine(unittest.TestCase):
    def setUp(self):
        logging.basicConfig(level=logging.DEBUG)
        self.engine = TaskEngine()
        self.ctx = Context(None)
        self.ctx.bind('taskengine', self.engine)
        self.engine.start(self.ctx)
        self.logger = logging.getLogger(__name__)

    def tearDown(self):
        self.engine.stop(self.ctx)

    def test_register_and_unregister_action(self):
        def mock_action():
            return True

        t1 = self.engine.register(mock_action)
        action_key, mod_name, _ = service.action_key(__name__, 'mock_action')
        self.assertEqual(t1.key, action_key)

        self.engine.unregister(action_key)

        self.assertIsNone(self.engine.get_action(action_key))
示例#4
0
class TestTaskEngine(unittest.TestCase):
    def setUp(self):
        logging.basicConfig(level=logging.DEBUG)
        self.engine = TaskEngine()
        self.ctx = Context(None)
        self.ctx.bind('taskengine', self.engine)
        self.engine.start(self.ctx)
        self.logger = logging.getLogger(__name__)

    def tearDown(self):
        self.engine.stop(self.ctx)

    def test_register_and_unregister_action(self):
        def mock_action():
            return True

        t1 = self.engine.register(mock_action)
        action_key = service.action_key(__name__, 'mock_action')
        self.assertEqual(t1.key, action_key)

        self.engine.unregister(action_key)

        self.assertIsNone(self.engine.get_action(action_key))
示例#5
0
class TestTaskEngine(unittest.TestCase):
    def setUp(self):
        logging.basicConfig(level=logging.DEBUG)
        self.engine = TaskEngine()
        self.ctx = Context(None)
        self.ctx.bind('taskengine', self.engine)
        self.engine.start(self.ctx)
        self.logger = logging.getLogger(__name__)

    def tearDown(self):
        self.engine.stop(self.ctx)

    def test_register_and_unregister_task(self):

        def mock_task1():
            return True

        t1 = self.engine.register(mock_task1)
        task_key = __name__ + '.mock_task1'
        self.assertEqual(t1.key, task_key)

        self.engine.unregister(task_key)

        self.assertIsNone(self.engine.get_task_proxy(task_key))

    def test_once_schedule(self):
        def mock_task2():
            self.logger.debug("mock_task2() run.")
            return True

        t1 = self.engine.register(mock_task2)
        task_key = __name__ + '.mock_task2'
        task1 = t1.run_once()
        task1.join()
        self.assertTrue(task1.result)

    def test_periodic_schedule(self):
        global counter
        counter = 0

        def mock_task3():
            global counter
            counter += 1
            return counter

        t1 = self.engine.register(mock_task3)

        sched = t1.run_periodic(0.1)
        gevent.sleep(1)
        self.assertTrue(sched.result > 5)

    def test_cancel_schedule(self):
        def mock_once_task():
            return True

        t1 = self.engine.register(mock_once_task)
        schedule1 = t1.run_once(delayed_secs=10)
        got_sched = self.engine.get_schedule(schedule1.id)
        self.assertIsNotNone(got_sched)

        self.engine.cancel(schedule1)
        got_sched = self.engine.get_schedule(schedule1.id)
        self.assertIsNone(got_sched)