comparison test/db_test_base.py @ 4448:2784c239e6c8

clear the cache on commit for rdbms backends: Don't carry over cached values from one transaction to the next (there may be other changes from other transactions) see new ConcurrentDBTest for a read-modify-update cycle that fails with the old caching behavior.
author Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
date Fri, 22 Oct 2010 14:14:26 +0000
parents 67bef70ab9b9
children 34dce76bb202
comparison
equal deleted inserted replaced
4447:9d37875416c3 4448:2784c239e6c8
2170 try: 2170 try:
2171 shutil.rmtree(self.dirname) 2171 shutil.rmtree(self.dirname)
2172 except OSError, error: 2172 except OSError, error:
2173 if error.errno not in (errno.ENOENT, errno.ESRCH): raise 2173 if error.errno not in (errno.ENOENT, errno.ESRCH): raise
2174 2174
2175 class ConcurrentDBTest(ClassicInitTest):
2176 def testConcurrency(self):
2177 # The idea here is a read-modify-update cycle in the presence of
2178 # a cache that has to be properly handled. The same applies if
2179 # we extend a String or otherwise modify something that depends
2180 # on the previous value.
2181
2182 # set up and open a tracker
2183 tracker = setupTracker(self.dirname, self.backend)
2184 # open the database
2185 self.db = tracker.open('admin')
2186
2187 prio = '1'
2188 self.assertEqual(self.db.priority.get(prio, 'order'), 1.0)
2189 def inc(db):
2190 db.priority.set(prio, order=db.priority.get(prio, 'order') + 1)
2191
2192 inc(self.db)
2193
2194 db2 = tracker.open("admin")
2195 self.assertEqual(db2.priority.get(prio, 'order'), 1.0)
2196 db2.commit()
2197 self.db.commit()
2198 self.assertEqual(self.db.priority.get(prio, 'order'), 2.0)
2199
2200 inc(db2)
2201 db2.commit()
2202 db2.clearCache()
2203 self.assertEqual(db2.priority.get(prio, 'order'), 3.0)
2204 db2.close()
2205
2206
2175 # vim: set et sts=4 sw=4 : 2207 # vim: set et sts=4 sw=4 :

Roundup Issue Tracker: http://roundup-tracker.org/