From 6d459c35a1ee59648cfb3899abe5e623a1142363 Mon Sep 17 00:00:00 2001 From: Dariusz Rybi Date: Wed, 29 Jan 2020 11:28:40 +0100 Subject: [PATCH] Handle unknown CannotComputeTask.reason --- golem/task/taskmanager.py | 2 +- tests/golem/task/test_taskmanager.py | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/golem/task/taskmanager.py b/golem/task/taskmanager.py index 60debcaa1a..12a0e87064 100644 --- a/golem/task/taskmanager.py +++ b/golem/task/taskmanager.py @@ -880,7 +880,7 @@ def task_computation_cancelled( ban_node = subtask_state.time_started + timeout < time.time() return self.task_computation_failure( subtask_id, - f'Task computation rejected: {err.value}', + f'Task computation rejected: {err.value if err else "unknown"}', ban_node, ) diff --git a/tests/golem/task/test_taskmanager.py b/tests/golem/task/test_taskmanager.py index 42c3ff7f76..2967277902 100644 --- a/tests/golem/task/test_taskmanager.py +++ b/tests/golem/task/test_taskmanager.py @@ -747,11 +747,32 @@ def test_task_computation_cancelled_offer_cancelled(self, *_): ) task_mock.computation_failed.assert_not_called() self.assertIs( - self.tm.tasks_states[task_mock.header.task_id]\ + self.tm.tasks_states[task_mock.header.task_id] .subtask_states[subtask_id].status, SubtaskStatus.cancelled, ) + @patch('golem.task.taskmanager.TaskManager.dump_task') + @patch('golem.task.taskmanager.TaskManager.task_computation_failure') + def test_task_computation_cancelled_unknown_reason(self, failure_mock, *_): + reason = None + subtask_id = "aabbcc" + task_mock = self._get_task_mock() + self.tm.add_new_task(task_mock) + self.tm.start_task(task_mock.header.task_id) + task_mock.query_extra_data_return_value.ctd['subtask_id'] = subtask_id + self.tm.get_next_subtask("NODE", "xyz", 1000, 100, 'oh') + self.tm.task_computation_cancelled( + subtask_id, + reason, + timeout=1000, + ) + failure_mock.assert_called_once_with( + subtask_id, + 'Task computation rejected: unknown', + False, + ) + @patch('golem.task.taskbase.Task.needs_computation', return_value=True) def test_get_subtasks(self, *_): assert self.tm.get_subtasks("Task 1") is None