~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_server.py

  • Committer: Vincent Ladeuil
  • Date: 2010-06-04 11:48:56 UTC
  • mto: (5247.4.3 sftp-leaks)
  • mto: This revision was merged to the branch mainline in revision 5396.
  • Revision ID: v.ladeuil+lp@free.fr-20100604114856-7e505v5w40937ya5
All http tests passing, https failing.

* bzrlib/tests/test_server.py:
(TestingTCPServerInAThread): Daughter classes prefer to deal
with (host, port) while SocketServer classes use server_address.

* bzrlib/tests/test_http.py:
Fix some refactoring fallouts.

* bzrlib/tests/http_server.py:
(TestingHTTPServerMixin.__init__): Vastly simplified now that we
use TestingTCPServerInAThread.
(HttpServer.__init__, HttpServer.create_server)
(HttpServer.start_server): Simplified to the specifics.

Show diffs side-by-side

added added

removed removed

Lines of Context:
347
347
    def handle_error(self, request, client_address):
348
348
        # Stop serving and re-raise the last exception seen
349
349
        self.serving.clear()
 
350
        self.sibling_class.handle_error(self, request, client_address)
350
351
        raise
351
352
 
352
353
    # The following methods are called by the main thread
458
459
    def __init__(self, server_address, server_class, request_handler_class):
459
460
        self.server_class = server_class
460
461
        self.request_handler_class = request_handler_class
461
 
        self.server_address = server_address
 
462
        self.host, self.port = server_address
462
463
        self.server = None
463
464
 
464
465
    def __repr__(self):
465
 
        return "%s%r" % (self.__class__.__name__, self.server_address)
 
466
        return "%s(%s:%s)" % (self.__class__.__name__, self.host, self.port)
466
467
 
467
468
    def create_server(self):
468
 
        return self.server_class(self.server_address,
 
469
        return self.server_class((self.host, self.port),
469
470
                                 self.request_handler_class)
470
471
 
471
472
    def start_server(self):
476
477
        # Wait for the server thread to start (i.e release the lock)
477
478
        self.server.started.wait()
478
479
        # Get the real address, especially the port
479
 
        self.server_address = self.server.server_address
480
 
        self._server_thread.name = self.server_address
 
480
        self.host, self.port = self.server.server_address
 
481
        self._server_thread.name = '(%s:%s)' % (self.host, self.port)
481
482
        # If an exception occured during the server start, it will get raised,
482
483
        # otherwise, the server is blocked on its accept() call.
483
484
        self._server_thread.pending_exception()
499
500
            # The server is listening for a last connection, let's give it:
500
501
            last_conn = None
501
502
            try:
502
 
                last_conn = osutils.connect_socket(self.server.server_address)
 
503
                last_conn = osutils.connect_socket((self.host, self.port))
503
504
            except socket.error, e:
504
505
                # But ignore connection errors as the point is to unblock the
505
506
                # server thread, it may happen that it's not blocked or even