class TestInvalidTunnels(unittest.TestCase): def setUp(self): self.tunnel = TunnelBase(['ls'], 'DOESNOTEXIST') self.tm = TunnelManager() self.tm.tunnels.append(self.tunnel) def test_start_bad_exec(self): self.tm.start_tunnels() # No error was raised self.assertFalse(self.tunnel.is_running()) def test_continue_bad_exec(self): self.tm.continue_tunnels() # No error was raised self.assertFalse(self.tunnel.is_running())
class TestLongRun(TearDownRunForever): def setUp(self): self.executable = 'cal_run_forever' self.cmd = [self.executable] self.t = TunnelBase(self.cmd, self.executable) self.tm = TunnelManager() self.tm.tunnels = [self.t] def tearDown(self): signal.signal(signal.SIGCHLD, signal.SIG_IGN) try: subprocess.call("ps auxww | grep %s | awk '{print $2}' | xargs kill" % self.executable, shell=True) except OSError: pass def test_single_run(self): self.tm.start_tunnels() self.tm.continue_tunnels() time.sleep(1) self.assertTrue(is_really_running(self.t)) def test_close_running_externally_handled(self): self.tm.start_tunnels() proc = self.t.proc os.kill(proc.pid, signal.SIGTERM) # Wait for the process to close _wait_for_condition(lambda : not self.t.is_running(), "Process not closed") self.assertFalse(self.t.is_running()) def test_continue_after_kill(self): self.tm.start_tunnels() self.t.close(wait=False) _wait_for_condition(lambda: not is_really_running(self.t), "Process not stopped") self.tm.continue_tunnels() _wait_for_condition(lambda: is_really_running(self.t), "Process not started") self.assertTrue(is_really_running(self.t))
class TestStartingSingleTunnel(TearDownRunForever): def setUp(self): self.executable = 'cal_run_forever' self.cmd = [self.executable] self.t = TunnelBase(self.cmd, self.executable) self.tm = TunnelManager() self.tm.tunnels = [self.t] def test_start_success(self): self.tm.start_tunnels() self.assertTrue(self.t.is_running()) def test_continue_not_started(self): """ Calling continue before starting shouldn't error out """ self.tm.continue_tunnels() def test_continue_post_start(self): self.tm.start_tunnels() self.tm.continue_tunnels() self.assertTrue(self.t.is_running()) def test_vanilla_continue(self): self.tm.start_tunnels() self.tm.continue_tunnels() self.assertTrue(self.t.is_running()) def test_close(self): self.tm.start_tunnels() self.t.close(wait=False)
class TestInvalidTunnel(unittest.TestCase): def setUp(self): cmd = ['ls'] executable = 'lsDOESNOTEXIST' self.t = TunnelBase(cmd, executable) def test_open_fail(self): """ Test that ``TunnelBase.open`` returns ``False`` on a failed process open. Uses the ``ls`` unix program since it will return right away. """ self.assertRaises(ExecutableNotFound, self.t.open) def test_isrunning_failure(self): """ Test that TunnelBase.is_running correctly detects a process that failed to run. """ self.assertRaises(ExecutableNotFound, self.t.open) is_running = self.t.is_running() self.assertFalse(is_running, 'ls should not be running') def test_close_failure(self): """ Test that calling ``TunnelBase.close`` on a process that failed to start doesn't throw any errors. """ self.assertRaises(ExecutableNotFound, self.t.open) self.t.close() self.t.close(force=True) self.assertFalse(self.t.is_running())
class TestInvalidTunnel(unittest.TestCase): def setUp(self): cmd = ['ls'] executable = 'lsDOESNOTEXIST' self.t = TunnelBase(cmd, executable) def test_open_fail(self): """ Test that ``TunnelBase.open`` returns ``False`` on a failed process open. Uses the ``ls`` unix program since it will return right away. """ self.assertRaises(ExecutableNotFound, self.t.open) def test_isrunning_failure(self): """ Test that TunnelBase.is_running correctly detects a process that failed to run. """ self.assertRaises(ExecutableNotFound, self.t.open) is_running = self.t.is_running() self.assertFalse(is_running, 'ls should not be running') def test_close_failure(self): """ Test that calling ``TunnelBase.close`` on a process that failed to start doesn't throw any errors. """ self.assertRaises(ExecutableNotFound, self.t.open) self.t.close() self.t.close(force=True) self.assertFalse(self.t.is_running())
class TestValidTunnel(unittest.TestCase): def setUp(self): self.executable = 'cal_run_forever' self.cmd = [self.executable] self.t = TunnelBase(self.cmd, self.executable) def tearDown(self): subprocess.call(['killall', self.executable]) def test_open_proc(self): """ Test that ``TunnelBase.open`` returns the Popen object on a successful process open and also sets the proc attribute. """ proc = self.t.open() self.assertNotEqual(proc, None) self.assertEqual(proc, self.t.proc) def test_isrunning_success(self): """ Test that TunnelBase.is_running correctly detects a currently running process. """ proc = self.t.open() is_running = self.t.is_running() self.assertTrue(is_running, '%s should still be running' % self.executable) def test_isrunning_closed(self): """ Test that TunnelBase.is_running correctly detects a process that has been closed. """ proc = self.t.open() os.kill(self.t.proc.pid, signal.SIGKILL) self.t.proc.wait() # Wait for the process to close is_running = self.t.is_running() self.assertFalse(is_running, '%s should not be running' % self.executable) def test_close_running(self): """ Test that calling ``TunnelBase.close`` on a running process actually closes it. """ proc = self.t.open() self.t.close() is_running = self.t.is_running() self.assertFalse(is_running) def test_close_running_force(self): """ Test that calling ``TunnelBase.close`` with force=True on a running process actually closes it. """ proc = self.t.open() self.t.close(force=True) is_running = self.t.is_running() self.assertFalse(is_running) def test_close_already_closed(self): """ Test that calling ``TunnelBase.close`` on a process that is already closed doesn't throw any errors. """ proc = self.t.open() os.kill(self.t.proc.pid, signal.SIGKILL) self.t.proc.wait() self.t.close() self.t.close(force=True) self.assertFalse(self.t.is_running())
class TestValidTunnel(unittest.TestCase): def setUp(self): self.executable = 'cal_run_forever' self.cmd = [self.executable] self.t = TunnelBase(self.cmd, self.executable) def tearDown(self): subprocess.call(['killall', self.executable]) def test_open_proc(self): """ Test that ``TunnelBase.open`` returns the Popen object on a successful process open and also sets the proc attribute. """ proc = self.t.open() self.assertNotEqual(proc, None) self.assertEqual(proc, self.t.proc) def test_isrunning_success(self): """ Test that TunnelBase.is_running correctly detects a currently running process. """ proc = self.t.open() is_running = self.t.is_running() self.assertTrue(is_running, '%s should still be running' % self.executable) def test_isrunning_closed(self): """ Test that TunnelBase.is_running correctly detects a process that has been closed. """ proc = self.t.open() os.kill(self.t.proc.pid, signal.SIGKILL) self.t.proc.wait() # Wait for the process to close is_running = self.t.is_running() self.assertFalse(is_running, '%s should not be running' % self.executable) def test_close_running(self): """ Test that calling ``TunnelBase.close`` on a running process actually closes it. """ proc = self.t.open() self.t.close() is_running = self.t.is_running() self.assertFalse(is_running) def test_close_running_force(self): """ Test that calling ``TunnelBase.close`` with force=True on a running process actually closes it. """ proc = self.t.open() self.t.close(force=True) is_running = self.t.is_running() self.assertFalse(is_running) def test_close_already_closed(self): """ Test that calling ``TunnelBase.close`` on a process that is already closed doesn't throw any errors. """ proc = self.t.open() os.kill(self.t.proc.pid, signal.SIGKILL) self.t.proc.wait() self.t.close() self.t.close(force=True) self.assertFalse(self.t.is_running())