/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: 2020-03-22 01:35:14 UTC
  • mfrom: (7490.7.6 work)
  • mto: This revision was merged to the branch mainline in revision 7499.
  • Revision ID: jelmer@jelmer.uk-20200322013514-7vw1ntwho04rcuj3
merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

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