~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_server.py

  • Committer: Patch Queue Manager
  • Date: 2011-09-08 11:01:15 UTC
  • mfrom: (6123.1.16 gpg-typo)
  • Revision ID: pqm@cupuasso-20110908110115-gbb9benwkdksvzk5
(jelmer) Fix a typo (invalid format identifier) in an error message in
 bzrlib.gpg. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import SocketServer
20
20
import sys
21
21
import threading
22
 
import traceback
23
22
 
24
23
 
25
24
from bzrlib import (
26
25
    cethread,
27
 
    errors,
28
26
    osutils,
29
27
    transport,
30
28
    urlutils,
267
265
            #raise AssertionError('thread %s hung' % (self.name,))
268
266
 
269
267
 
270
 
class TestingTCPServerMixin(object):
 
268
class TestingTCPServerMixin:
271
269
    """Mixin to support running SocketServer.TCPServer in a thread.
272
270
 
273
271
    Tests are connecting from the main thread, the server has to be run in a
314
312
                self.process_request(request, client_address)
315
313
            except:
316
314
                self.handle_error(request, client_address)
317
 
        else:
318
 
            self.close_request(request)
 
315
                self.close_request(request)
319
316
 
320
317
    def get_request(self):
321
318
        return self.socket.accept()
335
332
        # The following can be used for debugging purposes, it will display the
336
333
        # exception and the traceback just when it occurs instead of waiting
337
334
        # for the thread to be joined.
 
335
 
338
336
        # SocketServer.BaseServer.handle_error(self, request, client_address)
339
 
 
340
 
        # We call close_request manually, because we are going to raise an
341
 
        # exception. The SocketServer implementation calls:
342
 
        #   handle_error(...)
343
 
        #   close_request(...)
344
 
        # But because we raise the exception, close_request will never be
345
 
        # triggered. This helps client not block waiting for a response when
346
 
        # the server gets an exception.
347
 
        self.close_request(request)
348
337
        raise
349
338
 
350
339
    def ignored_exceptions_during_shutdown(self, e):
430
419
        SocketServer.ThreadingTCPServer.__init__(self, server_address,
431
420
                                                 request_handler_class)
432
421
 
433
 
    def get_request(self):
 
422
    def get_request (self):
434
423
        """Get the request and client address from the socket."""
435
424
        sock, addr = TestingTCPServerMixin.get_request(self)
436
425
        # The thread is not create yet, it will be updated in process_request
451
440
        t = TestThread(
452
441
            sync_event=stopped,
453
442
            name='%s -> %s' % (client_address, self.server_address),
454
 
            target=self.process_request_thread,
455
 
            args=(started, stopped, request, client_address))
 
443
            target = self.process_request_thread,
 
444
            args = (started, stopped, request, client_address))
456
445
        # Update the client description
457
446
        self.clients.pop()
458
447
        self.clients.append((request, client_address, t))
600
589
    def __init__(self, request, client_address, server):
601
590
        medium.SmartServerSocketStreamMedium.__init__(
602
591
            self, request, server.backing_transport,
603
 
            server.root_client_path,
604
 
            timeout=_DEFAULT_TESTING_CLIENT_TIMEOUT)
 
592
            server.root_client_path)
605
593
        request.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
606
594
        SocketServer.BaseRequestHandler.__init__(self, request, client_address,
607
595
                                                 server)
608
596
 
609
597
    def handle(self):
610
 
        try:
611
 
            while not self.finished:
612
 
                server_protocol = self._build_protocol()
613
 
                self._serve_one_request(server_protocol)
614
 
        except errors.ConnectionTimeout:
615
 
            # idle connections aren't considered a failure of the server
616
 
            return
617
 
 
618
 
 
619
 
_DEFAULT_TESTING_CLIENT_TIMEOUT = 4.0
 
598
        while not self.finished:
 
599
            server_protocol = self._build_protocol()
 
600
            self._serve_one_request(server_protocol)
 
601
 
620
602
 
621
603
class TestingSmartServer(TestingThreadingTCPServer, server.SmartTCPServer):
622
604
 
625
607
        TestingThreadingTCPServer.__init__(self, server_address,
626
608
                                           request_handler_class)
627
609
        server.SmartTCPServer.__init__(self, backing_transport,
628
 
            root_client_path, client_timeout=_DEFAULT_TESTING_CLIENT_TIMEOUT)
629
 
 
 
610
                                       root_client_path)
630
611
    def serve(self):
631
612
        self.run_server_started_hooks()
632
613
        try: