Ejemplo n.º 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()
Ejemplo n.º 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()