1 | diff -rN -u old-tahoe/src/allmydata/test/no_network.py new-tahoe/src/allmydata/test/no_network.py |
---|
2 | --- old-tahoe/src/allmydata/test/no_network.py 2010-01-28 06:42:33.700000000 +0000 |
---|
3 | +++ new-tahoe/src/allmydata/test/no_network.py 2010-01-28 06:42:37.414000000 +0000 |
---|
4 | @@ -16,7 +16,7 @@ |
---|
5 | import os.path |
---|
6 | from zope.interface import implements |
---|
7 | from twisted.application import service |
---|
8 | -from twisted.internet import reactor |
---|
9 | +from twisted.internet import defer, reactor |
---|
10 | from twisted.python.failure import Failure |
---|
11 | from foolscap.api import Referenceable, fireEventually, RemoteException |
---|
12 | from base64 import b32encode |
---|
13 | @@ -38,6 +38,7 @@ |
---|
14 | def __init__(self, original): |
---|
15 | self.original = original |
---|
16 | self.broken = False |
---|
17 | + self.hung_until = None |
---|
18 | self.post_call_notifier = None |
---|
19 | self.disconnectors = {} |
---|
20 | |
---|
21 | @@ -57,11 +58,25 @@ |
---|
22 | return a |
---|
23 | args = tuple([wrap(a) for a in args]) |
---|
24 | kwargs = dict([(k,wrap(kwargs[k])) for k in kwargs]) |
---|
25 | + |
---|
26 | + def _really_call(): |
---|
27 | + meth = getattr(self.original, "remote_" + methname) |
---|
28 | + return meth(*args, **kwargs) |
---|
29 | + |
---|
30 | def _call(): |
---|
31 | if self.broken: |
---|
32 | raise IntentionalError("I was asked to break") |
---|
33 | - meth = getattr(self.original, "remote_" + methname) |
---|
34 | - return meth(*args, **kwargs) |
---|
35 | + if self.hung_until: |
---|
36 | + d2 = defer.Deferred() |
---|
37 | + self.hung_until.addCallback(lambda ign: _really_call()) |
---|
38 | + self.hung_until.addCallback(lambda res: d2.callback(res)) |
---|
39 | + def _err(res): |
---|
40 | + d2.errback(res) |
---|
41 | + return res |
---|
42 | + self.hung_until.addErrback(_err) |
---|
43 | + return d2 |
---|
44 | + return _really_call() |
---|
45 | + |
---|
46 | d = fireEventually() |
---|
47 | d.addCallback(lambda res: _call()) |
---|
48 | def _wrap_exception(f): |
---|
49 | @@ -240,6 +255,11 @@ |
---|
50 | # asked to hold a share |
---|
51 | self.servers_by_id[serverid].broken = True |
---|
52 | |
---|
53 | + def hang_server(self, serverid, until=defer.Deferred()): |
---|
54 | + # hang the given server until 'until' fires |
---|
55 | + self.servers_by_id[serverid].hung_until = until |
---|
56 | + |
---|
57 | + |
---|
58 | class GridTestMixin: |
---|
59 | def setUp(self): |
---|
60 | self.s = service.MultiService() |
---|