def test_kill_unstarted(self): """ Try to kill the component if it's not started. Should not fail. We do not try to kill a running component, as we should not start it during unit tests. """ component = Component('component', self, 'needed') component.kill() component.kill(True)
def test_component_kill(self): """ Check the kill is propagated. The case when component wasn't started yet is already tested elsewhere. """ class Process: def __init__(self): self.killed = False self.terminated = False def kill(self): self.killed = True def terminate(self): self.terminated = True process = Process() class ProcInfo: def __init__(self): self.process = process self.pid = 42 component = Component('component', self, 'needed', 'Address', [], ProcInfo) component.start() self.assertTrue(component.is_running()) component.kill() self.assertTrue(process.terminated) self.assertFalse(process.killed) process.terminated = False component.kill(True) self.assertTrue(process.killed) self.assertFalse(process.terminated)
def test_component_attributes(self): """ Test the default attributes of Component (not BaseComponent) and some of the methods we might be allowed to call. """ class TestProcInfo: def __init__(self): self.pid = 42 component = Component('component', self, 'needed', 'Address', ['hello'], TestProcInfo) self.assertEqual('component', component._process) self.assertEqual('component', component.name()) self.assertIsNone(component._procinfo) self.assertIsNone(component.pid()) self.assertEqual(['hello'], component._params) self.assertEqual('Address', component._address) self.assertFalse(component.is_running()) self.assertEqual({}, self.__registered_processes) component.start() self.assertTrue(component.is_running()) # Some versions of unittest miss assertIsInstance self.assertTrue(isinstance(component._procinfo, TestProcInfo)) self.assertEqual(42, component.pid()) self.assertEqual(component, self.__registered_processes.get(42))
def __create_component(self, kind): """ Convenience function that creates a component of given kind and installs the mock functions into it so we can hook up into its behaviour. The process used is some nonsense, as this isn't used in this kind of tests and we pretend to be the b10-init. """ component = Component('No process', self, kind, 'homeless', []) component._start_internal = self.__start component._stop_internal = self.__stop component._failed_internal = self.__fail return component
def test_component_kill(self): """ Check the kill is propagated. The case when component wasn't started yet is already tested elsewhere. """ class Process: def __init__(self): self.killed = False self.terminated = False def kill(self): self.killed = True def terminate(self): self.terminated = True process = Process() class ProcInfo: def __init__(self): self.process = process self.pid = 42 component = Component('component', self, 'needed', 'Address', [], ProcInfo) component.start() self.assertTrue(component.running()) component.kill() self.assertTrue(process.terminated) self.assertFalse(process.killed) process.terminated = False component.kill(True) self.assertTrue(process.killed) self.assertFalse(process.terminated)
def __create_component(self, kind): """ Convenience function that creates a component of given kind and installs the mock functions into it so we can hook up into its behaviour. The process used is some nonsense, as this isn't used in this kind of tests and we pretend to be the boss. """ component = Component('No process', self, kind, 'homeless', []) component._start_internal = self.__start component._stop_internal = self.__stop component._failed_internal = self.__fail return component
def test_component_start_stop_internal(self): """ Test the behavior of _stop_internal and _start_internal. """ component = Component('component', self, 'needed', 'Address') component.start() self.assertTrue(component.is_running()) self.assertEqual('component', self.__start_simple_params) component.pid = lambda: 42 component.stop() self.assertFalse(component.is_running()) self.assertEqual(('component', 'Address', 42), self.__stop_process_params)
def test_component_start_stop_internal(self): """ Test the behavior of _stop_internal and _start_internal. """ component = Component('component', self, 'needed', 'Address') component.start() self.assertTrue(component.running()) self.assertEqual('component', self.__start_simple_params) component.pid = lambda: 42 component.stop() self.assertFalse(component.running()) self.assertEqual(('component', 'Address', 42), self.__stop_process_params)
def test_component_attributes(self): """ Test the default attributes of Component (not BaseComponent) and some of the methods we might be allowed to call. """ class TestProcInfo: def __init__(self): self.pid = 42 component = Component('component', self, 'needed', 'Address', ['hello'], TestProcInfo) self.assertEqual('component', component._process) self.assertEqual('component', component.name()) self.assertIsNone(component._procinfo) self.assertIsNone(component.pid()) self.assertEqual(['hello'], component._params) self.assertEqual('Address', component._address) self.assertFalse(component.running()) self.assertEqual({}, self.__registered_processes) component.start() self.assertTrue(component.running()) # Some versions of unittest miss assertIsInstance self.assertTrue(isinstance(component._procinfo, TestProcInfo)) self.assertEqual(42, component.pid()) self.assertEqual(component, self.__registered_processes.get(42))
def __init__(self, process, b10_init, kind, address=None, params=None): Component.__init__(self, process, b10_init, kind, 'Auth', None, b10_init.start_auth)
def __init__(self, process, b10_init, kind, address=None, params=None): Component.__init__(self, process, b10_init, kind, 'ConfigManager', None, b10_init.start_cfgmgr)
def __init__(self, process, b10_init, kind, address=None, params=None): Component.__init__(self, process, b10_init, kind, None, None, b10_init.start_msgq)
def __init__(self, process, b10_init, kind, address=None, params=None): Component.__init__(self, process, b10_init, kind, 'Cmdctl', None, b10_init.start_cmdctl)
def __init__(self, process, b10_init, kind, address=None, params=None): Component.__init__(self, process, b10_init, kind, 'Resolver', None, b10_init.start_resolver)