mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-19 04:57:54 +00:00
tests: clean up tearDown to use flushEventualQueue instead of hacking fixed-time delays
This commit is contained in:
parent
92ba8dc8d2
commit
2122fbaca9
@ -23,14 +23,12 @@ class TestIntroducer(unittest.TestCase):
|
|||||||
self.parent.startService()
|
self.parent.startService()
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
log.msg("TestIntroducer.tearDown")
|
log.msg("TestIntroducer.tearDown")
|
||||||
d = defer.Deferred()
|
d = defer.succeed(None)
|
||||||
reactor.callLater(1.1, d.callback, None)
|
|
||||||
d.addCallback(lambda res: self.parent.stopService())
|
d.addCallback(lambda res: self.parent.stopService())
|
||||||
d.addCallback(flushEventualQueue)
|
d.addCallback(flushEventualQueue)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def poll(self, check_f, pollinterval=0.01):
|
def poll(self, check_f, pollinterval=0.01):
|
||||||
# Return a Deferred, then call check_f periodically until it returns
|
# Return a Deferred, then call check_f periodically until it returns
|
||||||
# True, at which point the Deferred will fire.. If check_f raises an
|
# True, at which point the Deferred will fire.. If check_f raises an
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
from twisted.trial import unittest
|
from twisted.trial import unittest
|
||||||
|
from foolscap.eventual import flushEventualQueue
|
||||||
|
|
||||||
from allmydata import queen
|
from allmydata import queen
|
||||||
|
|
||||||
@ -8,5 +9,6 @@ class Basic(unittest.TestCase):
|
|||||||
q = queen.Queen()
|
q = queen.Queen()
|
||||||
d = q.startService()
|
d = q.startService()
|
||||||
d.addCallback(lambda res: q.stopService())
|
d.addCallback(lambda res: q.stopService())
|
||||||
|
d.addCallback(flushEventualQueue)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
@ -10,14 +10,6 @@ from twisted.python import log
|
|||||||
from twisted.web.client import getPage
|
from twisted.web.client import getPage
|
||||||
|
|
||||||
class SystemTest(unittest.TestCase):
|
class SystemTest(unittest.TestCase):
|
||||||
# it takes a little while for a disconnected loopback TCP connection to
|
|
||||||
# be noticed by the other side. This is not directly visible to us, so we
|
|
||||||
# have to wait for time to pass rather than just waiting on a deferred.
|
|
||||||
# This is unfortunate, both because it arbitrarily slows down the test
|
|
||||||
# process, and because it is hard to predict what the minimum time
|
|
||||||
# necessary would be (on a slow or heavily loaded system, 100ms might not
|
|
||||||
# be enough).
|
|
||||||
DISCONNECT_DELAY = 0.1
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.sparent = service.MultiService()
|
self.sparent = service.MultiService()
|
||||||
@ -25,12 +17,7 @@ class SystemTest(unittest.TestCase):
|
|||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
log.msg("shutting down SystemTest services")
|
log.msg("shutting down SystemTest services")
|
||||||
d = self.sparent.stopService()
|
d = self.sparent.stopService()
|
||||||
d.addCallback(lambda res: flushEventualQueue())
|
d.addCallback(flushEventualQueue)
|
||||||
def _done(res):
|
|
||||||
d1 = defer.Deferred()
|
|
||||||
reactor.callLater(self.DISCONNECT_DELAY, d1.callback, None)
|
|
||||||
return d1
|
|
||||||
d.addCallback(_done)
|
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def add_service(self, s):
|
def add_service(self, s):
|
||||||
@ -109,11 +96,7 @@ class SystemTest(unittest.TestCase):
|
|||||||
d.addCallback(_check)
|
d.addCallback(_check)
|
||||||
def _shutdown_extra_node(res):
|
def _shutdown_extra_node(res):
|
||||||
if self.extra_node:
|
if self.extra_node:
|
||||||
d1 = self.extra_node.stopService()
|
return self.extra_node.stopService()
|
||||||
d2 = defer.Deferred()
|
|
||||||
reactor.callLater(self.DISCONNECT_DELAY, d2.callback, res)
|
|
||||||
d1.addCallback(lambda ignored: d2)
|
|
||||||
return d1
|
|
||||||
return res
|
return res
|
||||||
d.addBoth(_shutdown_extra_node)
|
d.addBoth(_shutdown_extra_node)
|
||||||
return d
|
return d
|
||||||
|
Loading…
Reference in New Issue
Block a user