def test_cache_cleaning(self):
"""Make sure the automatic cache cleaning logic works as expected."""
with TemporaryDirectory() as cache_directory:
context = create_context()
accelerator = NpmAccel(context=context, cache_directory=cache_directory)
just_above_limit = accelerator.cache_limit + 1
for i in range(just_above_limit):
# Create a fake (empty) tar archive.
fingerprint = random_string(length=40, characters=string.hexdigits)
filename = os.path.join(cache_directory, '%s.tar' % fingerprint)
context.write_file(filename, '')
# Create the cache metadata.
accelerator.write_metadata(filename)
# Sanity check the cache entries.
assert len(list(accelerator.find_archives())) == just_above_limit
# Run the cleanup.
accelerator.clean_cache()
# Make sure the number of cache entries decreased.
assert len(list(accelerator.find_archives())) == accelerator.cache_limit
评论列表
文章目录