mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-02-21 10:01:54 +00:00
Apply David-Sarah's recommended changes. Closes #974
This commit is contained in:
parent
4f19f2b4b4
commit
15c95c2e12
@ -27,6 +27,13 @@ def parse_url(url, defaultPort=None):
|
||||
path = "/"
|
||||
return scheme, host, port, path
|
||||
|
||||
class BadResponse(object):
|
||||
def __init__(self, url, err):
|
||||
self.status = -1
|
||||
self.reason = "Error trying to connect to %s: %s" % (url, err)
|
||||
def read(self):
|
||||
return ""
|
||||
|
||||
|
||||
def do_http(method, url, body=""):
|
||||
if isinstance(body, str):
|
||||
@ -62,12 +69,8 @@ def do_http(method, url, body=""):
|
||||
try:
|
||||
c.endheaders()
|
||||
except socket_error, err:
|
||||
class BadResponse(object):
|
||||
status=-1
|
||||
reason="Error trying to connect to %s: %s" % (url, err)
|
||||
read=lambda _: ""
|
||||
return BadResponse()
|
||||
|
||||
return BadResponse(url, err)
|
||||
|
||||
while True:
|
||||
data = body.read(8192)
|
||||
if not data:
|
||||
|
@ -3288,19 +3288,16 @@ class Errors(GridTestMixin, CLITestMixin, unittest.TestCase):
|
||||
self.set_up_grid()
|
||||
|
||||
# Simulate a connection error
|
||||
endheaders = allmydata.scripts.common_http.httplib.HTTPConnection.endheaders
|
||||
def _fix_endheaders(*args):
|
||||
allmydata.scripts.common_http.httplib.HTTPConnection.endheaders = endheaders
|
||||
def _socket_error(*args, **kwargs):
|
||||
raise socket_error('test error')
|
||||
allmydata.scripts.common_http.httplib.HTTPConnection.endheaders = _socket_error
|
||||
self.patch(allmydata.scripts.common_http.httplib.HTTPConnection,
|
||||
"endheaders", _socket_error)
|
||||
|
||||
d = self.do_cli("mkdir")
|
||||
def _check_invalid((rc,stdout,stderr)):
|
||||
self.failIfEqual(rc, 0)
|
||||
self.failUnlessIn("Error trying to connect to http://127.0.0.1", stderr)
|
||||
d.addCallback(_check_invalid)
|
||||
d.addCallback(_fix_endheaders)
|
||||
return d
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user