Rev 5266: Merge http-leaks into sftp-leaks in file:///home/vila/src/bzr/experimental/leaking-tests/

Vincent Ladeuil v.ladeuil+lp at free.fr
Fri Jun 11 17:58:27 BST 2010


At file:///home/vila/src/bzr/experimental/leaking-tests/

------------------------------------------------------------
revno: 5266 [merge]
revision-id: v.ladeuil+lp at free.fr-20100611165827-5mklzdvc21llvut7
parent: v.ladeuil+lp at free.fr-20100611163153-1n9icwp4ongkmexh
parent: v.ladeuil+lp at free.fr-20100611165821-n9qocd25c84rrd1t
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: sftp-leaks
timestamp: Fri 2010-06-11 18:58:27 +0200
message:
  Merge http-leaks into sftp-leaks
modified:
  bzrlib/tests/test_server.py    test_server.py-20100209163834-im1ozfuenfmqaa2m-1
-------------- next part --------------
=== modified file 'bzrlib/tests/test_server.py'
--- a/bzrlib/tests/test_server.py	2010-06-11 11:01:30 +0000
+++ b/bzrlib/tests/test_server.py	2010-06-11 16:58:21 +0000
@@ -34,6 +34,14 @@
 from bzrlib.smart import server
 
 
+def debug_threads():
+    # FIXME: There is a dependency loop between bzrlib.tests and
+    # bzrlib.tests.test_server that needs to be fixed. In the mean time
+    # defining this function is enough for our needs. -- vila 20100611
+    from bzrlib import tests
+    return 'threads' in tests.selftest_debug_flags
+
+
 class TestServer(transport.Server):
     """A Transport Server dedicated to tests.
 
@@ -485,6 +493,7 @@
         stopped = threading.Event()
         t = ThreadWithException(
             event=stopped,
+            name='%s -> %s' % (client_address, self.server_address),
             target = self.process_request_thread,
             args = (started, stopped, request, client_address))
         # Update the client description
@@ -493,9 +502,10 @@
         # Propagate the exception handler since we must the same one for
         # connections running in their own threads than TestingTCPServer.
         t.set_ignored_exceptions(self.ignored_exceptions)
-        t.name = '%s -> %s' % (client_address, self.server_address)
         t.start()
         started.wait()
+        if debug_threads():
+            print 'Client thread %s started' % (t.name,)
         # If an exception occured during the thread start, it will get raised.
         t.pending_exception()
 
@@ -509,6 +519,9 @@
             # after the connection is inited. This could happen during server
             # shutdown. If an exception occurred in the thread it will be
             # re-raised
+            if debug_threads():
+                print 'Client thread %s will be joined' % (
+                    connection_thread.name,)
             connection_thread.join()
 
     def set_ignored_exceptions(self, thread, ignored_exceptions):
@@ -546,13 +559,16 @@
     def start_server(self):
         self.server = self.create_server()
         self._server_thread = ThreadWithException(
-            event=self.server.started, target=self.run_server)
+            event=self.server.started,
+            name='(%s:%s)' % (self.host, self.port),
+            target=self.run_server)
         self._server_thread.start()
         # Wait for the server thread to start (i.e release the lock)
         self.server.started.wait()
+        if debug_threads():
+            print 'Server thread %s started' % (self._server_thread.name,)
         # Get the real address, especially the port
         self.host, self.port = self.server.server_address
-        self._server_thread.name = '(%s:%s)' % (self.host, self.port)
         # If an exception occured during the server start, it will get raised,
         # otherwise, the server is blocked on its accept() call.
         self._server_thread.pending_exception()
@@ -573,6 +589,9 @@
             self.set_ignored_exceptions(
                 self.server.ignored_exceptions_during_shutdown)
             self.server.serving.clear()
+            if debug_threads():
+                print 'Server thread %s will be joined' % (
+                    self._server_thread.name,)
             # The server is listening for a last connection, let's give it:
             last_conn = None
             try:



More information about the bazaar-commits mailing list