/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: 2017-06-08 23:30:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6690.
  • Revision ID: jelmer@jelmer.uk-20170608233031-3qavls2o7a1pqllj
Update imports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
import errno
18
18
import socket
19
 
import socketserver
 
19
try:
 
20
    import socketserver
 
21
except ImportError:
 
22
    import SocketServer as socketserver
20
23
import sys
21
24
import threading
 
25
import traceback
22
26
 
23
27
 
24
28
from breezy import (
32
36
    chroot,
33
37
    pathfilter,
34
38
    )
35
 
from breezy.bzr.smart import (
 
39
from breezy.smart import (
36
40
    medium,
37
41
    server,
38
42
    )
253
257
        serving a client connection is hung.
254
258
        """
255
259
        super(TestThread, self).join(timeout)
256
 
        if timeout and self.is_alive():
 
260
        if timeout and self.isAlive():
257
261
            # The timeout expired without joining the thread, the thread is
258
262
            # therefore stucked and that's a failure as far as the test is
259
263
            # concerned. We used to hang here.
263
267
            # platforms, this doesn't occur, so just mentioning the problem is
264
268
            # enough for now -- vila 2010824
265
269
            sys.stderr.write('thread %s hung\n' % (self.name,))
266
 
            # raise AssertionError('thread %s hung' % (self.name,))
 
270
            #raise AssertionError('thread %s hung' % (self.name,))
267
271
 
268
272
 
269
273
class TestingTCPServerMixin(object):
310
314
        if self.verify_request(request, client_address):
311
315
            try:
312
316
                self.process_request(request, client_address)
313
 
            except BaseException:
 
317
            except:
314
318
                self.handle_error(request, client_address)
315
319
        else:
316
320
            self.close_request(request)
360
364
                               errno.ENOTCONN,
361
365
                               errno.EPIPE,
362
366
                               ]
363
 
        if isinstance(e, socket.error) and e.errno in accepted_errnos:
 
367
        if isinstance(e, socket.error) and e[0] in accepted_errnos:
364
368
            return True
365
369
        return False
366
370
 
453
457
        t = TestThread(
454
458
            sync_event=stopped,
455
459
            name='%s -> %s' % (client_address, self.server_address),
456
 
            target=self.process_request_thread,
457
 
            args=(started, detached, stopped, request, client_address))
 
460
            target = self.process_request_thread,
 
461
            args = (started, detached, stopped, request, client_address))
458
462
        # Update the client description
459
463
        self.clients.pop()
460
464
        self.clients.append((request, client_address, t))
558
562
            last_conn = None
559
563
            try:
560
564
                last_conn = osutils.connect_socket((self.host, self.port))
561
 
            except socket.error:
 
565
            except socket.error as e:
562
566
                # But ignore connection errors as the point is to unblock the
563
567
                # server thread, it may happen that it's not blocked or even
564
568
                # not started.
622
626
 
623
627
_DEFAULT_TESTING_CLIENT_TIMEOUT = 60.0
624
628
 
625
 
 
626
629
class TestingSmartServer(TestingThreadingTCPServer, server.SmartTCPServer):
627
630
 
628
631
    def __init__(self, server_address, request_handler_class,
629
632
                 backing_transport, root_client_path):
630
633
        TestingThreadingTCPServer.__init__(self, server_address,
631
634
                                           request_handler_class)
632
 
        server.SmartTCPServer.__init__(
633
 
            self, backing_transport,
 
635
        server.SmartTCPServer.__init__(self, backing_transport,
634
636
            root_client_path, client_timeout=_DEFAULT_TESTING_CLIENT_TIMEOUT)
635
637
 
636
638
    def serve(self):
650
652
 
651
653
    This server is backed by the process's cwd.
652
654
    """
653
 
 
654
655
    def __init__(self, thread_name_suffix=''):
655
656
        self.client_path_extra = None
656
657
        self.thread_name_suffix = thread_name_suffix
657
658
        self.host = '127.0.0.1'
658
659
        self.port = 0
659
660
        super(SmartTCPServer_for_testing, self).__init__(
660
 
            (self.host, self.port),
661
 
            TestingSmartServer,
662
 
            TestingSmartConnectionHandler)
 
661
                (self.host, self.port),
 
662
                TestingSmartServer,
 
663
                TestingSmartConnectionHandler)
663
664
 
664
665
    def create_server(self):
665
666
        return self.server_class((self.host, self.port),
667
668
                                 self.backing_transport,
668
669
                                 self.root_client_path)
669
670
 
 
671
 
670
672
    def start_server(self, backing_transport_server=None,
671
673
                     client_path_extra='/extra/'):
672
674
        """Set up server for testing.
735
737
 
736
738
 
737
739
class ReadonlySmartTCPServer_for_testing_v2_only(
738
 
        SmartTCPServer_for_testing_v2_only):
 
740
    SmartTCPServer_for_testing_v2_only):
739
741
    """Get a readonly server for testing."""
740
742
 
741
743
    def get_backing_transport(self, backing_transport_server):