[Zodb-checkins] CVS: Zope/lib/python/ZODB/tests - testCache.py:1.13.10.7

Tim Peters tim.one at comcast.net
Mon Jun 7 18:46:51 EDT 2004


Update of /cvs-repository/Zope/lib/python/ZODB/tests
In directory cvs.zope.org:/tmp/cvs-serv24523/lib/python/ZODB/tests

Modified Files:
      Tag: Zope-2_7-branch
	testCache.py 
Log Message:
checkMinimizeTerminates():  backport test fix from the trunk.
The nasty immortal objects created by this test can create mysterious
errors in subsequent tests, as Jim discovered when testing the Zope X3
beta.  This patch defangs the objects (renders them harmless and mortal
again) after the body of the test completes.


=== Zope/lib/python/ZODB/tests/testCache.py 1.13.10.6 => 1.13.10.7 ===
--- Zope/lib/python/ZODB/tests/testCache.py:1.13.10.6	Fri May 21 12:14:05 2004
+++ Zope/lib/python/ZODB/tests/testCache.py	Mon Jun  7 18:46:47 2004
@@ -71,6 +71,21 @@
             o.value += 1
         get_transaction().commit()
 
+
+# CantGetRidOfMe is used by checkMinimizeTerminates.
+make_trouble = True
+class CantGetRidOfMe(MinPO):
+    def __init__(self, value):
+        MinPO.__init__(self, value)
+        self.an_attribute = 42
+
+    def __del__(self):
+        # Referencing an attribute of self causes self to be
+        # loaded into the cache again, which also resurrects
+        # self.
+        if make_trouble:
+            self.an_attribute
+
 class DBMethods(CacheTestBase):
 
     __super_setUp = CacheTestBase.setUp
@@ -128,29 +143,28 @@
         # unghostifying itself again.
         class Worker(threading.Thread):
 
-            class CantGetRidOfMe(MinPO):
-                def __init__(self, value):
-                    MinPO.__init__(self, value)
-                    self.an_attribute = 42
-
-                def __del__(self):
-                    # Referencing an attribute of self causes self to be
-                    # loaded into the cache again, which also resurrects
-                    # self.
-                    self.an_attribute
-
             def __init__(self, testcase):
                 threading.Thread.__init__(self)
                 self.testcase = testcase
 
             def run(self):
+                global make_trouble
+                # Make CantGetRidOfMe.__del__ dangerous.
+                make_trouble = True
+
                 conn = self.testcase.conns[0]
                 r = conn.root()
                 d = r[1]
                 for i in range(len(d)):
-                    d[i] = self.CantGetRidOfMe(i)
+                    d[i] = CantGetRidOfMe(i)
                 get_transaction().commit()
 
+                self.testcase.db.cacheMinimize(0)
+
+                # Defang the nasty objects.  Else, because they're
+                # immortal now, they hang around and create trouble
+                # for subsequent tests.
+                make_trouble = False
                 self.testcase.db.cacheMinimize(0)
 
         w = Worker(self)




More information about the Zodb-checkins mailing list