Esempio n. 1
0
    def test_task_postrun(self, _mock):
        with self.settings(CELERY_ALWAYS_EAGER=False):
            test_task.delay()
        self._verify_task_filled()

        task_postrun.send(sender=self)
        self._verify_task_empty()

        # Assert the original `apply_async` called.
        assert _mock.called, (
            'Expected PostRequestTask.original_apply_async call')
Esempio n. 2
0
    def test_start_end_duration(self):
        # create a task and send pre/post run signals to test signal handlers
        id = 'foo'
        tr = TaskResult(label='test task', object_id='id', url='/foo', task_id=id)
        tr.save()
        task_time = 2
        task_prerun.send(sender=TaskResultTestCase, task_id=id)
        sleep(task_time)
        task_postrun.send(sender=TaskResultTestCase, task_id=id)

        tr = TaskResult.objects.get(task_id=id)
        self.assertTrue(tr.task_start,
            'task start time should be set based on celery task_prerun signal')
        self.assertTrue(tr.task_end,
            'task end time should be set based on celery task_postrun signal')
        self.assertEqual(task_time, tr.duration.seconds)
Esempio n. 3
0
    def test_start_end_duration(self):
        # create a task and send pre/post run signals to test signal handlers
        id = 'foo'
        tr = TaskResult(label='test task',
                        object_id='id',
                        url='/foo',
                        task_id=id)
        tr.save()
        task_time = 2
        task_prerun.send(sender=TaskResultTestCase, task_id=id)
        sleep(task_time)
        task_postrun.send(sender=TaskResultTestCase, task_id=id)

        tr = TaskResult.objects.get(task_id=id)
        self.assertTrue(
            tr.task_start,
            'task start time should be set based on celery task_prerun signal')
        self.assertTrue(
            tr.task_end,
            'task end time should be set based on celery task_postrun signal')
        self.assertEqual(task_time, tr.duration.seconds)