/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/__init__.py

  • Committer: Vincent Ladeuil
  • Date: 2009-10-08 14:34:02 UTC
  • mto: (5247.1.1 first-try)
  • mto: This revision was merged to the branch mainline in revision 5396.
  • Revision ID: v.ladeuil+lp@free.fr-20091008143402-b4uivhhkykn95u8v
Collect and shutdown clients for SmartTCPServer_for_testing.

* bzrlib/tests/http_server.py:
(TestingHTTPServerMixin.serve): Try to avoid hanging in the server
thread, we already catch the socket.timeout exception, we may as
well use it.
(TestingThreadingHTTPServer.process_request_thread): Get rid of
the spurious pdb.set_trace().

* bzrlib/tests/__init__.py:
(ExtendedTestResult.stopTestRun): Display how many threads are
left at the end.
(TestCase._check_leaked_threads): 

* bzrlib/smart/server.py:
(SmartTCPServer.serve_conn): Return the created thread so daughter
classes can play with it.
(SmartTCPServer_for_testing.serve_conn): Collect the client
sockets/threads.
(SmartTCPServer_for_testing.shutdown_client): shutdown a client
socket.
(SmartTCPServer_for_testing.tearDown): shutdown client
sockets/threads.

Show diffs side-by-side

added added

removed removed

Lines of Context:
222
222
                '%s is leaking threads among %d leaking tests.\n' % (
223
223
                TestCase._first_thread_leaker_id,
224
224
                TestCase._leaking_threads_tests))
 
225
            # We don't report the main thread as an active one.
 
226
            self.stream.write('%d threads were left active in the end.\n'
 
227
                              % (TestCase._active_threads - 1))
225
228
 
226
229
    def _extractBenchmarkTime(self, testCase):
227
230
        """Add a benchmark time for the current test case."""
846
849
        active = threading.activeCount()
847
850
        leaked_threads = active - TestCase._active_threads
848
851
        TestCase._active_threads = active
849
 
        if leaked_threads:
 
852
        # If some tests make the number of threads *decrease*, we'll consider
 
853
        # that they are just observing old threads dieing, not agressively kill
 
854
        # random threads. So we don't report these tests as leaking. The risk
 
855
        # is that we have false positives that way (the test see 2 threads
 
856
        # going away but leak one) but it seems less likely than the actual
 
857
        # false positives (the test see threads going away and does not leak).
 
858
        if leaked_threads > 0:
 
859
            print '%s is leaking, active is now %d' % (self.id(), active)
850
860
            TestCase._leaking_threads_tests += 1
851
861
            if TestCase._first_thread_leaker_id is None:
852
862
                TestCase._first_thread_leaker_id = self.id()