~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart_transport.py

  • Committer: Robert Collins
  • Date: 2009-03-02 07:20:02 UTC
  • mfrom: (4067 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4069.
  • Revision ID: robertc@robertcollins.net-20090302072002-8e20qt9mv3asyy86
Merge bzr.dev [fix conflicts with fetch refactoring].

Show diffs side-by-side

added added

removed removed

Lines of Context:
2385
2385
        return response_handler
2386
2386
 
2387
2387
    def test_interrupted_by_error(self):
2388
 
        interrupted_body_stream = (
2389
 
            'oS' # successful response
2390
 
            's\0\0\0\x02le' # empty args
2391
 
            'b\0\0\0\x09chunk one' # first chunk
2392
 
            'b\0\0\0\x09chunk two' # second chunk
2393
 
            'oE' # error flag
2394
 
            's\0\0\0\x0el5:error3:abce' # bencoded error
2395
 
            'e' # message end
2396
 
            )
2397
2388
        response_handler = self.make_response_handler(interrupted_body_stream)
2398
2389
        stream = response_handler.read_streamed_body()
2399
 
        self.assertEqual('chunk one', stream.next())
2400
 
        self.assertEqual('chunk two', stream.next())
 
2390
        self.assertEqual('aaa', stream.next())
 
2391
        self.assertEqual('bbb', stream.next())
2401
2392
        exc = self.assertRaises(errors.ErrorFromSmartServer, stream.next)
2402
 
        self.assertEqual(('error', 'abc'), exc.error_tuple)
 
2393
        self.assertEqual(('error', 'Boom!'), exc.error_tuple)
2403
2394
 
2404
2395
    def test_interrupted_by_connection_lost(self):
2405
2396
        interrupted_body_stream = (
2796
2787
        self.calls.append('finished_writing')
2797
2788
 
2798
2789
 
 
2790
interrupted_body_stream = (
 
2791
    'oS' # status flag (success)
 
2792
    's\x00\x00\x00\x08l4:argse' # args struct ('args,')
 
2793
    'b\x00\x00\x00\x03aaa' # body part ('aaa')
 
2794
    'b\x00\x00\x00\x03bbb' # body part ('bbb')
 
2795
    'oE' # status flag (error)
 
2796
    's\x00\x00\x00\x10l5:error5:Boom!e' # err struct ('error', 'Boom!')
 
2797
    'e' # EOM
 
2798
    )
 
2799
 
 
2800
 
2799
2801
class TestResponseEncodingProtocolThree(tests.TestCase):
2800
2802
 
2801
2803
    def make_response_encoder(self):
2817
2819
            # end of message
2818
2820
            'e')
2819
2821
 
 
2822
    def test_send_broken_body_stream(self):
 
2823
        encoder, out_stream = self.make_response_encoder()
 
2824
        encoder._headers = {}
 
2825
        def stream_that_fails():
 
2826
            yield 'aaa'
 
2827
            yield 'bbb'
 
2828
            raise Exception('Boom!')
 
2829
        response = _mod_request.SuccessfulSmartServerResponse(
 
2830
            ('args',), body_stream=stream_that_fails())
 
2831
        encoder.send_response(response)
 
2832
        expected_response = (
 
2833
            'bzr message 3 (bzr 1.6)\n'  # protocol marker
 
2834
            '\x00\x00\x00\x02de' # headers dict (empty)
 
2835
            + interrupted_body_stream)
 
2836
        self.assertEqual(expected_response, out_stream.getvalue())
 
2837
 
2820
2838
 
2821
2839
class TestResponseEncoderBufferingProtocolThree(tests.TestCase):
2822
2840
    """Tests for buffering of responses.