def test_wait_with_subtask_timeout(self): def get_task(task_id): return {'id': task_id, 'state': TASK_STATES['TIMEOUT']} conf = {'key': 'value'} task_id = 100 subtask_id = 999 args = [] hub = Mock(worker=Mock( get_task=Mock(side_effect=get_task), check_wait=Mock(return_value=([subtask_id], [])), create_subtask=Mock(return_value=subtask_id), )) t = TaskBase(hub, conf, task_id, args) t.foreground = False t.spawn_subtask('method', []) with self.assertRaises(FailTaskException): t.wait() hub.worker.check_wait.assert_called_once_with(task_id) hub.worker.get_task.assert_has_calls( [call(task_id), call(subtask_id)], any_order=False) hub.worker.wait.assert_called_once_with(task_id, None)
def test_wait_with_subtask_timeout(self): def get_task(task_id): return {'id': task_id, 'state': TASK_STATES['TIMEOUT']} conf = {'key': 'value'} task_id = 100 subtask_id = 999 args = [] hub = Mock(worker=Mock( get_task=Mock(side_effect=get_task), check_wait=Mock(return_value=([subtask_id], [])), create_subtask=Mock(return_value=subtask_id), )) t = TaskBase(hub, conf, task_id, args) t.foreground = False t.spawn_subtask('method', []) with self.assertRaises(FailTaskException): t.wait() hub.worker.check_wait.assert_called_once_with(task_id) hub.worker.get_task.assert_has_calls([call(task_id), call(subtask_id)], any_order=False) hub.worker.wait.assert_called_once_with(task_id, None)
def test_wait_with_subtask_closed(self): def get_task(task_id): return {'id': task_id, 'state': TASK_STATES['CLOSED']} conf = {'key': 'value'} task_id = 100 subtask_id = 999 args = [] hub = Mock(worker=Mock( get_task=Mock(side_effect=get_task), check_wait=Mock(return_value=([subtask_id], [])), create_subtask=Mock(return_value=subtask_id), )) t = TaskBase(hub, conf, task_id, args) t.foreground = False t.spawn_subtask('method', []) finished = t.wait() self.assertEqual(len(finished), 1) hub.worker.check_wait.assert_called_once_with(task_id) hub.worker.get_task.assert_has_calls( [call(task_id), call(subtask_id)], any_order=False) hub.worker.wait.assert_called_once_with(task_id, None)
def test_wait_with_subtask_closed(self): def get_task(task_id): return {'id': task_id, 'state': TASK_STATES['CLOSED']} conf = {'key': 'value'} task_id = 100 subtask_id = 999 args = [] hub = Mock(worker=Mock( get_task=Mock(side_effect=get_task), check_wait=Mock(return_value=([subtask_id], [])), create_subtask=Mock(return_value=subtask_id), )) t = TaskBase(hub, conf, task_id, args) t.foreground = False t.spawn_subtask('method', []) finished = t.wait() self.assertEqual(len(finished), 1) hub.worker.check_wait.assert_called_once_with(task_id) hub.worker.get_task.assert_has_calls([call(task_id), call(subtask_id)], any_order=False) hub.worker.wait.assert_called_once_with(task_id, None)
def test_spawn_subtask_foreground_task(self): task_info = {'id': 100} hub = Mock(worker=Mock(get_task=Mock(return_value=task_info))) conf = {'key': 'value'} task_id = 100 args = [] t = TaskBase(hub, conf, task_id, args) t.foreground = True with self.assertRaises(RuntimeError): t.spawn_subtask('method', []) hub.worker.create_subtask.assert_not_called()
def test_spawn_subtask(self): task_info = {'id': 100} conf = {'key': 'value'} task_id = 100 subtask_id = 999 args = [] hub = Mock(worker=Mock( get_task=Mock(return_value=task_info), create_subtask=Mock(return_value=subtask_id), )) t = TaskBase(hub, conf, task_id, args) t.foreground = False ret_id = t.spawn_subtask('method', [], 'label') self.assertEqual(ret_id, subtask_id) hub.worker.create_subtask.assert_called_once_with('label', 'method', [], task_id)
def test_spawn_subtask(self): task_info = {'id': 100} conf = {'key': 'value'} task_id = 100 subtask_id = 999 args = [] hub = Mock(worker=Mock( get_task=Mock(return_value=task_info), create_subtask=Mock(return_value=subtask_id), )) t = TaskBase(hub, conf, task_id, args) t.foreground = False ret_id = t.spawn_subtask('method', [], 'label') self.assertEqual(ret_id, subtask_id) hub.worker.create_subtask.assert_called_once_with( 'label', 'method', [], task_id)