/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 bzrlib/tests/test_server.py

  • Committer: Patch Queue Manager
  • Date: 2011-12-02 12:02:54 UTC
  • mfrom: (6015.42.8 test-server-races)
  • Revision ID: pqm@pqm.ubuntu.com-20111202120254-kccrfj6buuqt1iui
(vila) Properly synchronize connection thread start with test server main
 thread. (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
432
432
    def get_request(self):
433
433
        """Get the request and client address from the socket."""
434
434
        sock, addr = TestingTCPServerMixin.get_request(self)
435
 
        # The thread is not create yet, it will be updated in process_request
 
435
        # The thread is not created yet, it will be updated in process_request
436
436
        self.clients.append((sock, addr, None))
437
437
        return sock, addr
438
438
 
439
 
    def process_request_thread(self, started, stopped, request, client_address):
 
439
    def process_request_thread(self, started, detached, stopped,
 
440
                               request, client_address):
440
441
        started.set()
 
442
        # We will be on our own once the server tells us we're detached
 
443
        detached.wait()
441
444
        SocketServer.ThreadingTCPServer.process_request_thread(
442
445
            self, request, client_address)
443
446
        self.close_request(request)
446
449
    def process_request(self, request, client_address):
447
450
        """Start a new thread to process the request."""
448
451
        started = threading.Event()
 
452
        detached = threading.Event()
449
453
        stopped = threading.Event()
450
454
        t = TestThread(
451
455
            sync_event=stopped,
452
456
            name='%s -> %s' % (client_address, self.server_address),
453
 
            target=self.process_request_thread,
454
 
            args=(started, stopped, request, client_address))
 
457
            target = self.process_request_thread,
 
458
            args = (started, detached, stopped, request, client_address))
455
459
        # Update the client description
456
460
        self.clients.pop()
457
461
        self.clients.append((request, client_address, t))
460
464
        t.set_ignored_exceptions(self.ignored_exceptions)
461
465
        t.start()
462
466
        started.wait()
463
 
        if debug_threads():
464
 
            sys.stderr.write('Client thread %s started\n' % (t.name,))
465
467
        # If an exception occured during the thread start, it will get raised.
466
 
        # In rare cases, an exception raised during the request processing may
467
 
        # also get caught here (see http://pad.lv/869366)
468
468
        t.pending_exception()
 
469
        if debug_threads():
 
470
            sys.stderr.write('Client thread %s started\n' % (t.name,))
 
471
        # Tell the thread, it's now on its own for exception handling.
 
472
        detached.set()
469
473
 
470
474
    # The following methods are called by the main thread
471
475