~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart_transport.py

  • Committer: Vincent Ladeuil
  • Date: 2010-06-29 16:21:13 UTC
  • mfrom: (5325 +trunk)
  • mto: (5247.1.12 first-try)
  • mto: This revision was merged to the branch mainline in revision 5326.
  • Revision ID: v.ladeuil+lp@free.fr-20100629162113-xa6y33u17mfi024v
Merge bzr.dev into cleanup resolving conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
2864
2864
        self.responder = protocol.ProtocolThreeResponder(self.writes.append)
2865
2865
 
2866
2866
    def assertWriteCount(self, expected_count):
 
2867
        # self.writes can be quite large; don't show the whole thing
2867
2868
        self.assertEqual(
2868
2869
            expected_count, len(self.writes),
2869
 
            "Too many writes: %r" % (self.writes,))
 
2870
            "Too many writes: %d, expected %d" % (len(self.writes), expected_count))
2870
2871
 
2871
2872
    def test_send_error_writes_just_once(self):
2872
2873
        """An error response is written to the medium all at once."""
2895
2896
        response = _mod_request.SuccessfulSmartServerResponse(
2896
2897
            ('arg', 'arg'), body_stream=['chunk1', 'chunk2'])
2897
2898
        self.responder.send_response(response)
2898
 
        # We will write just once, despite the multiple chunks, due to
2899
 
        # buffering.
2900
 
        self.assertWriteCount(1)
2901
 
 
2902
 
    def test_send_response_with_body_stream_flushes_buffers_sometimes(self):
2903
 
        """When there are many bytes (>1MB), multiple writes will occur rather
2904
 
        than buffering indefinitely.
2905
 
        """
2906
 
        # Construct a response with stream with ~1.5MB in it. This should
2907
 
        # trigger 2 writes, but not 3
2908
 
        onekib = '12345678' * 128
2909
 
        body_stream = [onekib] * (1024 + 512)
2910
 
        response = _mod_request.SuccessfulSmartServerResponse(
2911
 
            ('arg', 'arg'), body_stream=body_stream)
2912
 
        self.responder.send_response(response)
2913
 
        self.assertWriteCount(2)
 
2899
        # Per the discussion in bug 590638 we flush once after the header and
 
2900
        # then once after each chunk
 
2901
        self.assertWriteCount(3)
2914
2902
 
2915
2903
 
2916
2904
class TestSmartClientUnicode(tests.TestCase):