/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

Merge sftp-leaks into catch-them-all

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
from bzrlib.smart import server
35
35
 
36
36
 
 
37
def debug_threads():
 
38
    # FIXME: There is a dependency loop between bzrlib.tests and
 
39
    # bzrlib.tests.test_server that needs to be fixed. In the mean time
 
40
    # defining this function is enough for our needs. -- vila 20100611
 
41
    from bzrlib import tests
 
42
    return 'threads' in tests.selftest_debug_flags
 
43
 
 
44
 
37
45
class TestServer(transport.Server):
38
46
    """A Transport Server dedicated to tests.
39
47
 
485
493
        stopped = threading.Event()
486
494
        t = ThreadWithException(
487
495
            event=stopped,
 
496
            name='%s -> %s' % (client_address, self.server_address),
488
497
            target = self.process_request_thread,
489
498
            args = (started, stopped, request, client_address))
490
499
        # Update the client description
493
502
        # Propagate the exception handler since we must the same one for
494
503
        # connections running in their own threads than TestingTCPServer.
495
504
        t.set_ignored_exceptions(self.ignored_exceptions)
496
 
        t.name = '%s -> %s' % (client_address, self.server_address)
497
505
        t.start()
498
506
        started.wait()
 
507
        if debug_threads():
 
508
            print 'Client thread %s started' % (t.name,)
499
509
        # If an exception occured during the thread start, it will get raised.
500
510
        t.pending_exception()
501
511
 
509
519
            # after the connection is inited. This could happen during server
510
520
            # shutdown. If an exception occurred in the thread it will be
511
521
            # re-raised
 
522
            if debug_threads():
 
523
                print 'Client thread %s will be joined' % (
 
524
                    connection_thread.name,)
512
525
            connection_thread.join()
513
526
 
514
527
    def set_ignored_exceptions(self, thread, ignored_exceptions):
546
559
    def start_server(self):
547
560
        self.server = self.create_server()
548
561
        self._server_thread = ThreadWithException(
549
 
            event=self.server.started, target=self.run_server)
 
562
            event=self.server.started,
 
563
            name='(%s:%s)' % (self.host, self.port),
 
564
            target=self.run_server)
550
565
        self._server_thread.start()
551
566
        # Wait for the server thread to start (i.e release the lock)
552
567
        self.server.started.wait()
 
568
        if debug_threads():
 
569
            print 'Server thread %s started' % (self._server_thread.name,)
553
570
        # Get the real address, especially the port
554
571
        self.host, self.port = self.server.server_address
555
 
        self._server_thread.name = '(%s:%s)' % (self.host, self.port)
556
572
        # If an exception occured during the server start, it will get raised,
557
573
        # otherwise, the server is blocked on its accept() call.
558
574
        self._server_thread.pending_exception()
573
589
            self.set_ignored_exceptions(
574
590
                self.server.ignored_exceptions_during_shutdown)
575
591
            self.server.serving.clear()
 
592
            if debug_threads():
 
593
                print 'Server thread %s will be joined' % (
 
594
                    self._server_thread.name,)
576
595
            # The server is listening for a last connection, let's give it:
577
596
            last_conn = None
578
597
            try: