Exemple #1
0
    def __build_subtasks(n):

        subtasks = dict()
        subtask_id = None

        for i in xrange(0, n):

            subtask = SubtaskState()
            subtask.subtask_id = str(uuid.uuid4())
            subtask.computer = ComputerState()
            subtask.computer.node_name = 'node_{}'.format(i)
            subtask.computer.node_id = 'deadbeef0{}'.format(i)
            subtask.results = []
            subtask.stderr = 'error_{}'.format(i)
            subtask.stdout = 'output_{}'.format(i)
            subtask.extra_data = {'start_task': i, 'end_task': i}
            subtask_id = subtask.subtask_id

            subtasks[subtask.subtask_id] = subtask

        return subtasks, subtask_id
Exemple #2
0
    def test_task_result_incoming(self, mock_addr):
        mock_addr.return_value = self.addr_return
        subtask_id = "xxyyzz"
        node_id = 'node'

        task_mock = self._get_task_mock()
        task_mock.counting_nodes = {}

        with patch("golem.task.taskbase.Task.result_incoming"
                   ) as result_incoming_mock:
            self.tm.task_result_incoming(subtask_id)
            assert not result_incoming_mock.called

        task_mock.subtasks_given = dict()
        task_mock.subtasks_given[subtask_id] = TaskClient(node_id)

        subtask_state = SubtaskState()
        subtask_state.status = SubtaskStatus.downloading
        subtask_state.subtask_id = subtask_id
        subtask_state.computer = Mock()
        subtask_state.computer.node_id = node_id

        task_state = TaskState()
        task_state.computer = Mock()
        task_state.subtask_states[subtask_id] = subtask_state

        sync_wait(self.tm.add_new_task(task_mock))
        self.tm.subtask2task_mapping[subtask_id] = "xyz"
        self.tm.tasks_states["xyz"] = task_state

        with patch("golem.task.taskbase.Task.result_incoming"
                   ) as result_incoming_mock:
            self.tm.task_result_incoming(subtask_id)
            assert result_incoming_mock.called

        self.tm.tasks = []
        with patch("golem.task.taskbase.Task.result_incoming"
                   ) as result_incoming_mock:
            self.tm.task_result_incoming(subtask_id)
            assert not result_incoming_mock.called