예제 #1
0
    def test_timeout_tasks_fails_to_interrupt_if_not_open_or_finished(self):
        tasks = {}

        for state_id in TASK_STATES:
            state = TASK_STATES[state_id]
            if state == TASK_STATES['OPEN'] or state in FINISHED_STATES:
                continue

            tasks[state] = Task.objects.create(
                worker=self._worker,
                arch=self._arch,
                channel=self._channel,
                owner=self._user,
                state=state,
            )

        req = _make_request(self._worker)

        for _, task in tasks.items():
            with self.assertRaises(Exception):
                worker.timeout_tasks(req, [task.id])

        for state, task in tasks.items():
            t = Task.objects.get(id=task.id)
            self.assertEqual(t.state, state)
    def test_timeout_tasks_fails_to_interrupt_if_not_open_or_finished(self):
        tasks = {}

        for state_id in TASK_STATES:
            state = TASK_STATES[state_id]
            if state == TASK_STATES['OPEN'] or state in FINISHED_STATES:
                continue

            tasks[state] = Task.objects.create(
                worker=self._worker,
                arch=self._arch,
                channel=self._channel,
                owner=self._user,
                state=state,
            )

        req = _make_request(self._worker)

        for _, task in tasks.items():
            with self.assertRaises(Exception):
                worker.timeout_tasks(req, [task.id])

        for state, task in tasks.items():
            t = Task.objects.get(id=task.id)
            self.assertEqual(t.state, state)
예제 #3
0
    def test_timeout_tasks_timeout_tasks_recursively(self):
        t1 = Task.objects.create(
            worker=self._worker,
            arch=self._arch,
            channel=self._channel,
            owner=self._user,
            state=TASK_STATES['OPEN'],
        )

        t2 = Task.objects.create(
            worker=self._worker,
            arch=self._arch,
            channel=self._channel,
            owner=self._user,
            state=TASK_STATES['OPEN'],
            parent=t1,
        )

        req = _make_request(self._worker)
        ok = worker.timeout_tasks(req, [t1.id])
        self.assertTrue(ok)

        t1 = Task.objects.get(id=t1.id)
        self.assertEqual(t1.state, TASK_STATES['TIMEOUT'])

        t2 = Task.objects.get(id=t2.id)
        self.assertEqual(t2.state, TASK_STATES['TIMEOUT'])
    def test_timeout_tasks_timeout_tasks_recursively(self):
        t1 = Task.objects.create(
            worker=self._worker,
            arch=self._arch,
            channel=self._channel,
            owner=self._user,
            state=TASK_STATES['OPEN'],
        )

        t2 = Task.objects.create(
            worker=self._worker,
            arch=self._arch,
            channel=self._channel,
            owner=self._user,
            state=TASK_STATES['OPEN'],
            parent=t1,
        )

        req = _make_request(self._worker)
        ok = worker.timeout_tasks(req, [t1.id])
        self.assertTrue(ok)

        t1 = Task.objects.get(id=t1.id)
        self.assertEqual(t1.state, TASK_STATES['TIMEOUT'])

        t2 = Task.objects.get(id=t2.id)
        self.assertEqual(t2.state, TASK_STATES['TIMEOUT'])
예제 #5
0
    def test_timeout_tasks_fails_to_interrupt_another_worker_task(self):
        w = Worker.objects.create(
            worker_key='other-worker',
            name='other-worker',
        )

        t = Task.objects.create(
            worker=w,
            arch=self._arch,
            channel=self._channel,
            owner=self._user,
            state=TASK_STATES['OPEN'],
        )

        req = _make_request(self._worker)

        with self.assertRaises(Task.DoesNotExist):
            worker.timeout_tasks(req, [t.id])

        t = Task.objects.get(id=t.id)
        self.assertEqual(t.state, TASK_STATES['OPEN'])
    def test_timeout_tasks_fails_to_interrupt_another_worker_task(self):
        w = Worker.objects.create(
            worker_key='other-worker',
            name='other-worker',
        )

        t = Task.objects.create(
            worker=w,
            arch=self._arch,
            channel=self._channel,
            owner=self._user,
            state=TASK_STATES['OPEN'],
        )

        req = _make_request(self._worker)

        with self.assertRaises(Task.DoesNotExist):
            worker.timeout_tasks(req, [t.id])

        t = Task.objects.get(id=t.id)
        self.assertEqual(t.state, TASK_STATES['OPEN'])
예제 #7
0
    def test_timeout_tasks_single_task(self):
        t = Task.objects.create(
            worker=self._worker,
            arch=self._arch,
            channel=self._channel,
            owner=self._user,
            state=TASK_STATES['OPEN'],
        )

        req = _make_request(self._worker)
        ok = worker.timeout_tasks(req, [t.id])
        self.assertTrue(ok)

        t = Task.objects.get(id=t.id)
        self.assertEqual(t.state, TASK_STATES['TIMEOUT'])
    def test_timeout_tasks_single_task(self):
        t = Task.objects.create(
            worker=self._worker,
            arch=self._arch,
            channel=self._channel,
            owner=self._user,
            state=TASK_STATES['OPEN'],
        )

        req = _make_request(self._worker)
        ok = worker.timeout_tasks(req, [t.id])
        self.assertTrue(ok)

        t = Task.objects.get(id=t.id)
        self.assertEqual(t.state, TASK_STATES['TIMEOUT'])
예제 #9
0
    def test_timeout_tasks_do_not_interrupt_finished_tasks(self):
        tasks = {}

        for state in FINISHED_STATES:
            tasks[state] = Task.objects.create(
                worker=self._worker,
                arch=self._arch,
                channel=self._channel,
                owner=self._user,
                state=state,
            )

        req = _make_request(self._worker)
        ok = worker.timeout_tasks(req, [t.id for t in tasks.values()])
        self.assertTrue(ok)

        for state, task in tasks.items():
            t = Task.objects.get(id=task.id)
            self.assertEqual(t.state, state)
예제 #10
0
    def test_timeout_tasks_do_not_interrupt_finished_tasks(self):
        tasks = {}

        for state in FINISHED_STATES:
            tasks[state] = Task.objects.create(
                worker=self._worker,
                arch=self._arch,
                channel=self._channel,
                owner=self._user,
                state=state,
            )

        req = _make_request(self._worker)
        ok = worker.timeout_tasks(req, [t.id for t in tasks.values()])
        self.assertTrue(ok)


        for state, task in tasks.items():
            t = Task.objects.get(id=task.id)
            self.assertEqual(t.state, state)
예제 #11
0
 def timeout_tasks(self, task_list):
     return worker.timeout_tasks(self._request, task_list)
예제 #12
0
 def test_timeout_tasks_empty_task_list(self):
     req = _make_request(self._worker)
     ok = worker.timeout_tasks(req, [])
     self.assertTrue(ok)
예제 #13
0
 def test_timeout_tasks(self):
     with self.assertRaises(PermissionDenied):
         worker.timeout_tasks(_make_request(None, False), [])
예제 #14
0
 def test_timeout_tasks_empty_task_list(self):
     req = _make_request(self._worker)
     ok = worker.timeout_tasks(req, [])
     self.assertTrue(ok)
예제 #15
0
 def test_timeout_tasks(self):
     with self.assertRaises(PermissionDenied):
         worker.timeout_tasks(_make_request(None, False), [])