def test_normal_items(self): logging.info('+++++++++++++++++++++++++++ test normal items') cfg = ComposerConfig(runner_fn=self.runner_fn, name='scheduler for normal items') composer = Composer(config=cfg) composer.run(db_engine=db.engine) normal_items = [Task(1), Task(2), Task(3)] name = 'normal items' composer.collect(name, normal_items, {}) self.assertEqual(1, len(db.session.query(SchedulerItem).all()), 'incorrect items') # test unique item name composer.collect(name, normal_items, {}) self.assertEqual(1, len(db.session.query(SchedulerItem).all()), 'incorrect items') time.sleep(20) self.assertEqual(1, len(db.session.query(SchedulerRunner).all()), 'incorrect runners') self.assertEqual(RunnerStatus.DONE.value, composer.get_recent_runners(name)[-1].status, 'should finish runner') # finish item composer.finish(name) self.assertEqual(ItemStatus.OFF, composer.get_item_status(name), 'should finish item') composer.stop()
def test_interval_items(self): logging.info( '+++++++++++++++++++++++++++ test finishing interval items') cfg = ComposerConfig(runner_fn=self.runner_fn, name='finish normal items') composer = Composer(config=cfg) composer.run(db_engine=db.engine) name = 'cronjob' # test invalid interval self.assertRaises(ValueError, composer.collect, name, [Task(1)], {}, interval=9) composer.collect(name, [Task(1)], {}, interval=10) self.assertEqual(1, len(db.session.query(SchedulerItem).all()), 'incorrect items') time.sleep(20) self.assertEqual(2, len(db.session.query(SchedulerRunner).all()), 'incorrect runners') self.assertEqual(RunnerStatus.DONE.value, composer.get_recent_runners(name)[-1].status, 'should finish runner') composer.finish(name) self.assertEqual(ItemStatus.OFF, composer.get_item_status(name), 'should finish item') composer.stop()