Ejemplo n.º 1
0
    def test_wakeup_task_catch_os_error(self):
        t = Task.objects.create(
            worker=self._worker.worker,
            arch=self._arch,
            channel=self._channel,
            owner=self._user,
            method='DummyForkTask',
            state=TASK_STATES['FREE'],
        )

        tm = TaskManager(conf={'worker': self._worker})

        task_info = t.export(False)
        task_info['alert'] = True

        with patch('kobo.worker.taskmanager.os', fork=Mock(return_value=9999)) as os_mock:
            tm.take_task(task_info)

        with patch('kobo.worker.taskmanager.os', kill=Mock(side_effect=OSError)) as os_mock:
            tm.wakeup_task(task_info)
            os_mock.kill.assert_called_once_with(9999, signal.SIGUSR2)

        with self.assertRaises(ValueError):
            with patch('kobo.worker.taskmanager.os', kill=Mock(side_effect=ValueError)) as os_mock:
                tm.wakeup_task(task_info)
                os_mock.kill.assert_called_once_with(9999, signal.SIGUSR2)
Ejemplo n.º 2
0
    def test_wakeup_task_if_alert_is_not_set(self):
        t = Task.objects.create(
            worker=self._worker.worker,
            arch=self._arch,
            channel=self._channel,
            owner=self._user,
            method='DummyForkTask',
            state=TASK_STATES['FREE'],
        )

        tm = TaskManager(conf={'worker': self._worker})
        task_info = t.export(False)

        with patch('kobo.worker.taskmanager.os', fork=Mock(return_value=9999)) as os_mock:
            tm.take_task(task_info)
            os_mock.fork.assert_called_once()
            tm.wakeup_task(task_info)
            os_mock.kill.assert_not_called()