diff options
| author | Jaap Roes <jaap@eight.nl> | 2013-08-26 16:34:02 +0200 |
|---|---|---|
| committer | Anssi Kääriäinen <akaariai@gmail.com> | 2013-11-07 16:12:15 +0200 |
| commit | 7be638390e18fcbfaaed638f9908673360c280d3 (patch) | |
| tree | 5a75b950a0aa5b8f86c30ed80506d5e3e7cfc052 /tests | |
| parent | ac2d86f8d31b8acca4b1ee362b1bff154bd37eab (diff) | |
Fixed #20536 -- rewrite of the file based cache backend
* Safer for use in multiprocess environments
* Better random culling
* Cache files use less disk space
* Safer delete behavior
Also fixed #15806, fixed #15825.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/cache/tests.py | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/tests/cache/tests.py b/tests/cache/tests.py index 053ee14a58..e4ef951295 100644 --- a/tests/cache/tests.py +++ b/tests/cache/tests.py @@ -1076,32 +1076,34 @@ class FileBasedCacheTests(unittest.TestCase, BaseCacheTests): def tearDown(self): self.cache.clear() + os.rmdir(self.dirname) - def test_hashing(self): - """Test that keys are hashed into subdirectories correctly""" - self.cache.set("foo", "bar") - key = self.cache.make_key("foo") - keyhash = hashlib.md5(key.encode()).hexdigest() - keypath = os.path.join(self.dirname, keyhash[:2], keyhash[2:4], keyhash[4:]) - self.assertTrue(os.path.exists(keypath)) + def test_cull(self): + self.perform_cull_test(50, 29) - def test_subdirectory_removal(self): - """ - Make sure that the created subdirectories are correctly removed when empty. - """ - self.cache.set("foo", "bar") - key = self.cache.make_key("foo") - keyhash = hashlib.md5(key.encode()).hexdigest() - keypath = os.path.join(self.dirname, keyhash[:2], keyhash[2:4], keyhash[4:]) - self.assertTrue(os.path.exists(keypath)) + def test_ignores_non_cache_files(self): + fname = os.path.join(self.dirname, 'not-a-cache-file') + with open(fname, 'w'): + os.utime(fname, None) + self.cache.clear() + self.assertTrue(os.path.exists(fname), + 'Expected cache.clear to ignore non cache files') + os.remove(fname) - self.cache.delete("foo") - self.assertTrue(not os.path.exists(keypath)) - self.assertTrue(not os.path.exists(os.path.dirname(keypath))) - self.assertTrue(not os.path.exists(os.path.dirname(os.path.dirname(keypath)))) + def test_clear_does_not_remove_cache_dir(self): + self.cache.clear() + self.assertTrue(os.path.exists(self.dirname), + 'Expected cache.clear to keep the cache dir') - def test_cull(self): - self.perform_cull_test(50, 29) + def test_creates_cache_dir_if_nonexistent(self): + os.rmdir(self.dirname) + self.cache.set('foo', 'bar') + os.path.exists(self.dirname) + + def test_zero_cull(self): + # Regression test for #15806 + self.cache = get_cache(self.backend_name, LOCATION=self.dirname, OPTIONS={'MAX_ENTRIES': 30, 'CULL_FREQUENCY': 0}) + self.perform_cull_test(50, 19) class CustomCacheKeyValidationTests(unittest.TestCase): |
