/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_test_server.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-16 23:15:15 UTC
  • mfrom: (7180 work)
  • mto: This revision was merged to the branch mainline in revision 7183.
  • Revision ID: jelmer@jelmer.uk-20181116231515-zqd2yn6kj8lfydyp
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
218
218
            # We use 'request' instead of 'self' below because the test matters
219
219
            # more and we need a container to properly set connection_thread.
220
220
            def handle_connection(request):
221
 
                req = request.readline()
 
221
                request.readline()
222
222
                # Capture the thread and make it use 'caught' so we can wait on
223
223
                # the event that will be set when the exception is caught. We
224
224
                # also capture the thread to know where to look.
233
233
        client.write(b'ping\n')
234
234
        # Wait for the exception to be caught
235
235
        caught.wait()
236
 
        self.assertEqual(b'', client.read()) # connection closed
 
236
        self.assertEqual(b'', client.read())  # connection closed
237
237
        # Check that the connection thread did catch the exception,
238
238
        # http://pad.lv/869366 was wrongly checking the server thread which
239
239
        # works for TestingTCPServer where the connection is handled in the
252
252
        # so the handler below can access it when it's executed (it's
253
253
        # instantiated when the request is processed)
254
254
        self.connection_thread = None
 
255
 
255
256
        class CantServe(Exception):
256
257
            pass
257
258
 
277
278
        client.connect((server.host, server.port))
278
279
        # Wait for the exception to be caught
279
280
        caught.wait()
280
 
        self.assertEqual(b'', client.read()) # connection closed
 
281
        self.assertEqual(b'', client.read())  # connection closed
281
282
        # The connection wasn't served properly but the exception should have
282
283
        # been swallowed (see test_server_crash_while_responding remark about
283
284
        # http://pad.lv/869366 explaining why we can't check the server thread
302
303
class TestTestingSmartServer(tests.TestCase):
303
304
 
304
305
    def test_sets_client_timeout(self):
305
 
        server = test_server.TestingSmartServer(('localhost', 0), None, None,
 
306
        server = test_server.TestingSmartServer(
 
307
            ('localhost', 0), None, None,
306
308
            root_client_path='/no-such-client/path')
307
309
        self.assertEqual(test_server._DEFAULT_TESTING_CLIENT_TIMEOUT,
308
310
                         server._client_timeout)
325
327
        s = FakeServer()
326
328
        server_sock, client_sock = portable_socket_pair()
327
329
        # This should timeout quickly, but not generate an exception.
328
 
        handler = test_server.TestingSmartConnectionHandler(server_sock,
329
 
            server_sock.getpeername(), s)
 
330
        test_server.TestingSmartConnectionHandler(
 
331
            server_sock, server_sock.getpeername(), s)
330
332
 
331
333
    def test_connection_shutdown_while_serving_no_error(self):
332
334
        s = FakeServer()
333
335
        server_sock, client_sock = portable_socket_pair()
 
336
 
334
337
        class ShutdownConnectionHandler(
335
 
            test_server.TestingSmartConnectionHandler):
 
338
                test_server.TestingSmartConnectionHandler):
336
339
 
337
340
            def _build_protocol(self):
338
341
                self.finished = True
339
342
                return super(ShutdownConnectionHandler, self)._build_protocol()
340
343
        # This should trigger shutdown after the entering _build_protocol, and
341
344
        # we should exit cleanly, without raising an exception.
342
 
        handler = ShutdownConnectionHandler(server_sock,
343
 
            server_sock.getpeername(), s)
 
345
        ShutdownConnectionHandler(server_sock, server_sock.getpeername(), s)