def testScheduleCronKick_noCronExpression(self): """Tests that test plan without cron expressions do not get scheduled.""" test_plan = ndb_models.TestPlan(name='test_plan') test_plan.put() test_plan_kicker.ScheduleCronKick(test_plan.key.id()) # No tasks scheduled tasks = self.mock_task_scheduler.GetTasks( queue_names=[test_plan_kicker.TEST_PLAN_KICKER_QUEUE]) self.assertEmpty(tasks)
def ScheduleTestPlanCronJob(test_plan_id): """Schedules a cron job for a test plan. If the test plan is not for cron, no cron job will be scheduled. Args: test_plan_id: a test plan ID. """ test_plan_kicker.ScheduleCronKick(test_plan_id)
def testScheduleCronKick_invalidTimezone(self): """Tests that test plan with invalid timezones do not get scheduled.""" test_plan = ndb_models.TestPlan( name='test_plan', cron_exp='0 0 * * *', cron_exp_timezone='INVALID') test_plan.put() test_plan_kicker.ScheduleCronKick(test_plan.key.id()) # No tasks scheduled tasks = self.mock_task_scheduler.GetTasks( queue_names=[test_plan_kicker.TEST_PLAN_KICKER_QUEUE]) self.assertEmpty(tasks)
def testScheduleCronKick_withTimezone(self, get_current_time): """Tests that test plans can be scheduled relative to a timezone.""" # Create test plan that runs every day at midnight in PT test_plan = ndb_models.TestPlan( name='test_plan', cron_exp='0 0 * * *', cron_exp_timezone='America/Los_Angeles') test_plan.put() # Current time is 12:30 AM UTC and next run time is midnight PT (8 AM UTC) get_current_time.return_value = datetime.datetime(1970, 1, 1, 0, 30, 0) next_run_time = pytz.UTC.localize(datetime.datetime(1970, 1, 1, 8, 0, 0)) test_plan_kicker.ScheduleCronKick(test_plan.key.id()) tasks = self.mock_task_scheduler.GetTasks( queue_names=[test_plan_kicker.TEST_PLAN_KICKER_QUEUE]) self.assertLen(tasks, 1) self.assertEqual(next_run_time, tasks[0].eta)
def testScheduleCronKick(self, get_current_time): """Tests that test plans can be scheduled.""" # Create test plan that runs every day at midnight test_plan = ndb_models.TestPlan(name='test_plan', cron_exp='0 0 * * *') test_plan.put() test_plan_id = test_plan.key.id() # Current time is 12:30 AM UTC and next run time is the following midnight get_current_time.return_value = datetime.datetime(1970, 1, 1, 0, 30, 0) next_run_time = pytz.UTC.localize(datetime.datetime(1970, 1, 2, 0, 0, 0)) test_plan_kicker.ScheduleCronKick(test_plan_id) tasks = self.mock_task_scheduler.GetTasks( queue_names=[test_plan_kicker.TEST_PLAN_KICKER_QUEUE]) self.assertLen(tasks, 1) self.assertEqual(next_run_time, tasks[0].eta) data = json.loads(tasks[0].payload) self.assertEqual(test_plan_id, data['test_plan_id'])