~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_server.py

  • Committer: Jelmer Vernooij
  • Date: 2011-10-05 12:45:41 UTC
  • mfrom: (6190 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6216.
  • Revision ID: jelmer@samba.org-20111005124541-chv6scmle72z72gq
Merge bzr.dev.

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
22
23
 
23
24
 
24
25
from bzrlib import (
25
26
    cethread,
 
27
    errors,
26
28
    osutils,
27
29
    transport,
28
30
    urlutils,
312
314
                self.process_request(request, client_address)
313
315
            except:
314
316
                self.handle_error(request, client_address)
315
 
                self.close_request(request)
 
317
        else:
 
318
            self.close_request(request)
316
319
 
317
320
    def get_request(self):
318
321
        return self.socket.accept()
332
335
        # The following can be used for debugging purposes, it will display the
333
336
        # exception and the traceback just when it occurs instead of waiting
334
337
        # for the thread to be joined.
335
 
 
336
338
        # 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)
337
348
        raise
338
349
 
339
350
    def ignored_exceptions_during_shutdown(self, e):
419
430
        SocketServer.ThreadingTCPServer.__init__(self, server_address,
420
431
                                                 request_handler_class)
421
432
 
422
 
    def get_request (self):
 
433
    def get_request(self):
423
434
        """Get the request and client address from the socket."""
424
435
        sock, addr = TestingTCPServerMixin.get_request(self)
425
436
        # The thread is not create yet, it will be updated in process_request
440
451
        t = TestThread(
441
452
            sync_event=stopped,
442
453
            name='%s -> %s' % (client_address, self.server_address),
443
 
            target = self.process_request_thread,
444
 
            args = (started, stopped, request, client_address))
 
454
            target=self.process_request_thread,
 
455
            args=(started, stopped, request, client_address))
445
456
        # Update the client description
446
457
        self.clients.pop()
447
458
        self.clients.append((request, client_address, t))
596
607
                                                 server)
597
608
 
598
609
    def handle(self):
599
 
        while not self.finished:
600
 
            server_protocol = self._build_protocol()
601
 
            self._serve_one_request(server_protocol)
 
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
602
617
 
603
618
 
604
619
_DEFAULT_TESTING_CLIENT_TIMEOUT = 4.0