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_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)