Rev 4733: Clearer thread leaks reports. in file:///home/vila/src/bzr/experimental/leaking-tests/

Vincent Ladeuil v.ladeuil+lp at free.fr
Fri Oct 9 10:59:39 BST 2009


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

------------------------------------------------------------
revno: 4733
revision-id: v.ladeuil+lp at free.fr-20091009095939-nr9pv6s5c1ccc009
parent: pqm at pqm.ubuntu.com-20091008031135-6d7vxh4s0umav1eo
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: leaking-tests
timestamp: Fri 2009-10-09 11:59:39 +0200
message:
  Clearer thread leaks reports.
  
  * bzrlib/tests/__init__.py:
  (ExtendedTestResult.stopTestRun): Report the number of threads
  finally left running.
  (TestCase._check_leaked_threads): Restrict the leaking test
  definition to the tests that unambiguously leak threads.
-------------- next part --------------
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2009-10-08 01:50:30 +0000
+++ b/bzrlib/tests/__init__.py	2009-10-09 09:59:39 +0000
@@ -222,6 +222,10 @@
                 '%s is leaking threads among %d leaking tests.\n' % (
                 TestCase._first_thread_leaker_id,
                 TestCase._leaking_threads_tests))
+            # We don't report the main thread as an active one.
+            self.stream.write(
+                '%d non-main threads were left active in the end.\n'
+                % (TestCase._active_threads - 1))
 
     def _extractBenchmarkTime(self, testCase):
         """Add a benchmark time for the current test case."""
@@ -846,7 +850,15 @@
         active = threading.activeCount()
         leaked_threads = active - TestCase._active_threads
         TestCase._active_threads = active
-        if leaked_threads:
+        # If some tests make the number of threads *decrease*, we'll consider
+        # that they are just observing old threads dieing, not agressively kill
+        # random threads. So we don't report these tests as leaking. The risk
+        # is that we have false positives that way (the test see 2 threads
+        # going away but leak one) but it seems less likely than the actual
+        # false positives (the test see threads going away and does not leak).
+        if leaked_threads > 0:
+            if 'threads' in selftest_debug_flags:
+                print '%s is leaking, active is now %d' % (self.id(), active)
             TestCase._leaking_threads_tests += 1
             if TestCase._first_thread_leaker_id is None:
                 TestCase._first_thread_leaker_id = self.id()



More information about the bazaar-commits mailing list