def test_init_worker_positive(self, init_worker_mock): """Test init_worker method positive result.""" task_manager = TaskManager(is_lazy_pool_start=False) task_manager.start() try: init_worker_mock.assert_called() finally: task_manager.stop()
def test_start_already_started(self): """Test start method already started.""" obj = TaskManager() with mock.patch.object(obj.logger, "debug") as debug_mock: obj._stopped = False obj.start() debug_mock.assert_called_once() obj.stop()
class TestTaskPoolManagementManager(TestCase): """Tests for pool management by task manager. Lazy and non lazy.""" def tearDown(self): """Stop task manager. assumed it's created on each test.""" self.task_manager.stop() def test_start_stop_reflected_by_is_started(self) -> None: """Test is_started property of task manaher.""" self.task_manager = TaskManager() assert not self.task_manager.is_started self.task_manager.start() assert self.task_manager.is_started self.task_manager.stop() assert not self.task_manager.is_started def test_lazy_pool_not_started(self) -> None: """Lazy pool creation assumes pool create on first task enqueue.""" self.task_manager = TaskManager(is_lazy_pool_start=True) self.task_manager.start() assert not self.task_manager._pool def test_not_lazy_pool_is_started(self) -> None: """Lazy pool creation assumes pool create on first task enqueue.""" self.task_manager = TaskManager(is_lazy_pool_start=False) self.task_manager.start() assert self.task_manager._pool @patch("aea.skills.tasks.Pool.apply_async") def test_lazy_pool_start_on_enqueue(self, apply_async_mock: Mock) -> None: """ Test lazy pool created on enqueue once. :param apply_async_mock: is mock for aea.skills.tasks.Pool.apply_async """ self.task_manager = TaskManager(is_lazy_pool_start=True) self.task_manager.start() assert not self.task_manager._pool self.task_manager.enqueue_task(print) apply_async_mock.assert_called_once() assert self.task_manager._pool """Check pool created once on several enqueues""" pool = self.task_manager._pool self.task_manager.enqueue_task(print) assert self.task_manager._pool is pool
def test_start_lazy_pool_start(self): """Test start method with lazy pool start.""" obj = TaskManager(is_lazy_pool_start=False) with mock.patch.object(obj.logger, "debug") as debug_mock: obj.start() obj._stopped = True obj.start() debug_mock.assert_called_with("Pool was already started!") obj.start()
def test_start_already_started(self, debug_mock): """Test start method already started.""" obj = TaskManager() obj._stopped = False obj.start() debug_mock.assert_called_once()