[Zope3-checkins] CVS: Zope3/src/zope/app/container/tests - test_contained.py:1.2.10.2

Jim Fulton jim at zope.com
Fri Jan 30 11:16:58 EST 2004


Update of /cvs-repository/Zope3/src/zope/app/container/tests
In directory cvs.zope.org:/tmp/cvs-serv10120/src/zope/app/container/tests

Modified Files:
      Tag: zope3-zodb3-devel-branch
	test_contained.py 
Log Message:
Fixed a bug in tp_dealloc.  The slot needs to call the base-class,
Persistent, tp_dealloc, so that the object gets removed from the
zodb object cache.


=== Zope3/src/zope/app/container/tests/test_contained.py 1.2.10.1 => 1.2.10.2 ===
--- Zope3/src/zope/app/container/tests/test_contained.py:1.2.10.1	Fri Jan  9 17:23:49 2004
+++ Zope3/src/zope/app/container/tests/test_contained.py	Fri Jan 30 11:16:57 2004
@@ -12,6 +12,7 @@
 #
 ##############################################################################
 import unittest
+import gc
 from zope.testing.doctestunit import DocTestSuite
 from zope.app.tests.placelesssetup import setUp, tearDown
 from zope.app.container.contained import ContainedProxy
@@ -23,7 +24,7 @@
 class MyOb(Persistent):
     pass
 
-def test_basic_attribute_management_and_picklability():
+def test_basic_proxy_attribute_management_and_picklability():
     """Contained-object proxy
 
     This is a picklable proxy that can be put around objects that
@@ -165,6 +166,69 @@
         
     >>> db.close()
     """
+
+def test_proxy_cache_interaction():
+    """Test to make sure the proxy properly interacts with the object cache
+
+    Persistent objects are their own weak refs.  Thier deallocators
+    need to notify their connection's cache that their object is being
+    deallocated, so that it is removed from the cache.
+
+    >>> from ZODB.tests.util import DB
+    >>> db = DB()
+    >>> db.setCacheSize(5)
+    >>> conn = db.open()
+    >>> conn.root()['p'] = ContainedProxy(None)
+
+    We need to create some filler objects to push our proxy out of the cache:
+
+    >>> for i in range(10):
+    ...     conn.root()[i] = MyOb()
+
+    >>> get_transaction().commit()
+
+    Let's get the oid of our proxy:
+
+    >>> oid = conn.root()['p']._p_oid
+
+    Now, we'll access the filler object's:
+
+    >>> x = [getattr(conn.root()[i], 'x', 0) for i in range(10)]
+
+    We've also accessed the root object. If we garbage-collect the
+    cache:
+
+    >>> conn._cache.incrgc()
+
+    Then the root object will still be active, because it was accessed
+    recently:
+
+    >>> conn.root()._p_changed
+    0
+
+    And the proxy will be in the cache, because it's refernced from
+    the root object:
+
+    >>> conn._cache.get(oid, None) is not None
+    True
+
+    But it's a ghost:
+
+    >>> conn.root()['p']._p_changed
+
+    If we deactivate the root object:
+
+    >>> conn.root()._p_deactivate()
+
+    Then we'll release the last reference to the proxy and it should
+    no longer be in the cache. To be sure, we'll call gc:
+
+    >>> x = gc.collect()
+    >>> conn._cache.get(oid, None) is not None
+    False
+    
+    """
+
 
 def test_suite():
     return unittest.TestSuite((




More information about the Zope3-Checkins mailing list