From: Brian Warner Date: Wed, 4 Apr 2007 23:09:13 +0000 (-0700) Subject: tests: clean up tearDown to use flushEventualQueue instead of hacking fixed-time... X-Git-Url: https://git.rkrishnan.org/%5B/%5D%20/uri/%22file:/FOOURL?a=commitdiff_plain;h=2122fbaca929b11f479dd22273eb9de9ebe0aa0d;p=tahoe-lafs%2Ftahoe-lafs.git tests: clean up tearDown to use flushEventualQueue instead of hacking fixed-time delays --- diff --git a/src/allmydata/test/test_introducer.py b/src/allmydata/test/test_introducer.py index c1f78cdc..a0da3e55 100644 --- a/src/allmydata/test/test_introducer.py +++ b/src/allmydata/test/test_introducer.py @@ -23,14 +23,12 @@ class TestIntroducer(unittest.TestCase): self.parent.startService() def tearDown(self): log.msg("TestIntroducer.tearDown") - d = defer.Deferred() - reactor.callLater(1.1, d.callback, None) + d = defer.succeed(None) d.addCallback(lambda res: self.parent.stopService()) d.addCallback(flushEventualQueue) return d - def poll(self, check_f, pollinterval=0.01): # Return a Deferred, then call check_f periodically until it returns # True, at which point the Deferred will fire.. If check_f raises an diff --git a/src/allmydata/test/test_queen.py b/src/allmydata/test/test_queen.py index 0a242c4c..e60d4334 100644 --- a/src/allmydata/test/test_queen.py +++ b/src/allmydata/test/test_queen.py @@ -1,5 +1,6 @@ from twisted.trial import unittest +from foolscap.eventual import flushEventualQueue from allmydata import queen @@ -8,5 +9,6 @@ class Basic(unittest.TestCase): q = queen.Queen() d = q.startService() d.addCallback(lambda res: q.stopService()) + d.addCallback(flushEventualQueue) return d diff --git a/src/allmydata/test/test_system.py b/src/allmydata/test/test_system.py index 67df5489..c87ed5c1 100644 --- a/src/allmydata/test/test_system.py +++ b/src/allmydata/test/test_system.py @@ -10,14 +10,6 @@ from twisted.python import log from twisted.web.client import getPage 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): self.sparent = service.MultiService() @@ -25,12 +17,7 @@ class SystemTest(unittest.TestCase): def tearDown(self): log.msg("shutting down SystemTest services") d = self.sparent.stopService() - d.addCallback(lambda res: flushEventualQueue()) - def _done(res): - d1 = defer.Deferred() - reactor.callLater(self.DISCONNECT_DELAY, d1.callback, None) - return d1 - d.addCallback(_done) + d.addCallback(flushEventualQueue) return d def add_service(self, s): @@ -109,11 +96,7 @@ class SystemTest(unittest.TestCase): d.addCallback(_check) def _shutdown_extra_node(res): if self.extra_node: - d1 = self.extra_node.stopService() - d2 = defer.Deferred() - reactor.callLater(self.DISCONNECT_DELAY, d2.callback, res) - d1.addCallback(lambda ignored: d2) - return d1 + return self.extra_node.stopService() return res d.addBoth(_shutdown_extra_node) return d