Exemple #1
0
    def test_find_tasks_waiting(self):
        task_waiting = TaskHistoryFactory()
        task_waiting.task_status = TaskHistory.STATUS_WAITING
        task_waiting.save()
        task_pending = TaskHistoryFactory()

        url = reverse(waiting_tasks_api)
        response = self.client.get(url)
        tasks = loads(response.content)

        self.assertIn(str(task_waiting.id), tasks)
        self.assertEqual(tasks[str(task_waiting.id)], task_waiting.task_name)
        self.assertNotIn(str(task_pending.id), tasks)
    def test_find_tasks_running(self):
        task_running = TaskHistoryFactory()
        task_running.task_status = TaskHistory.STATUS_RUNNING
        task_running.save()
        task_pending = TaskHistoryFactory()

        url = reverse(running_tasks_api)
        response = self.client.get(url)
        tasks = loads(response.content)

        self.assertIn(str(task_running.id), tasks)
        self.assertEqual(tasks[str(task_running.id)], task_running.task_name)
        self.assertNotIn(str(task_pending.id), tasks)
    def test_lock_retry(self):
        database = factory.DatabaseFactory()
        task1 = TaskHistoryFactory()
        task2 = TaskHistoryFactory()
        task3 = TaskHistoryFactory()

        task1.task_status = TaskHistory.STATUS_ERROR
        task1.save()

        task2.task_name = task1.task_name
        task2.save()

        database.pin_task(task1)

        self.assertFalse(database.update_task(task3))
        self.assertTrue(database.update_task(task2))
        self.assertFalse(database.update_task(task2))

        database.unpin_task()
        self.assertTrue(database.pin_task(task3))
    def test_lock_retry(self):
        database = factory.DatabaseFactory()
        task1 = TaskHistoryFactory()
        task2 = TaskHistoryFactory()
        task3 = TaskHistoryFactory()

        task1.task_status = TaskHistory.STATUS_ERROR
        task1.save()

        task2.task_name = task1.task_name
        task2.save()

        database.pin_task(task1)

        self.assertFalse(database.update_task(task3))
        self.assertTrue(database.update_task(task2))
        self.assertFalse(database.update_task(task2))

        database.unpin_task()
        self.assertTrue(database.pin_task(task3))