/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 bzrlib/tests/test_smart_transport.py

  • Committer: Andrew Bennetts
  • Date: 2008-05-13 11:32:15 UTC
  • mto: This revision was merged to the branch mainline in revision 3428.
  • Revision ID: andrew.bennetts@canonical.com-20080513113215-gtr2ul998vg6taif
Distinguish between errors in decoding a message into message parts from errors in handling decoded message parts, and use that to make sure that entire requests are read even when they result in exceptions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2322
2322
        self.assertEqual(('error', 'abc'), exc.error_tuple)
2323
2323
 
2324
2324
 
 
2325
class TestMessageHandlerErrors(tests.TestCase):
 
2326
    """Tests for v3 that unrecognised (but well-formed) requests/responses are
 
2327
    still fully read off the wire, so that subsequent requests/responses on the
 
2328
    same medium can be decoded.
 
2329
    """
 
2330
 
 
2331
    def test_non_conventional_request(self):
 
2332
        """ConventionalRequestHandler (the default message handler on the
 
2333
        server side) will reject an unconventional message, but still consume
 
2334
        all the bytes of that message and signal when it has done so.
 
2335
 
 
2336
        This is what allows a server to continue to accept requests after the
 
2337
        client sends a completely unrecognised request.
 
2338
        """
 
2339
        # Define an invalid request (but one that is a well-formed message).
 
2340
        # This particular invalid request not only lacks the mandatory
 
2341
        # verb+args tuple, it has a single-byte part, which is forbidden.  In
 
2342
        # fact it has that part twice, to trigger multiple errors.
 
2343
        invalid_request = (
 
2344
            protocol.MESSAGE_VERSION_THREE +  # protocol version marker
 
2345
            '\0\0\0\x02de' + # empty headers
 
2346
            'oX' + # a single byte part: 'X'.  ConventionalRequestHandler will
 
2347
                   # error at this part.
 
2348
            'oX' + # and again.
 
2349
            'e' # end of message
 
2350
            )
 
2351
 
 
2352
        to_server = StringIO(invalid_request)
 
2353
        from_server = StringIO()
 
2354
        transport = memory.MemoryTransport('memory:///')
 
2355
        server = medium.SmartServerPipeStreamMedium(
 
2356
            to_server, from_server, transport)
 
2357
        proto = server._build_protocol()
 
2358
        message_handler = proto.message_handler
 
2359
        server._serve_one_request(proto)
 
2360
        # All the bytes have been read from the medium...
 
2361
        self.assertEqual('', to_server.read())
 
2362
        # ...and the protocol decoder has consumed all the bytes, and has
 
2363
        # finished reading.
 
2364
        self.assertEqual('', proto.unused_data)
 
2365
        self.assertEqual(0, proto.next_read_size())
 
2366
 
 
2367
 
2325
2368
class InstrumentedRequestHandler(object):
2326
2369
    """Test Double of SmartServerRequestHandler."""
2327
2370