def test_stop_service_stub_ignores_disconnected_agent(self): """The base class agent, stopService will the stop method. If the client is not connected then no attempt is made to close it. """ mock_agent = self.mocker.patch(BaseAgent) mock_client = self.mocker.mock(ZookeeperClient) # connection is closed after agent.stop invoked. with self.mocker.order(): mock_agent.stop() # client existence check mock_agent.client self.mocker.result(mock_client) # client connected check mock_agent.client self.mocker.result(mock_client) mock_client.connected self.mocker.result(False) self.mocker.replay() agent = BaseAgent() return agent.stopService()
def test_stop_service_stub_closes_agent(self): """The base class agent, stopService will the stop method. Additionally it will close the agent's zookeeper client if the client is still connected. """ mock_agent = self.mocker.patch(BaseAgent) mock_client = self.mocker.mock(ZookeeperClient) # connection is closed after agent.stop invoked. with self.mocker.order(): mock_agent.stop() self.mocker.passthrough() # client existence check mock_agent.client self.mocker.result(mock_client) # client connected check mock_agent.client self.mocker.result(mock_client) mock_client.connected self.mocker.result(True) # client close mock_agent.client self.mocker.result(mock_client) mock_client.close() self.mocker.replay() agent = BaseAgent() return agent.stopService()
def test_stop_service_stub_ignores_disconnected_agent(self): """The base class agent, stopService will the stop method. If the client is not connected then no attempt is made to close it. """ mock_agent = self.mocker.patch(BaseAgent) mock_client = self.mocker.mock(ZookeeperClient) session_file = self.makeFile() # connection is closed after agent.stop invoked. with self.mocker.order(): mock_agent.stop() # client existence check mock_agent.client self.mocker.result(mock_client) # client connected check mock_agent.client self.mocker.result(mock_client) mock_client.connected self.mocker.result(False) mock_agent.config self.mocker.result({"session_file": session_file}) self.mocker.replay() agent = BaseAgent() yield agent.stopService() self.assertFalse(os.path.exists(session_file))
def test_stop_service_stub_closes_agent(self): """The base class agent, stopService will the stop method. Additionally it will close the agent's zookeeper client if the client is still connected. """ mock_agent = self.mocker.patch(BaseAgent) mock_client = self.mocker.mock(ZookeeperClient) session_file = self.makeFile() # connection is closed after agent.stop invoked. with self.mocker.order(): mock_agent.stop() self.mocker.passthrough() # client existence check mock_agent.client self.mocker.result(mock_client) # client connected check mock_agent.client self.mocker.result(mock_client) mock_client.connected self.mocker.result(True) # client close mock_agent.client self.mocker.result(mock_client) mock_client.close() # delete session file mock_agent.config self.mocker.result({"session_file": session_file}) self.mocker.replay() agent = BaseAgent() yield agent.stopService() self.assertFalse(os.path.exists(session_file))