Rev 4906: Small refactor, add a test helper to make it easier to set up testing. in http://bazaar.launchpad.net/~jameinel/bzr/2.1-client-reconnect-819604

John Arbash Meinel john at arbash-meinel.com
Mon Oct 10 12:02:11 UTC 2011


At http://bazaar.launchpad.net/~jameinel/bzr/2.1-client-reconnect-819604

------------------------------------------------------------
revno: 4906
revision-id: john at arbash-meinel.com-20111010120153-8evage2354iga53o
parent: john at arbash-meinel.com-20111008102315-5y0yk3bnxhpa86el
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1-client-reconnect-819604
timestamp: Mon 2011-10-10 14:01:53 +0200
message:
  Small refactor, add a test helper to make it easier to set up testing.
-------------- next part --------------
=== modified file 'bzrlib/tests/test_smart_transport.py'
--- a/bzrlib/tests/test_smart_transport.py	2011-10-08 09:43:14 +0000
+++ b/bzrlib/tests/test_smart_transport.py	2011-10-10 12:01:53 +0000
@@ -98,7 +98,7 @@
     def __init__(self, read_from, write_to, fail_at_write=True):
         super(FirstRejectedStringIOSSHVendor, self).__init__(read_from,
             write_to)
-        self.fail_at_write= fail_at_write
+        self.fail_at_write = fail_at_write
         self._first = True
 
     def connect_ssh(self, username, password, host, port, command):
@@ -3381,6 +3381,17 @@
 
 class Test_SmartClientRequest(tests.TestCase):
 
+    def make_client_with_failing_medium(self, fail_at_write=True):
+        response = StringIO()
+        output = StringIO()
+        vendor = FirstRejectedStringIOSSHVendor(response, output,
+                    fail_at_write=fail_at_write)
+        client_medium = medium.SmartSSHClientMedium(
+            'a host', 'a port', 'a user', 'a pass', 'base', vendor,
+            'bzr')
+        smart_client = client._SmartClient(client_medium)
+        return output, vendor, smart_client
+
     def test__send_no_retry_pipes(self):
         client_read, server_write = create_file_pipes()
         server_read, client_write = create_file_pipes()
@@ -3414,13 +3425,7 @@
             handler.read_response_tuple, expect_body=False)
 
     def test__send_retries_on_write(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)
+        output, vendor, smart_client = self.make_client_with_failing_medium()
         smart_request = client._SmartClientRequest(smart_client, 'hello', ())
         handler = smart_request._send(3)
         message_sent = output.getvalue()
@@ -3436,14 +3441,8 @@
             vendor.calls)
 
     def test__send_doesnt_retry_read_failure(self):
-        response = StringIO()
-        output = StringIO()
-        vendor = FirstRejectedStringIOSSHVendor(response, output,
-                    fail_at_write=False)
-        client_medium = medium.SmartSSHClientMedium(
-            'a host', 'a port', 'a user', 'a pass', 'base', vendor,
-            'bzr')
-        smart_client = client._SmartClient(client_medium)
+        output, vendor, smart_client = self.make_client_with_failing_medium(
+            fail_at_write=False)
         smart_request = client._SmartClientRequest(smart_client, 'hello', ())
         handler = smart_request._send(3)
         message_sent = output.getvalue()
@@ -3460,13 +3459,7 @@
         # We don't know how much of body_stream would get iterated as part of
         # _send before it failed to actually send the request, so we
         # just always fail in this condition.
-        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)
+        output, vendor, smart_client = self.make_client_with_failing_medium()
         smart_request = client._SmartClientRequest(smart_client, 'hello', (),
             body_stream=['a', 'b'])
         self.assertRaises(errors.ConnectionReset, smart_request._send, 3)



More information about the bazaar-commits mailing list