def __init_basic_customizer(self): task_dialog = TaskDetailsDialog(self.gui.main_window.window) task_state = TaskDesc() ss1 = SubtaskState() ss1.subtask_id = "abc" ss1.computer.node_name ="ABC" ss1.computer.ip_address = "10.10.10.10" ss1.computer.performance = "1000" ss1.subtask_definition = "DEF 1" ss1.subtask_status = SubtaskStatus.downloading ss2 = SubtaskState() ss2.subtask_id = "def" ss2.computer.node_name = "DEF" ss2.computer.ip_address = "10.10.10.20" ss2.computer.performance = "2000" ss2.subtask_definition = "DEF 2" ss2.subtask_status = SubtaskStatus.starting ss3 = SubtaskState() ss3.subtask_id = "xyz" ss3.computer.node_name = "XYZ" ss3.computer.ip_address = "10.10.10.30" ss3.computer.performance = "3000" ss3.subtask_definition = "DEF 3" ss3.subtask_status = SubtaskStatus.finished task_state.task_state.subtask_states["abc"] = ss1 task_state.task_state.subtask_states["def"] = ss2 task_state.task_state.subtask_states["xyz"] = ss3 task_state.task_state.progress = 0.33 task_state.task_state.remaining_time = 34 task_state.task_state.elapsed_time = 12 customizer = TaskDetailsDialogCustomizer(task_dialog, self.logic, task_state) return customizer
def __add_subtask_to_tasks_states(self, node_name, node_id, price, ctd, address): if ctd.task_id not in self.tasks_states: raise RuntimeError("Should never be here!") logger.debug('add_subtask_to_tasks_states(%r, %r, %r, %r, %r)', node_name, node_id, price, ctd, address) ss = SubtaskState() ss.computer.node_id = node_id ss.computer.node_name = node_name ss.computer.performance = ctd.performance ss.computer.ip_address = address ss.computer.price = price ss.time_started = time.time() ss.deadline = ctd.deadline # TODO: read node ip address ss.subtask_definition = ctd.short_description ss.subtask_id = ctd.subtask_id ss.extra_data = ctd.extra_data ss.subtask_status = TaskStatus.starting ss.value = 0 self.tasks_states[ctd.task_id].subtask_states[ctd.subtask_id] = ss
def __add_subtask_to_tasks_states(self, node_name, node_id, ctd, address): logger.debug('add_subtask_to_tasks_states(%r, %r, %r, %r)', node_name, node_id, ctd, address) ss = SubtaskState() ss.time_started = time.time() ss.node_id = node_id ss.node_name = node_name ss.deadline = ctd['deadline'] ss.subtask_definition = ctd['short_description'] ss.subtask_id = ctd['subtask_id'] ss.extra_data = ctd['extra_data'] ss.subtask_status = SubtaskStatus.starting (self.tasks_states[ctd['task_id']].subtask_states[ctd['subtask_id']] ) = ss
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
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
def test_to_dictionary(): ss = SubtaskState() ss.subtask_definition = "My long task definition" ss.subtask_id = "ABCDEF" ss.subtask_progress = 0.92 ss.time_started = get_timestamp_utc() ss.deadline = timeout_to_deadline(ss.time_started + 5) ss.extra_data = {"param1": 1323, "param2": "myparam"} ss.subtask_rem_time = deadline_to_timeout( ss.deadline) - ss.time_started ss.subtask_status = SubtaskStatus.starting ss.value = 138 ss.stdout = "path/to/file" ss.stderr = "path/to/file2" ss.results = ["path/to/file3", "path/to/file4"] ss.computation_time = 130 ss.node_id = "NODE1" ss_dict = ss.to_dictionary() assert ss_dict['description'] == "My long task definition" assert ss_dict['subtask_id'] == "ABCDEF" assert ss_dict['progress'] == 0.92 assert ss_dict['time_started'] == get_timestamp_utc() assert ss_dict.get('deadline') is None assert ss_dict.get('extra_data') is None assert ss_dict['time_remaining'] == 5 assert ss_dict['status'] == SubtaskStatus.starting.value assert ss_dict.get('value') is None assert ss_dict['stdout'] == "path/to/file" assert ss_dict['stderr'] == "path/to/file2" assert ss_dict['results'] == ["path/to/file3", "path/to/file4"] assert ss_dict.get('computation_time') is None assert ss_dict['node_id'] == "NODE1"
def test_sorting(self): task_dialog = TaskDetailsDialog(self.gui.main_window.window) task_state = TaskDesc() customizer = TaskDetailsDialogCustomizer(task_dialog, self.logic, task_state) self.assertEqual(customizer.sorting, -1) self.assertIsNone(customizer.sorting_order) task_state.task_state.progress = 0.33 task_state.task_state.remaining_time = 34 task_state.task_state.elapsed_time = 12 ss1 = SubtaskState() ss1.computer.node_name = "ABC" ss1.subtask_id = "def" ss1.subtask_status = SubtaskStatus.finished task_state.task_state.subtask_states['def'] = ss1 ss2 = SubtaskState() ss2.computer.node_name = "DEF" ss2.subtask_id = "abc" ss2.subtask_status = SubtaskStatus.finished task_state.task_state.subtask_states['abc'] = ss2 customizer.update_view(task_state.task_state) self.assertEqual(customizer.sorting, -1) self.assertIsNone(customizer.sorting_order) self.assertEqual(len(customizer.subtask_table_elements), 2) ids = [str(customizer.gui.ui.nodesTableWidget.item(i, 1).text()) for i in range(2)] self.assertIn('def', ids) self.assertIn('abc', ids) customizer._TaskDetailsDialogCustomizer__header_clicked(1) self.assertEqual(customizer.sorting, 1) self.assertEqual(customizer.sorting_order, SortingOrder.ascending) self.assertEqual(len(customizer.subtask_table_elements), 2) self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(0, 0).text()), "DEF") self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(1, 0).text()), "ABC") self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(0, 1).text()), "abc") self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(1, 1).text()), "def") customizer._TaskDetailsDialogCustomizer__header_clicked(1) self.assertEqual(customizer.sorting, 1) self.assertEqual(customizer.sorting_order, SortingOrder.descending) self.assertEqual(len(customizer.subtask_table_elements), 2) self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(0, 0).text()), "ABC") self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(1, 0).text()), "DEF") self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(0, 1).text()), "def") self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(1, 1).text()), "abc") ss3 = SubtaskState() ss3.computer.node_name = "FGH" ss3.subtask_id = "fgh" ss3.subtask_status = SubtaskStatus.finished task_state.task_state.subtask_states['fgh'] = ss3 customizer.update_view(task_state.task_state) self.assertEqual(customizer.sorting, 1) self.assertEqual(customizer.sorting_order, SortingOrder.descending) self.assertEqual(len(customizer.subtask_table_elements), 3) self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(0, 0).text()), "FGH") self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(1, 0).text()), "ABC") self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(2, 0).text()), "DEF") self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(0, 1).text()), "fgh") self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(1, 1).text()), "def") self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(2, 1).text()), "abc") customizer._TaskDetailsDialogCustomizer__header_clicked(0) self.assertEqual(customizer.sorting, 0) self.assertEqual(customizer.sorting_order, SortingOrder.ascending) self.assertEqual(len(customizer.subtask_table_elements), 3) self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(0, 0).text()), "ABC") self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(1, 0).text()), "DEF") self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(2, 0).text()), "FGH") self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(0, 1).text()), "def") self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(1, 1).text()), "abc") self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(2, 1).text()), "fgh") customizer._TaskDetailsDialogCustomizer__header_clicked(0) self.assertEqual(customizer.sorting, 0) self.assertEqual(customizer.sorting_order, SortingOrder.descending) self.assertEqual(len(customizer.subtask_table_elements), 3) self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(0, 0).text()), "FGH") self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(1, 0).text()), "DEF") self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(2, 0).text()), "ABC") self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(0, 1).text()), "fgh") self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(1, 1).text()), "abc") self.assertEqual(str(customizer.gui.ui.nodesTableWidget.item(2, 1).text()), "def")