Commit e3ae0a6d authored by Jeremy Hylton's avatar Jeremy Hylton

Add test for abort().

Remove unittest boilerplate.
parent cb77ccea
...@@ -11,32 +11,9 @@ ...@@ -11,32 +11,9 @@
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
"""Test behavior of Connection plus cPickleCache. """Test behavior of Connection plus cPickleCache."""
Methods involved:
get()
add()
cacheFullSweep()
cacheMinimize()
invalidate()
Other:
resetCache()
cache internal issues:
cache gets full
when incrgc is called
gc
Need to cover various transaction boundaries:
commit
abort
sub-transaction commit / abort
-- can provide our own txn implementation
"""
import doctest import doctest
import unittest
from persistent import Persistent from persistent import Persistent
from ZODB.config import databaseFromString from ZODB.config import databaseFromString
...@@ -62,11 +39,18 @@ class RegularObject(Persistent): ...@@ -62,11 +39,18 @@ class RegularObject(Persistent):
self.__class__.invalidations += 1 self.__class__.invalidations += 1
super(RegularObject, self)._p_invalidate() super(RegularObject, self)._p_invalidate()
class CacheTests(unittest.TestCase): def init(cls):
cls.deactivations = 0
cls.invalidations = 0
init = classmethod(init)
class CacheTests:
def test_cache(self): def test_cache(self):
r"""Test basic cache methods. r"""Test basic cache methods.
>>> RegularObject.init()
>>> db = databaseFromString("<zodb>\n" >>> db = databaseFromString("<zodb>\n"
... "cache-size 4\n" ... "cache-size 4\n"
... "<mappingstorage/>\n" ... "<mappingstorage/>\n"
...@@ -169,5 +153,42 @@ class CacheTests(unittest.TestCase): ...@@ -169,5 +153,42 @@ class CacheTests(unittest.TestCase):
[0, 0, 0, 0, 0] [0, 0, 0, 0, 0]
""" """
def test_cache_on_abort(self):
r"""Test that the cache handles transaction abort correctly.
>>> RegularObject.init()
>>> db = databaseFromString("<zodb>\n"
... "cache-size 4\n"
... "<mappingstorage/>\n"
... "</zodb>")
>>> cn = db.open()
>>> r = cn.root()
>>> L = []
>>> for i in range(5):
... o = RegularObject()
... L.append(o)
... r[i] = o
>>> get_transaction().commit()
>>> RegularObject.deactivations
1
Modify three of the objects and verify that they are
deactivated when the transaction aborts.
>>> for i in range(0, 5, 2):
... L[i].attr = i
>>> [L[i]._p_state for i in range(0, 5, 2)]
[1, 1, 1]
>>> cn._cache.ringlen()
5
>>> get_transaction().abort()
>>> cn._cache.ringlen()
2
>>> RegularObject.deactivations
4
"""
def test_suite(): def test_suite():
return doctest.DocTestSuite() return doctest.DocTestSuite()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment