Exemplo n.º 1
0
class TestScheduleJobs(TransactionTestCase):

    def setUp(self):
        self.q = Queue()
        self.w = Worker.create([self.q])

    def test_shedule_call(self):
        """Schedule to fire now"""
        job = self.q.schedule_call(now(), do_nothing)
        self.w.work(burst=True)
        with self.assertRaises(Job.DoesNotExist) as exc:
            Job.objects.get(queue_id='default', pk=job.id)

    def test_schedule_future_call(self):
        """Schedule to fire in the distant future"""
        job = self.q.schedule_call(datetime(2999,12,1, tzinfo=utc), do_nothing)
        self.w.work(burst=True)
        # check it is still in the queue
        self.assertIsNotNone(Job.objects.get(queue_id='default', pk=job.id))
Exemplo n.º 2
0
class Test_get_job_or_promise(TransactionTestCase):
    """Test the Job._get_job_or_promise classmethod"""

    def setUp(self):
        self.q = Queue(scheduled=True)
        # simulate the default worker timeout
        self.timeout = 60
        future = now() + timedelta(seconds=self.timeout/2)
        # enqueue a job for 30 seconds time in the future
        self.job = self.q.schedule_call(future, do_nothing)


    def test_get_job_or_promise(self):
        """Test get a promise of a job in the future"""

        job, promise, timeout = Job._get_job_or_promise(
            self.q.connection, self.q, self.timeout)
        self.assertLessEqual(timeout, self.timeout)
        self.assertIsNone(job)
        self.assertEqual(promise, self.q.name)

    def test_get_no_job_no_promise(self):
        """Test get no job and no promise"""

        # job is in the future beyond the current
        # worker timeout
        job, promise, timeout = Job._get_job_or_promise(
            self.q.connection, self.q, 1)
        self.assertEqual(timeout, 1)
        self.assertIsNone(job)
        self.assertIsNone(promise)

    def test_get_earlier_job_no_promise(self):
        """Test get earlier job and no promise"""
        # Job enqueue after the first scheduled job
        # but to be exec ahead of the scheduled job
        now_job = self.q.enqueue(do_nothing)
        job, promise, timeout = Job._get_job_or_promise(
            self.q.connection, self.q, 60)
        # timeout should remain the same
        self.assertEqual(timeout, 60)
        self.assertEqual(now_job.id, job.id)
        self.assertIsNone(promise)
Exemplo n.º 3
0
class Test_get_job_no_promise(TransactionTestCase):
    def setUp(self):
        # setup a job in the very near future which
        # should execute
        self.q = Queue()
        # simulate the default worker timeout
        self.timeout = 60
        future = now() + timedelta(seconds=1)
        # enqueue a job for 1 second time in the future
        self.job = self.q.schedule_call(future, do_nothing)
        time.sleep(1)

    def test_get_job_no_promise(self):
        """Test get job and no promise"""

        job, promise, timeout = Job._get_job_or_promise(
            self.q.connection, self.q, self.timeout)
        self.assertEqual(timeout, self.timeout)
        self.assertEquals(job.id, self.job.id)
        self.assertIsNone(promise)
Exemplo n.º 4
0
class TestGetJobNoPromise(TransactionTestCase):
    def setUp(self):
        # setup a job in the very near future which
        # should execute
        self.q = Queue(scheduled=True)
        # simulate the default worker timeout
        self.timeout = 60
        future = now() + timedelta(seconds=1)
        # enqueue a job for 1 second time in the future
        self.job = self.q.schedule_call(future, do_nothing)
        time.sleep(1)

    def test_get_job_no_promise(self):
        """Test get job and no promise"""

        job, promise, timeout = Job._get_job_or_promise(
            self.q.connection, self.q, self.timeout)
        self.assertEqual(timeout, self.timeout)
        self.assertEqual(job.id, self.job.id)
        self.assertIsNone(promise)
Exemplo n.º 5
0
class Test_get_job_or_promise(TransactionTestCase):
    """Test the Job._get_job_or_promise classmethod"""
    def setUp(self):
        self.q = Queue()
        # simulate the default worker timeout
        self.timeout = 60
        future = now() + timedelta(seconds=self.timeout / 2)
        # enqueue a job for 30 seconds time in the future
        self.job = self.q.schedule_call(future, do_nothing)

    def test_get_job_or_promise(self):
        """Test get a promise of a job in the future"""

        job, promise, timeout = Job._get_job_or_promise(
            self.q.connection, self.q, self.timeout)
        self.assertLessEqual(timeout, self.timeout)
        self.assertIsNone(job)
        self.assertEqual(promise, self.q.name)

    def test_get_no_job_no_promise(self):
        """Test get no job and no promise"""

        # job is in the future beyond the current
        # worker timeout
        job, promise, timeout = Job._get_job_or_promise(
            self.q.connection, self.q, 1)
        self.assertEqual(timeout, 1)
        self.assertIsNone(job)
        self.assertIsNone(promise)

    def test_get_earlier_job_no_promise(self):
        """Test get earlier job and no promise"""
        # Job enqueue after the first scheduled job
        # but to be exec ahead of the scheduled job
        now_job = self.q.enqueue(do_nothing)
        job, promise, timeout = Job._get_job_or_promise(
            self.q.connection, self.q, 60)
        # timeout should remain the same
        self.assertEqual(timeout, 60)
        self.assertEqual(now_job.id, job.id)
        self.assertIsNone(promise)