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

  • Committer: Jelmer Vernooij
  • Date: 2018-05-06 11:48:54 UTC
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180506114854-h4qd9ojaqy8wxjsd
Move .mailmap to root.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
    import SocketServer as socketserver
23
23
import sys
24
24
import threading
 
25
import traceback
25
26
 
26
27
 
27
28
from breezy import (
249
250
 
250
251
class TestThread(cethread.CatchingExceptionThread):
251
252
 
252
 
    if not getattr(cethread.CatchingExceptionThread, 'is_alive', None):
253
 
        def is_alive(self):
254
 
            return self.isAlive()
255
 
 
256
253
    def join(self, timeout=5):
257
254
        """Overrides to use a default timeout.
258
255
 
260
257
        serving a client connection is hung.
261
258
        """
262
259
        super(TestThread, self).join(timeout)
263
 
        if timeout and self.is_alive():
 
260
        if timeout and self.isAlive():
264
261
            # The timeout expired without joining the thread, the thread is
265
262
            # therefore stucked and that's a failure as far as the test is
266
263
            # concerned. We used to hang here.
270
267
            # platforms, this doesn't occur, so just mentioning the problem is
271
268
            # enough for now -- vila 2010824
272
269
            sys.stderr.write('thread %s hung\n' % (self.name,))
273
 
            # raise AssertionError('thread %s hung' % (self.name,))
 
270
            #raise AssertionError('thread %s hung' % (self.name,))
274
271
 
275
272
 
276
273
class TestingTCPServerMixin(object):
317
314
        if self.verify_request(request, client_address):
318
315
            try:
319
316
                self.process_request(request, client_address)
320
 
            except BaseException:
 
317
            except:
321
318
                self.handle_error(request, client_address)
322
319
        else:
323
320
            self.close_request(request)
460
457
        t = TestThread(
461
458
            sync_event=stopped,
462
459
            name='%s -> %s' % (client_address, self.server_address),
463
 
            target=self.process_request_thread,
464
 
            args=(started, detached, stopped, request, client_address))
 
460
            target = self.process_request_thread,
 
461
            args = (started, detached, stopped, request, client_address))
465
462
        # Update the client description
466
463
        self.clients.pop()
467
464
        self.clients.append((request, client_address, t))
565
562
            last_conn = None
566
563
            try:
567
564
                last_conn = osutils.connect_socket((self.host, self.port))
568
 
            except socket.error:
 
565
            except socket.error as e:
569
566
                # But ignore connection errors as the point is to unblock the
570
567
                # server thread, it may happen that it's not blocked or even
571
568
                # not started.
629
626
 
630
627
_DEFAULT_TESTING_CLIENT_TIMEOUT = 60.0
631
628
 
632
 
 
633
629
class TestingSmartServer(TestingThreadingTCPServer, server.SmartTCPServer):
634
630
 
635
631
    def __init__(self, server_address, request_handler_class,
636
632
                 backing_transport, root_client_path):
637
633
        TestingThreadingTCPServer.__init__(self, server_address,
638
634
                                           request_handler_class)
639
 
        server.SmartTCPServer.__init__(
640
 
            self, backing_transport,
 
635
        server.SmartTCPServer.__init__(self, backing_transport,
641
636
            root_client_path, client_timeout=_DEFAULT_TESTING_CLIENT_TIMEOUT)
642
637
 
643
638
    def serve(self):
657
652
 
658
653
    This server is backed by the process's cwd.
659
654
    """
660
 
 
661
655
    def __init__(self, thread_name_suffix=''):
662
656
        self.client_path_extra = None
663
657
        self.thread_name_suffix = thread_name_suffix
664
658
        self.host = '127.0.0.1'
665
659
        self.port = 0
666
660
        super(SmartTCPServer_for_testing, self).__init__(
667
 
            (self.host, self.port),
668
 
            TestingSmartServer,
669
 
            TestingSmartConnectionHandler)
 
661
                (self.host, self.port),
 
662
                TestingSmartServer,
 
663
                TestingSmartConnectionHandler)
670
664
 
671
665
    def create_server(self):
672
666
        return self.server_class((self.host, self.port),
674
668
                                 self.backing_transport,
675
669
                                 self.root_client_path)
676
670
 
 
671
 
677
672
    def start_server(self, backing_transport_server=None,
678
673
                     client_path_extra='/extra/'):
679
674
        """Set up server for testing.
742
737
 
743
738
 
744
739
class ReadonlySmartTCPServer_for_testing_v2_only(
745
 
        SmartTCPServer_for_testing_v2_only):
 
740
    SmartTCPServer_for_testing_v2_only):
746
741
    """Get a readonly server for testing."""
747
742
 
748
743
    def get_backing_transport(self, backing_transport_server):