Skip to content

Commit fd27518

Browse files
committed
chore:test checking scheduled after failed execution
#75
1 parent 37e9ffa commit fd27518

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

scheduler/tests/test_models.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -643,27 +643,37 @@ class TestCronJob(BaseTestCases.TestBaseJob):
643643
TaskModelClass = CronTask
644644

645645
def test_clean(self):
646-
task = task_factory(self.TaskModelClass)
646+
task = task_factory(CronTask)
647647
task.cron_string = '* * * * *'
648648
task.queue = list(settings.QUEUES)[0]
649649
task.callable = 'scheduler.tests.jobs.test_job'
650650
self.assertIsNone(task.clean())
651651

652652
def test_clean_cron_string_invalid(self):
653-
task = task_factory(self.TaskModelClass)
653+
task = task_factory(CronTask)
654654
task.cron_string = 'not-a-cron-string'
655655
task.queue = list(settings.QUEUES)[0]
656656
task.callable = 'scheduler.tests.jobs.test_job'
657657
with self.assertRaises(ValidationError):
658658
task.clean_cron_string()
659659

660660
def test_repeat(self):
661-
task = task_factory(self.TaskModelClass, repeat=10)
661+
task = task_factory(CronTask, repeat=10)
662662
entry = _get_job_from_scheduled_registry(task)
663663
self.assertEqual(entry.meta['repeat'], 10)
664664

665665
def test_check_rescheduled_after_execution(self):
666-
task = task_factory(self.TaskModelClass, )
666+
task = task_factory(CronTask, )
667+
queue = task.rqueue
668+
first_run_id = task.job_id
669+
entry = queue.fetch_job(first_run_id)
670+
queue.run_sync(entry)
671+
task.refresh_from_db()
672+
self.assertTrue(task.is_scheduled())
673+
self.assertNotEqual(task.job_id, first_run_id)
674+
675+
def test_check_rescheduled_after_failed_execution(self):
676+
task = task_factory(CronTask, callable_name="scheduler.tests.jobs.scheduler.tests.jobs.test_job", )
667677
queue = task.rqueue
668678
first_run_id = task.job_id
669679
entry = queue.fetch_job(first_run_id)
@@ -676,7 +686,7 @@ def test_cron_task_enqueuing_jobs(self):
676686
queue = get_queue()
677687
prev_queued = len(queue.scheduled_job_registry)
678688
prev_finished = len(queue.finished_job_registry)
679-
task = task_factory(self.TaskModelClass, callable_name='scheduler.tests.jobs.enqueue_jobs')
689+
task = task_factory(CronTask, callable_name='scheduler.tests.jobs.enqueue_jobs')
680690
self.assertEqual(prev_queued + 1, len(queue.scheduled_job_registry))
681691
first_run_id = task.job_id
682692
entry = queue.fetch_job(first_run_id)

0 commit comments

Comments
 (0)