testutil: factor stall() out into a common location

This commit is contained in:
Brian Warner 2008-04-22 16:47:15 -07:00
parent 57d5341715
commit 81ab1ec785
4 changed files with 11 additions and 19 deletions

View File

@ -7,7 +7,7 @@ from twisted.python import log
import allmydata
from allmydata import client, introducer
from allmydata.util import base32
from allmydata.util import base32, testutil
from foolscap.eventual import flushEventualQueue
class FakeIntroducerClient(introducer.IntroducerClient):
@ -145,7 +145,7 @@ def flush_but_dont_ignore(res):
d.addCallback(_done)
return d
class Run(unittest.TestCase):
class Run(unittest.TestCase, testutil.StallMixin):
def setUp(self):
self.sparent = service.MultiService()
@ -163,11 +163,6 @@ class Run(unittest.TestCase):
open(os.path.join(basedir, "suicide_prevention_hotline"), "w")
c = client.Client(basedir)
def stall(self, res=None, delay=1):
d = defer.Deferred()
reactor.callLater(delay, d.callback, res)
return d
def test_reloadable(self):
basedir = "test_client.Run.test_reloadable"
os.mkdir(basedir)

View File

@ -64,7 +64,7 @@ class FakeClient:
return d
class Dirnode(unittest.TestCase, testutil.ShouldFailMixin):
class Dirnode(unittest.TestCase, testutil.ShouldFailMixin, testutil.StallMixin):
def setUp(self):
self.client = FakeClient()
@ -162,11 +162,6 @@ class Dirnode(unittest.TestCase, testutil.ShouldFailMixin):
def failUnlessGreaterOrEqualThan(self, a, b):
self.failUnless(a >= b, "%r should be >= %r" % (a, b))
def stall(self, res, delay=1.0):
d = defer.Deferred()
reactor.callLater(delay, d.callback, res)
return d
def test_create(self):
self.expected_manifest = []

View File

@ -50,7 +50,8 @@ class CountingDataUploadable(upload.Data):
return upload.Data.read(self, length)
class SystemTest(testutil.SignalMixin, testutil.PollMixin, unittest.TestCase):
class SystemTest(testutil.SignalMixin, testutil.PollMixin, testutil.StallMixin,
unittest.TestCase):
def setUp(self):
self.sparent = service.MultiService()
@ -978,11 +979,6 @@ class SystemTest(testutil.SignalMixin, testutil.PollMixin, unittest.TestCase):
log.msg(msg, **kwargs)
return res
def stall(self, res, delay=1.0):
d = defer.Deferred()
reactor.callLater(delay, d.callback, res)
return d
def _do_publish_private(self, res):
self.smalldata = "sssh, very secret stuff"
ut = upload.Data(self.smalldata, convergence=None)

View File

@ -57,6 +57,12 @@ class PollMixin:
if check_f():
lc.stop()
class StallMixin:
def stall(self, res=None, delay=1):
d = defer.Deferred()
reactor.callLater(delay, d.callback, res)
return d
class ShouldFailMixin:
def shouldFail(self, expected_failure, which, substring,