/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_smart_transport.py

  • Committer: Jelmer Vernooij
  • Date: 2018-05-27 18:00:21 UTC
  • mto: (6973.12.2 python3-k)
  • mto: This revision was merged to the branch mainline in revision 6992.
  • Revision ID: jelmer@jelmer.uk-20180527180021-kbdxgsh5bbbxha8o
Random bunch of python3 bee-improvements.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1190
1190
        # This should timeout quickly, and then close the connection so that
1191
1191
        # client_sock recv doesn't block.
1192
1192
        server.serve()
1193
 
        self.assertEqual('', client_sock.recv(1))
 
1193
        self.assertEqual(b'', client_sock.recv(1))
1194
1194
 
1195
1195
    def test_pipe_wait_for_bytes_with_timeout_with_data(self):
1196
1196
        # We intentionally use a real pipe here, so that we can 'select' on it.
2532
2532
        self.assertEqual(expected_bytes[0:2], smart_protocol.read_body_bytes(2))
2533
2533
        self.assertEqual(expected_bytes[2:4], smart_protocol.read_body_bytes(2))
2534
2534
        self.assertEqual(expected_bytes[4:6], smart_protocol.read_body_bytes(2))
2535
 
        self.assertEqual(expected_bytes[6], smart_protocol.read_body_bytes())
 
2535
        self.assertEqual(expected_bytes[6:7], smart_protocol.read_body_bytes())
2536
2536
 
2537
2537
    def test_client_cancel_read_body_does_not_eat_body_bytes(self):
2538
2538
        # cancelling the expected body needs to finish the request, but not
3757
3757
 
3758
3758
class Test_SmartClientRequest(tests.TestCase):
3759
3759
 
3760
 
    def make_client_with_failing_medium(self, fail_at_write=True, response=''):
 
3760
    def make_client_with_failing_medium(self, fail_at_write=True, response=b''):
3761
3761
        response_io = BytesIO(response)
3762
3762
        output = BytesIO()
3763
3763
        vendor = FirstRejectedBytesIOSSHVendor(response_io, output,
3824
3824
        client_medium = medium.SmartTCPClientMedium(host, port, '/')
3825
3825
        client_medium._ensure_connection()
3826
3826
        smart_client = client._SmartClient(client_medium)
3827
 
        smart_request = client._SmartClientRequest(smart_client, 'hello', ())
 
3827
        smart_request = client._SmartClientRequest(smart_client, b'hello', ())
3828
3828
        # Accept the connection, but don't actually talk to the client.
3829
3829
        server_sock, _ = listen_sock.accept()
3830
3830
        server_sock.close()
3836
3836
 
3837
3837
    def test__send_retries_on_write(self):
3838
3838
        output, vendor, smart_client = self.make_client_with_failing_medium()
3839
 
        smart_request = client._SmartClientRequest(smart_client, 'hello', ())
 
3839
        smart_request = client._SmartClientRequest(smart_client, b'hello', ())
3840
3840
        handler = smart_request._send(3)
3841
 
        self.assertEqual('bzr message 3 (bzr 1.6)\n' # protocol
3842
 
                         '\x00\x00\x00\x02de'   # empty headers
3843
 
                         's\x00\x00\x00\tl5:helloee',
 
3841
        self.assertEqual(b'bzr message 3 (bzr 1.6)\n' # protocol
 
3842
                         b'\x00\x00\x00\x02de'   # empty headers
 
3843
                         b's\x00\x00\x00\tl5:helloee',
3844
3844
                         output.getvalue())
3845
3845
        self.assertEqual(
3846
3846
            [('connect_ssh', 'a user', 'a pass', 'a host', 'a port',
3854
3854
    def test__send_doesnt_retry_read_failure(self):
3855
3855
        output, vendor, smart_client = self.make_client_with_failing_medium(
3856
3856
            fail_at_write=False)
3857
 
        smart_request = client._SmartClientRequest(smart_client, 'hello', ())
 
3857
        smart_request = client._SmartClientRequest(smart_client, b'hello', ())
3858
3858
        handler = smart_request._send(3)
3859
 
        self.assertEqual('bzr message 3 (bzr 1.6)\n' # protocol
3860
 
                         '\x00\x00\x00\x02de'   # empty headers
3861
 
                         's\x00\x00\x00\tl5:helloee',
 
3859
        self.assertEqual(b'bzr message 3 (bzr 1.6)\n' # protocol
 
3860
                         b'\x00\x00\x00\x02de'   # empty headers
 
3861
                         b's\x00\x00\x00\tl5:helloee',
3862
3862
                         output.getvalue())
3863
3863
        self.assertEqual(
3864
3864
            [('connect_ssh', 'a user', 'a pass', 'a host', 'a port',
3869
3869
 
3870
3870
    def test__send_request_retries_body_stream_if_not_started(self):
3871
3871
        output, vendor, smart_client = self.make_client_with_failing_medium()
3872
 
        smart_request = client._SmartClientRequest(smart_client, 'hello', (),
3873
 
            body_stream=['a', 'b'])
 
3872
        smart_request = client._SmartClientRequest(smart_client, b'hello', (),
 
3873
            body_stream=[b'a', b'b'])
3874
3874
        response_handler = smart_request._send(3)
3875
3875
        # We connect, get disconnected, and notice before consuming the stream,
3876
3876
        # so we try again one time and succeed.