예제 #1
0
    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()
예제 #2
0
    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()
예제 #3
0
    def test_thread(self):
        ts = mock.MagicMock()
        ts.config_desc = ClientConfigDescriptor()
        ts.benchmark_manager.benchmarks_needed.return_value = False
        ts.get_task_computer_root.return_value = self.new_path

        tc = TaskComputer(ts, use_docker_manager=False)
        tc.counting_task = True
        tc.waiting_for_task = None

        tt = self._new_task_thread(tc)
        sync_wait(tt.start())

        self.assertGreater(tt.end_time - tt.start_time, 0)
        self.assertLess(tt.end_time - tt.start_time, 20)
예제 #4
0
 def test_thread(self):
     files_ = self.additional_dir_content([0, [1], [1], [1], [1]])
     ts = mock.MagicMock()
     ts.config_desc = config_desc()
     tc = TaskComputer("ABC", ts, use_docker_machine_manager=False)
     tc.counting_task = True
     tc.waiting_for_task = None
     tt = PyTaskThread(
         tc, "xxyyzz", self.path,
         "cnt=0\nfor i in range(1000000):\n\tcnt += 1\noutput=cnt", {},
         "hello thread", os.path.dirname(files_[0]),
         os.path.dirname(files_[1]), 20)
     tt.run()
     self.assertGreater(tt.end_time - tt.start_time, 0)
     self.assertLess(tt.end_time - tt.start_time, 20)
     self.assertTrue(tc.counting_task)