def test_termination(self): script = "import time\ntime.sleep(20)" task_server = Mock() task_server.config_desc = ClientConfigDescriptor() task_server.client.datadir = self.test_dir task_server.benchmark_manager = Mock() task_server.benchmark_manager.benchmarks_needed.return_value = False task_server.client.get_node_name.return_value = "test_node" task_server.get_task_computer_root.return_value = \ task_server.client.datadir task_computer = TaskComputer(task_server, use_docker_manager=False) image = DockerImage("golemfactory/base", tag="1.2") with self.assertRaises(AttributeError): dir_mapping = DockerTaskThread.generate_dir_mapping( self.resources_dir, self.output_dir) DockerTaskThread("subtask_id", None, script, None, dir_mapping, timeout=30) def test(): dir_mapping = DockerTaskThread.generate_dir_mapping( self.resources_dir, self.output_dir) tt = DockerTaskThread("subtask_id", [image], script, None, "test task thread", dir_mapping, timeout=30) task_computer.counting_thread = tt task_computer.counting_task = True tt.setDaemon(True) tt.start() time.sleep(1) started = time.time() parent_thread = Thread(target=test) parent_thread.start() time.sleep(1) ct = task_computer.counting_thread while ct and ct.is_alive(): task_computer.run() if time.time() - started > 15: self.fail("Job timed out") else: ct = task_computer.counting_thread time.sleep(1)
def test_run(self): task_server = mock.MagicMock() task_server.config_desc = config_desc() task_server.config_desc.task_request_interval = 0.5 task_server.config_desc.use_waiting_for_task_timeout = True task_server.config_desc.waiting_for_task_timeout = 1 task_server.config_desc.accept_tasks = True task_server.get_task_computer_root.return_value = self.path tc = TaskComputer("ABC", task_server, use_docker_machine_manager=False) self.assertFalse(tc.counting_task) self.assertEqual(len(tc.current_computations), 0) self.assertIsNone(tc.waiting_for_task) tc.last_task_request = 0 tc.run() task_server.request_task.assert_called_with() task_server.request_task = mock.MagicMock() task_server.config_desc.accept_tasks = False tc2 = TaskComputer("DEF", task_server, use_docker_machine_manager=False) tc2.counting_task = False tc2.current_computations = [] tc2.waiting_for_task = None tc2.last_task_request = 0 tc2.run() task_server.request_task.assert_not_called() tc2.runnable = True tc2.compute_tasks = True tc2.waiting_for_task = False tc2.counting_task = False tc2.last_task_request = 0 tc2.current_computations = [] tc2.run() assert task_server.request_task.called task_server.request_task.called = False tc2.waiting_for_task = 'xxyyzz' tc2.use_waiting_ttl = True tc2.last_checking = 10**10 tc2.run() tc2.session_timeout()
def test_run(self): task_server = self.task_server task_server.config_desc.task_request_interval = 0.5 task_server.config_desc.accept_tasks = True task_server.get_task_computer_root.return_value = self.path tc = TaskComputer(task_server, use_docker_manager=False) self.assertIsNone(tc.counting_task) self.assertIsNone(tc.counting_thread) self.assertIsNone(tc.waiting_for_task) tc.last_task_request = 0 tc.run() task_server.request_task.assert_called_with() task_server.request_task = mock.MagicMock() task_server.config_desc.accept_tasks = False tc2 = TaskComputer(task_server, use_docker_manager=False) tc2.counting_task = None tc2.counting_thread = None tc2.waiting_for_task = None tc2.last_task_request = 0 tc2.run() task_server.request_task.assert_not_called() tc2.runnable = True tc2.compute_tasks = True tc2.waiting_for_task = False tc2.counting_task = None tc2.last_task_request = 0 tc2.counting_thread = None tc2.run() assert task_server.request_task.called task_server.request_task.called = False tc2.waiting_for_task = 'xxyyzz' tc2.use_waiting_ttl = True tc2.last_checking = 10**10 tc2.run() tc2.session_timeout()
def test_termination(self): script = "import time\ntime.sleep(20)" task_server = Mock() task_server.config_desc = ClientConfigDescriptor() task_server.config_desc.estimated_blender_performance = 2000.0 task_server.config_desc.estimated_lux_performance = 2000.0 task_server.client.datadir = self.test_dir task_server.client.get_node_name.return_value = "test_node" task_server.get_task_computer_root.return_value = task_server.client.datadir task_computer = TaskComputer("node", task_server, use_docker_machine_manager=False) image = DockerImage("golemfactory/base", tag="1.2") with self.assertRaises(AttributeError): DockerTaskThread(task_computer, "subtask_id", None, self.work_dir, script, None, "test task thread", self.resources_dir, self.output_dir, timeout=30) def test(): tt = DockerTaskThread(task_computer, "subtask_id", [image], self.work_dir, script, None, "test task thread", self.resources_dir, self.output_dir, timeout=30) task_computer.current_computations.append(tt) task_computer.counting_task = True tt.setDaemon(True) tt.start() time.sleep(1) started = time.time() parent_thread = Thread(target=test) parent_thread.start() time.sleep(1) ct = task_computer.current_computations[0] while ct and ct.is_alive(): task_computer.run() if time.time() - started > 15: self.fail("Job timed out") elif task_computer.current_computations: ct = task_computer.current_computations[0] else: ct = None time.sleep(1)