def test__twistdBin(self): """ Should know what twistd to use. """ runner = Runner() path = commands.getoutput('which twistd') self.assertEqual(runner._twistdBin(), path)
def test_twistd(self): """ Should run twistd with the given arguments """ runner = Runner() fake_twistd = FilePath(self.mktemp()) fake_twistd.setContent('#!%s\n' 'import sys, os\n' 'print " ".join(sys.argv[1:])\n' 'print os.environ["FOO"]\n' 'print os.path.abspath(os.curdir)\n' 'sys.stdout.flush()\n' 'sys.stderr.write("error\\n")\n' 'print "stdout"\n' 'sys.exit(4)\n' % sys.executable) fake_twistd.chmod(0777) runner._twistdBin = lambda: fake_twistd.path path = FilePath(self.mktemp()) path.makedirs() d = runner.twistd(['foo', 'bar', 'baz'], env={'FOO': 'foo value'}, path=path.path) def check(result): out, err, code = result self.assertEqual(code, 4) self.assertEqual(out, 'foo bar baz\n' 'foo value\n' '%s\n' 'stdout\n' % path.path) self.assertEqual(err, 'error\n') return d.addCallback(check)
def test_switch(self): """ Switch should work """ runner = Runner() # I'm getting AF_UNIX path too long errors using self.mktemp() base = FilePath(tempfile.mkdtemp()) log.msg('tmpdir: %r' % base.path) root = base.child('root') src = base.child('src') dst = base.child('dst') _ = yield runner.start(root.path, 'unix:'+src.path, 'unix:'+dst.path) pidfile = root.child('grace.pid') pid = pidfile.getContent() self.addCleanup(self.kill, pid) r = yield runner.switch(root.path, 'unix:'+src.path, 'unix:/foo') r = yield runner.ls(root.path) self.assertEqual(r, [ { 'src': 'unix:'+src.path, 'dst': 'unix:/foo', 'conns': 0, 'active': True, } ], "Should have switched")
def test_stop(self): """ Stop will stop a running process. """ runner = Runner() # I'm getting AF_UNIX path too long errors using self.mktemp() base = FilePath(tempfile.mkdtemp()) log.msg('tmpdir: %r' % base.path) root = base.child('root') src = base.child('src') dst = base.child('dst') _ = yield runner.start(root.path, 'unix:'+src.path, 'unix:'+dst.path) pidfile = root.child('grace.pid') pid = pidfile.getContent() self.addCleanup(self.kill, pid) _ = yield runner.stop(root.path) # tail the log until you see Server Shut Down # XXX stop should maybe do the same... so that it doesn't return until # the process has actually stopped. logfile = root.child('grace.log') self.assertTrue(logfile.exists()) _ = yield self.tailUntil(logfile.path, 'Server Shut Down.') self.assertFalse(pidfile.exists(), "pidfile should be gone: %r" % pidfile.path)
def test_start_waits(self): """ Start should not return until it's actually working. """ runner = Runner() base = FilePath(tempfile.mkdtemp()) root = base.child('root') src = base.child('src') dst = base.child('dst') _ = yield runner.start(root.path, 'unix:'+src.path, 'unix:'+dst.path) self.assertTrue(root.child('grace.pid').exists(), "Should have a pid") pid = root.child('grace.pid').getContent().strip() self.addCleanup(self.kill, pid) self.assertTrue(root.child('grace.socket').exists(), "Should have a " "socket") self.assertTrue(root.exists(), "Should have made the root dir") tac = root.child('grace.tac') self.assertTrue(tac.exists(), "Should have made grace.tac") self.assertEqual(tac.getContent(), getTac(('unix:'+src.path, 'unix:'+dst.path)), "Should have made the tac file using getTac")
def test_wait(self): """ Wait should work """ runner = Runner() # I'm getting AF_UNIX path too long errors using self.mktemp() base = FilePath(tempfile.mkdtemp()) log.msg('tmpdir: %r' % base.path) root = base.child('root') src = base.child('src') dst = base.child('dst') _ = yield runner.start(root.path, 'unix:'+src.path, 'unix:'+dst.path) pidfile = root.child('grace.pid') pid = pidfile.getContent() self.addCleanup(self.kill, pid) r = yield runner.wait(root.path, 'unix:'+src.path)