~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/http_server.py

  • Committer: John Arbash Meinel
  • Date: 2010-05-11 10:45:26 UTC
  • mto: This revision was merged to the branch mainline in revision 5225.
  • Revision ID: john@arbash-meinel.com-20100511104526-zxnstcxta22hzw2n
Implement a compiled extension for parsing the text key out of a CHKInventory value.

Related to bug #562666. This seems to shave 5-10% out of the time spent doing a complete
branch of bzr.dev/launchpad/etc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2006-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
31
31
import urlparse
32
32
 
33
33
from bzrlib import transport
 
34
from bzrlib.tests import test_server
34
35
from bzrlib.transport import local
35
36
 
36
37
 
318
319
        self.test_case_server = test_case_server
319
320
        self._home_dir = test_case_server._home_dir
320
321
 
321
 
    def tearDown(self):
 
322
    def stop_server(self):
322
323
         """Called to clean-up the server.
323
324
 
324
325
         Since the server may be (surely is, even) in a blocking listen, we
347
348
             # 'Socket is not connected' can also occur on OSX, with a
348
349
             # "regular" ENOTCONN (when something went wrong during test case
349
350
             # setup leading to self.setUp() *not* being called but
350
 
             # self.tearDown() still being called -- vila20081106
 
351
             # self.stop_server() still being called -- vila20081106
351
352
             if not len(e.args) or e.args[0] not in (errno.ENOTCONN, 10057):
352
353
                 raise
353
354
         # Let the server properly close the socket
382
383
        # lying around.
383
384
        self.daemon_threads = True
384
385
 
 
386
    def process_request_thread(self, request, client_address):
 
387
        SocketServer.ThreadingTCPServer.process_request_thread(
 
388
            self, request, client_address)
 
389
        # Under some circumstances (as in bug #383920), we need to force the
 
390
        # shutdown as python delays it until gc occur otherwise and the client
 
391
        # may hang.
 
392
        try:
 
393
            # The request process has been completed, the thread is about to
 
394
            # die, let's shutdown the socket if we can.
 
395
            request.shutdown(socket.SHUT_RDWR)
 
396
        except (socket.error, select.error), e:
 
397
            if e[0] in (errno.EBADF, errno.ENOTCONN):
 
398
                # Right, the socket is already down
 
399
                pass
 
400
            else:
 
401
                raise
 
402
 
385
403
 
386
404
class HttpServer(transport.Server):
387
405
    """A test server for http transports.
445
463
                raise httplib.UnknownProtocol(proto_vers)
446
464
            else:
447
465
                self._httpd = self.create_httpd(serv_cls, rhandler)
448
 
            host, self.port = self._httpd.socket.getsockname()
 
466
            self.host, self.port = self._httpd.socket.getsockname()
449
467
        return self._httpd
450
468
 
451
469
    def _http_start(self):
477
495
            except socket.timeout:
478
496
                pass
479
497
            except (socket.error, select.error), e:
480
 
               if e[0] == errno.EBADF:
481
 
                   # Starting with python-2.6, handle_request may raise socket
482
 
                   # or select exceptions when the server is shut down (as we
483
 
                   # do).
484
 
                   pass
485
 
               else:
486
 
                   raise
 
498
                if (e[0] == errno.EBADF
 
499
                    or (sys.platform == 'win32' and e[0] == 10038)):
 
500
                    # Starting with python-2.6, handle_request may raise socket
 
501
                    # or select exceptions when the server is shut down (as we
 
502
                    # do).
 
503
                    # 10038 = WSAENOTSOCK
 
504
                    # http://msdn.microsoft.com/en-us/library/ms740668%28VS.85%29.aspx
 
505
                    pass
 
506
                else:
 
507
                    raise
487
508
 
488
509
    def _get_remote_url(self, path):
489
510
        path_parts = path.split(os.path.sep)
501
522
        """Capture Server log output."""
502
523
        self.logs.append(format % args)
503
524
 
504
 
    def setUp(self, backing_transport_server=None):
505
 
        """See bzrlib.transport.Server.setUp.
 
525
    def start_server(self, backing_transport_server=None):
 
526
        """See bzrlib.transport.Server.start_server.
506
527
 
507
528
        :param backing_transport_server: The transport that requests over this
508
529
            protocol should be forwarded to. Note that this is currently not
510
531
        """
511
532
        # XXX: TODO: make the server back onto vfs_server rather than local
512
533
        # disk.
513
 
        if not (backing_transport_server is None or \
514
 
                isinstance(backing_transport_server, local.LocalURLServer)):
 
534
        if not (backing_transport_server is None
 
535
                or isinstance(backing_transport_server,
 
536
                              test_server.LocalURLServer)):
515
537
            raise AssertionError(
516
538
                "HTTPServer currently assumes local transport, got %s" % \
517
539
                backing_transport_server)
537
559
        self._http_starting.release()
538
560
        self.logs = []
539
561
 
540
 
    def tearDown(self):
541
 
        """See bzrlib.transport.Server.tearDown."""
542
 
        self._httpd.tearDown()
 
562
    def stop_server(self):
 
563
        self._httpd.stop_server()
543
564
        self._http_running = False
544
565
        # We don't need to 'self._http_thread.join()' here since the thread is
545
566
        # a daemonic one and will be garbage collected anyway. Joining just