diff --git a/tests/regressiontests/cache/tests.py b/tests/regressiontests/cache/tests.py
index c5349d5..aeef4b6 100644
a
|
b
|
class BaseCacheTests(object):
|
408 | 408 | self.assertEqual(self.cache.get('key3'), 'sausage') |
409 | 409 | self.assertEqual(self.cache.get('key4'), 'lobster bisque') |
410 | 410 | |
411 | | def perform_cull_test(self, initial_count, final_count): |
| 411 | def perform_cull_test(self, initial_count, final_count, cache=None): |
412 | 412 | """This is implemented as a utility method, because only some of the backends |
413 | 413 | implement culling. The culling algorithm also varies slightly, so the final |
414 | 414 | number of entries will vary between backends""" |
| 415 | if cache is None: |
| 416 | cache = self.cache |
| 417 | |
415 | 418 | # Create initial cache key entries. This will overflow the cache, causing a cull |
416 | 419 | for i in range(1, initial_count): |
417 | | self.cache.set('cull%d' % i, 'value', 1000) |
| 420 | cache.set('cull%d' % i, 'value', 1000) |
418 | 421 | count = 0 |
419 | 422 | # Count how many keys are left in the cache. |
420 | 423 | for i in range(1, initial_count): |
421 | | if self.cache.has_key('cull%d' % i): |
| 424 | if cache.has_key('cull%d' % i): |
422 | 425 | count = count + 1 |
423 | 426 | self.assertEqual(count, final_count) |
424 | 427 | |
… |
… |
class FileBasedCacheTests(unittest.TestCase, BaseCacheTests):
|
848 | 851 | def setUp(self): |
849 | 852 | self.dirname = tempfile.mkdtemp() |
850 | 853 | self.cache = get_cache(self.backend_name, LOCATION=self.dirname, OPTIONS={'MAX_ENTRIES': 30}) |
| 854 | self.full_cull_cache = get_cache(self.backend_name, |
| 855 | LOCATION=self.dirname, |
| 856 | OPTIONS={'MAX_ENTRIES': 30, 'CULL_FREQUENCY': 0}) |
851 | 857 | self.prefix_cache = get_cache(self.backend_name, LOCATION=self.dirname, KEY_PREFIX='cacheprefix') |
852 | 858 | self.v2_cache = get_cache(self.backend_name, LOCATION=self.dirname, VERSION=2) |
853 | 859 | self.custom_key_cache = get_cache(self.backend_name, LOCATION=self.dirname, KEY_FUNCTION=custom_key_func) |
… |
… |
class FileBasedCacheTests(unittest.TestCase, BaseCacheTests):
|
879 | 885 | self.assertTrue(not os.path.exists(os.path.dirname(keypath))) |
880 | 886 | self.assertTrue(not os.path.exists(os.path.dirname(os.path.dirname(keypath)))) |
881 | 887 | |
| 888 | def test_full_cull(self): |
| 889 | self.perform_cull_test(32, 1, self.full_cull_cache) |
| 890 | |
882 | 891 | def test_cull(self): |
883 | 892 | self.perform_cull_test(50, 29) |
884 | 893 | |