Rev 4899: Show that we try to retry the request if the first attempt fails. in http://bazaar.launchpad.net/~jameinel/bzr/2.1-client-reconnect-819604
John Arbash Meinel
john at arbash-meinel.com
Fri Oct 7 11:58:07 UTC 2011
At http://bazaar.launchpad.net/~jameinel/bzr/2.1-client-reconnect-819604
------------------------------------------------------------
revno: 4899
revision-id: john at arbash-meinel.com-20111007115742-ufmzjl8nudfdmq18
parent: john at arbash-meinel.com-20111006140132-k8z0kyg59z2v8bb8
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1-client-reconnect-819604
timestamp: Fri 2011-10-07 13:57:42 +0200
message:
Show that we try to retry the request if the first attempt fails.
-------------- next part --------------
=== modified file 'bzrlib/smart/client.py'
--- a/bzrlib/smart/client.py 2011-10-06 14:01:32 +0000
+++ b/bzrlib/smart/client.py 2011-10-07 11:57:42 +0000
@@ -69,7 +69,6 @@
self._send_request_no_retry(encoder, method, args, body=body,
readv_body=readv_body, body_stream=body_stream)
except errors.ConnectionReset, e:
- raise
# If we fail during the _send_request_no_retry phase, then we can
# be confident that the server did not get our request, because we
# haven't started waiting for the reply yet. So try the request
=== modified file 'bzrlib/tests/test_smart_transport.py'
--- a/bzrlib/tests/test_smart_transport.py 2011-10-06 14:01:32 +0000
+++ b/bzrlib/tests/test_smart_transport.py 2011-10-07 11:57:42 +0000
@@ -89,6 +89,26 @@
return StringIOSSHConnection(self)
+class FirstRejectedStringIOSSHVendor(StringIOSSHVendor):
+ """The first connection will be considered closed.
+
+ The second connection will succeed normally.
+ """
+
+ def __init__(self, read_from, write_to):
+ super(FirstRejectedStringIOSSHVendor, self).__init__(read_from,
+ write_to)
+ self._first = True
+
+ def connect_ssh(self, username, password, host, port, command):
+ self.calls.append(('connect_ssh', username, password, host, port,
+ command))
+ if self._first:
+ self._first = False
+ return ClosedSSHConnection(self)
+ return StringIOSSHConnection(self)
+
+
class StringIOSSHConnection(object):
"""A SSH connection that uses StringIO to buffer writes and answer reads."""
@@ -104,6 +124,24 @@
return self.vendor.read_from, self.vendor.write_to
+class ClosedSSHConnection(object):
+ """An SSH connection that just has closed channels."""
+
+ def __init__(self, vendor):
+ self.vendor = vendor
+
+ def close(self):
+ self.vendor.calls.append(('close', ))
+
+ def get_filelike_channels(self):
+ # We create matching pipes, and then close the ssh side
+ ssh_read, bzr_write = create_file_pipes()
+ bzr_read, ssh_write = create_file_pipes()
+ ssh_read.close()
+ ssh_write.close()
+ return bzr_read, bzr_write
+
+
class _InvalidHostnameFeature(tests.Feature):
"""Does 'non_existent.invalid' fail to resolve?
@@ -3363,6 +3401,27 @@
self.assertRaises(errors.ConnectionReset,
handler.read_response_tuple, expect_body=False)
+ def test__send_request_retries(self):
+ response = StringIO()
+ output = StringIO()
+ vendor = FirstRejectedStringIOSSHVendor(response, output)
+ client_medium = medium.SmartSSHClientMedium(
+ 'a host', 'a port', 'a user', 'a pass', 'base', vendor,
+ 'bzr')
+ smart_client = client._SmartClient(client_medium)
+ handler = smart_client._send_request(3, 'hello', ())
+ message_sent = output.getvalue()
+ self.assertStartsWith(message_sent, 'bzr message 3 (bzr 1.6)\n')
+ self.assertEndsWith(message_sent, 's\x00\x00\x00\tl5:helloee')
+ self.assertEqual(
+ [('connect_ssh', 'a user', 'a pass', 'a host', 'a port',
+ ['bzr', 'serve', '--inet', '--directory=/', '--allow-writes']),
+ ('close',),
+ ('connect_ssh', 'a user', 'a pass', 'a host', 'a port',
+ ['bzr', 'serve', '--inet', '--directory=/', '--allow-writes']),
+ ],
+ vendor.calls)
+
class LengthPrefixedBodyDecoder(tests.TestCase):
More information about the bazaar-commits
mailing list