[Zope3-checkins] CVS: Zope3 - test.py:1.74

Tim Peters tim.one at comcast.net
Mon Sep 22 12:26:06 EDT 2003


Update of /cvs-repository/Zope3
In directory cvs.zope.org:/tmp/cvs-serv4598

Modified Files:
	test.py 
Log Message:
ImmediateTestResult. startTest() and stopTest():  Print a message whenever
a test creates a Thread object and leaves it running beyond the end of
the test.  Such tests should be changed not to leave Threads behind (the
Threads continue to consume resources for the remainder of the test suite
run, and can create problems during Python shutdown at the end of the run).

A "test.py !zeo" run left behind 4 Threads for me just now:

testDirectService (zope.app.mail.tests.test_directives.DirectivesTest)
New thread(s): [<QueueProcessorThread(Thread-427, started daemon)>]

testQueuedService (zope.app.mail.tests.test_directives.DirectivesTest)
New thread(s): [<QueueProcessorThread(Thread-428, started daemon)>]

testSMTPMailer (zope.app.mail.tests.test_directives.DirectivesTest)
New thread(s): [<QueueProcessorThread(Thread-429, started daemon)>]

testSendmailMailer (zope.app.mail.tests.test_directives.DirectivesTest)
New thread(s): [<QueueProcessorThread(Thread-430, started daemon)>]

All of those are daemon threads and stay alive "forever".


=== Zope3/test.py 1.73 => 1.74 ===
--- Zope3/test.py:1.73	Sun Sep 21 13:29:54 2003
+++ Zope3/test.py	Mon Sep 22 12:26:05 2003
@@ -160,6 +160,7 @@
 import re
 import pdb
 import sys
+import threading    # just to get at Thread objects created by tests
 import time
 import traceback
 import unittest
@@ -206,6 +207,14 @@
             # XXX Perhaps eat the garbage here, so that the garbage isn't
             #     printed for every subsequent test.
 
+        # Did the test leave any new threads behind?
+        new_threads = [t for t in threading.enumerate()
+                         if t not in self._threads]
+        if new_threads:
+            print "The following test left new threads behind:"
+            print test
+            print "New thread(s):", new_threads
+
     def print_times(self, stream, count=None):
         results = self._testtimes.items()
         results.sort(lambda x, y: cmp(y[1], x[1]))
@@ -247,6 +256,7 @@
                 self.stream.write(": %s" % name)
                 self._lastWidth = width
             self.stream.flush()
+        self._threads = threading.enumerate()
         self.__super_startTest(test)
         self._testtimes[test] = time.time()
 
@@ -459,7 +469,7 @@
             test_dir = d
         else:
             raise ValueError("%s does not exist!" % test_dir)
-    
+
 
 def find_tests(rx):
     global finder
@@ -777,7 +787,7 @@
 	print """\
 	ERROR: Your python version is not supported by Zope3.
 	Zope3 needs either Python2.3 or Python2.2.3 or greater.
-	In particular, Zope3 on Python2.2.2 is a recipe for 
+	In particular, Zope3 on Python2.2.2 is a recipe for
 	pain. You are running:""" + sys.version
 	sys.exit(1)
 




More information about the Zope3-Checkins mailing list