mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-24 07:06:41 +00:00
test_runner.py: test that client and introducer nodes record their port number and use that port on the next restart. This tests for a regression caused by ref #1385.
This commit is contained in:
parent
b9eb0235ea
commit
531758df19
@ -352,6 +352,7 @@ class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
|
|||||||
HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
|
HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
|
||||||
TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
|
TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
|
||||||
INTRODUCER_FURL_FILE = os.path.join(c1, "introducer.furl")
|
INTRODUCER_FURL_FILE = os.path.join(c1, "introducer.furl")
|
||||||
|
PORTNUM_FILE = os.path.join(c1, "introducer.port")
|
||||||
NODE_URL_FILE = os.path.join(c1, "node.url")
|
NODE_URL_FILE = os.path.join(c1, "node.url")
|
||||||
CONFIG_FILE = os.path.join(c1, "tahoe.cfg")
|
CONFIG_FILE = os.path.join(c1, "tahoe.cfg")
|
||||||
|
|
||||||
@ -401,9 +402,16 @@ class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
|
|||||||
d.addCallback(lambda res: self.poll(_node_has_started))
|
d.addCallback(lambda res: self.poll(_node_has_started))
|
||||||
|
|
||||||
def _started(res):
|
def _started(res):
|
||||||
|
# read the introducer.furl and introducer.port files so we can check that their
|
||||||
|
# contents don't change on restart
|
||||||
|
self.furl = fileutil.read(INTRODUCER_FURL_FILE)
|
||||||
|
self.failUnless(os.path.exists(PORTNUM_FILE))
|
||||||
|
self.portnum = fileutil.read(PORTNUM_FILE)
|
||||||
|
|
||||||
open(HOTLINE_FILE, "w").write("")
|
open(HOTLINE_FILE, "w").write("")
|
||||||
self.failUnless(os.path.exists(TWISTD_PID_FILE))
|
self.failUnless(os.path.exists(TWISTD_PID_FILE))
|
||||||
self.failUnless(os.path.exists(NODE_URL_FILE))
|
self.failUnless(os.path.exists(NODE_URL_FILE))
|
||||||
|
|
||||||
# rm this so we can detect when the second incarnation is ready
|
# rm this so we can detect when the second incarnation is ready
|
||||||
os.unlink(NODE_URL_FILE)
|
os.unlink(NODE_URL_FILE)
|
||||||
return self.run_bintahoe(["--quiet", "restart", c1])
|
return self.run_bintahoe(["--quiet", "restart", c1])
|
||||||
@ -425,8 +433,15 @@ class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
|
|||||||
return os.path.exists(NODE_URL_FILE)
|
return os.path.exists(NODE_URL_FILE)
|
||||||
d.addCallback(lambda res: self.poll(_node_has_restarted))
|
d.addCallback(lambda res: self.poll(_node_has_restarted))
|
||||||
|
|
||||||
|
def _check_same_furl_and_port(res):
|
||||||
|
self.failUnless(os.path.exists(INTRODUCER_FURL_FILE))
|
||||||
|
self.failUnlessEqual(self.furl, fileutil.read(INTRODUCER_FURL_FILE))
|
||||||
|
self.failUnless(os.path.exists(PORTNUM_FILE))
|
||||||
|
self.failUnlessEqual(self.portnum, fileutil.read(PORTNUM_FILE))
|
||||||
|
d.addCallback(_check_same_furl_and_port)
|
||||||
|
|
||||||
# now we can kill it. TODO: On a slow machine, the node might kill
|
# now we can kill it. TODO: On a slow machine, the node might kill
|
||||||
# itself before we get a chance too, especially if spawning the
|
# itself before we get a chance to, especially if spawning the
|
||||||
# 'tahoe stop' command takes a while.
|
# 'tahoe stop' command takes a while.
|
||||||
def _stop(res):
|
def _stop(res):
|
||||||
open(HOTLINE_FILE, "w").write("")
|
open(HOTLINE_FILE, "w").write("")
|
||||||
@ -472,7 +487,7 @@ class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
|
|||||||
c1 = os.path.join(basedir, "c1")
|
c1 = os.path.join(basedir, "c1")
|
||||||
HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
|
HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
|
||||||
TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
|
TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
|
||||||
PORTNUMFILE = os.path.join(c1, "client.port")
|
PORTNUM_FILE = os.path.join(c1, "client.port")
|
||||||
|
|
||||||
d = self.run_bintahoe(["--quiet", "create-client", "--basedir", c1, "--webport", "0"])
|
d = self.run_bintahoe(["--quiet", "create-client", "--basedir", c1, "--webport", "0"])
|
||||||
def _cb(res):
|
def _cb(res):
|
||||||
@ -480,11 +495,11 @@ class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
|
|||||||
errstr = "cc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
|
errstr = "cc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
|
||||||
assert rc_or_sig == 0, errstr
|
assert rc_or_sig == 0, errstr
|
||||||
self.failUnlessEqual(rc_or_sig, 0)
|
self.failUnlessEqual(rc_or_sig, 0)
|
||||||
# By writing this file, we get forty seconds before the client will exit. This insures
|
|
||||||
|
# By writing this file, we get two minutes before the client will exit. This ensures
|
||||||
# that even if the 'stop' command doesn't work (and the test fails), the client should
|
# that even if the 'stop' command doesn't work (and the test fails), the client should
|
||||||
# still terminate.
|
# still terminate.
|
||||||
open(HOTLINE_FILE, "w").write("")
|
open(HOTLINE_FILE, "w").write("")
|
||||||
fileutil.write(os.path.join(basedir, "tahoe.cfg"), BASECONFIG_I % "pb://xrndsskn2zuuian5ltnxrte7lnuqdrkz@127.0.0.1:55617/introducer")
|
|
||||||
# now it's safe to start the node
|
# now it's safe to start the node
|
||||||
d.addCallback(_cb)
|
d.addCallback(_cb)
|
||||||
|
|
||||||
@ -515,7 +530,7 @@ class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
|
|||||||
d.addCallback(_cb2)
|
d.addCallback(_cb2)
|
||||||
|
|
||||||
def _node_has_started():
|
def _node_has_started():
|
||||||
return os.path.exists(PORTNUMFILE)
|
return os.path.exists(PORTNUM_FILE)
|
||||||
d.addCallback(lambda res: self.poll(_node_has_started))
|
d.addCallback(lambda res: self.poll(_node_has_started))
|
||||||
|
|
||||||
# now we can kill it. TODO: On a slow machine, the node might kill
|
# now we can kill it. TODO: On a slow machine, the node might kill
|
||||||
@ -533,17 +548,23 @@ class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
|
|||||||
c1 = os.path.join(basedir, "c1")
|
c1 = os.path.join(basedir, "c1")
|
||||||
HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
|
HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
|
||||||
TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
|
TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
|
||||||
PORTNUMFILE = os.path.join(c1, "client.port")
|
PORTNUM_FILE = os.path.join(c1, "client.port")
|
||||||
|
NODE_URL_FILE = os.path.join(c1, "node.url")
|
||||||
|
CONFIG_FILE = os.path.join(c1, "tahoe.cfg")
|
||||||
|
|
||||||
d = self.run_bintahoe(["--quiet", "create-node", "--basedir", c1, "--webport", "0"])
|
d = self.run_bintahoe(["--quiet", "create-node", "--basedir", c1, "--webport", "0"])
|
||||||
def _cb(res):
|
def _cb(res):
|
||||||
out, err, rc_or_sig = res
|
out, err, rc_or_sig = res
|
||||||
self.failUnlessEqual(rc_or_sig, 0)
|
self.failUnlessEqual(rc_or_sig, 0)
|
||||||
# By writing this file, we get sixty seconds before the client will exit. This insures
|
|
||||||
|
# Check that the --webport option worked.
|
||||||
|
config = fileutil.read(CONFIG_FILE)
|
||||||
|
self.failUnlessIn('\nweb.port = 0\n', config)
|
||||||
|
|
||||||
|
# By writing this file, we get two minutes before the client will exit. This ensures
|
||||||
# that even if the 'stop' command doesn't work (and the test fails), the client should
|
# that even if the 'stop' command doesn't work (and the test fails), the client should
|
||||||
# still terminate.
|
# still terminate.
|
||||||
open(HOTLINE_FILE, "w").write("")
|
open(HOTLINE_FILE, "w").write("")
|
||||||
fileutil.write(os.path.join(c1, "tahoe.cfg"), BASECONFIG_I % "pb://xrndsskn2zuuian5ltnxrte7lnuqdrkz@127.0.0.1:55617/introducer")
|
|
||||||
# now it's safe to start the node
|
# now it's safe to start the node
|
||||||
d.addCallback(_cb)
|
d.addCallback(_cb)
|
||||||
|
|
||||||
@ -570,15 +591,19 @@ class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
|
|||||||
d.addCallback(_cb2)
|
d.addCallback(_cb2)
|
||||||
|
|
||||||
def _node_has_started():
|
def _node_has_started():
|
||||||
return os.path.exists(PORTNUMFILE)
|
return os.path.exists(NODE_URL_FILE)
|
||||||
d.addCallback(lambda res: self.poll(_node_has_started))
|
d.addCallback(lambda res: self.poll(_node_has_started))
|
||||||
|
|
||||||
def _started(res):
|
def _started(res):
|
||||||
|
# read the client.port file so we can check that its contents
|
||||||
|
# don't change on restart
|
||||||
|
self.portnum = fileutil.read(PORTNUM_FILE)
|
||||||
|
|
||||||
open(HOTLINE_FILE, "w").write("")
|
open(HOTLINE_FILE, "w").write("")
|
||||||
self.failUnless(os.path.exists(TWISTD_PID_FILE))
|
self.failUnless(os.path.exists(TWISTD_PID_FILE))
|
||||||
# rm this so we can detect when the second incarnation is ready
|
|
||||||
os.unlink(PORTNUMFILE)
|
|
||||||
|
|
||||||
|
# rm this so we can detect when the second incarnation is ready
|
||||||
|
os.unlink(NODE_URL_FILE)
|
||||||
return self.run_bintahoe(["--quiet", "restart", c1])
|
return self.run_bintahoe(["--quiet", "restart", c1])
|
||||||
d.addCallback(_started)
|
d.addCallback(_started)
|
||||||
|
|
||||||
@ -596,8 +621,12 @@ class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
|
|||||||
# so poll until it is
|
# so poll until it is
|
||||||
d.addCallback(lambda res: self.poll(_node_has_started))
|
d.addCallback(lambda res: self.poll(_node_has_started))
|
||||||
|
|
||||||
|
def _check_same_port(res):
|
||||||
|
self.failUnlessEqual(self.portnum, fileutil.read(PORTNUM_FILE))
|
||||||
|
d.addCallback(_check_same_port)
|
||||||
|
|
||||||
# now we can kill it. TODO: On a slow machine, the node might kill
|
# now we can kill it. TODO: On a slow machine, the node might kill
|
||||||
# itself before we get a chance too, especially if spawning the
|
# itself before we get a chance to, especially if spawning the
|
||||||
# 'tahoe stop' command takes a while.
|
# 'tahoe stop' command takes a while.
|
||||||
def _stop(res):
|
def _stop(res):
|
||||||
open(HOTLINE_FILE, "w").write("")
|
open(HOTLINE_FILE, "w").write("")
|
||||||
|
Loading…
Reference in New Issue
Block a user