mirror of https://github.com/django/django.git
Fixed #27124 -- Excluded cull-related cache configs from memcached tests.
Since the `cull` and `zero_cull` test cache configs set `MAX_ENTRIES` and `CULL_FREQUENCY` in `OPTIONS`, which are only intended for use with the locmem, filesystem, and database backends. This prevents test failures once refs #20892 is fixed.
This commit is contained in:
parent
42dcceba61
commit
606a303856
|
@ -239,14 +239,17 @@ _caches_setting_base = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def caches_setting_for_tests(base=None, **params):
|
def caches_setting_for_tests(base=None, exclude=None, **params):
|
||||||
# `base` is used to pull in the memcached config from the original settings,
|
# `base` is used to pull in the memcached config from the original settings,
|
||||||
|
# `exclude` is a set of cache names denoting which `_caches_setting_base` keys
|
||||||
|
# should be omitted.
|
||||||
# `params` are test specific overrides and `_caches_settings_base` is the
|
# `params` are test specific overrides and `_caches_settings_base` is the
|
||||||
# base config for the tests.
|
# base config for the tests.
|
||||||
# This results in the following search order:
|
# This results in the following search order:
|
||||||
# params -> _caches_setting_base -> base
|
# params -> _caches_setting_base -> base
|
||||||
base = base or {}
|
base = base or {}
|
||||||
setting = {k: base.copy() for k in _caches_setting_base.keys()}
|
exclude = exclude or set()
|
||||||
|
setting = {k: base.copy() for k in _caches_setting_base.keys() if k not in exclude}
|
||||||
for key, cache_params in setting.items():
|
for key, cache_params in setting.items():
|
||||||
cache_params.update(_caches_setting_base[key])
|
cache_params.update(_caches_setting_base[key])
|
||||||
cache_params.update(params)
|
cache_params.update(params)
|
||||||
|
@ -1148,15 +1151,15 @@ for _cache_params in settings.CACHES.values():
|
||||||
if _cache_params['BACKEND'].startswith('django.core.cache.backends.memcached.'):
|
if _cache_params['BACKEND'].startswith('django.core.cache.backends.memcached.'):
|
||||||
memcached_params = _cache_params
|
memcached_params = _cache_params
|
||||||
|
|
||||||
memcached_never_expiring_params = memcached_params.copy()
|
# The memcached backends don't support cull-related options like `MAX_ENTRIES`.
|
||||||
memcached_never_expiring_params['TIMEOUT'] = None
|
memcached_excluded_caches = {'cull', 'zero_cull'}
|
||||||
|
|
||||||
memcached_far_future_params = memcached_params.copy()
|
|
||||||
memcached_far_future_params['TIMEOUT'] = 31536000 # 60*60*24*365, 1 year
|
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(memcached_params, "memcached not available")
|
@unittest.skipUnless(memcached_params, "memcached not available")
|
||||||
@override_settings(CACHES=caches_setting_for_tests(base=memcached_params))
|
@override_settings(CACHES=caches_setting_for_tests(
|
||||||
|
base=memcached_params,
|
||||||
|
exclude=memcached_excluded_caches,
|
||||||
|
))
|
||||||
class MemcachedCacheTests(BaseCacheTests, TestCase):
|
class MemcachedCacheTests(BaseCacheTests, TestCase):
|
||||||
|
|
||||||
def test_invalid_keys(self):
|
def test_invalid_keys(self):
|
||||||
|
@ -1186,13 +1189,21 @@ class MemcachedCacheTests(BaseCacheTests, TestCase):
|
||||||
self.assertEqual(caches[cache_key]._cache.pickleProtocol,
|
self.assertEqual(caches[cache_key]._cache.pickleProtocol,
|
||||||
pickle.HIGHEST_PROTOCOL)
|
pickle.HIGHEST_PROTOCOL)
|
||||||
|
|
||||||
@override_settings(CACHES=caches_setting_for_tests(base=memcached_never_expiring_params))
|
@override_settings(CACHES=caches_setting_for_tests(
|
||||||
|
base=memcached_params,
|
||||||
|
exclude=memcached_excluded_caches,
|
||||||
|
TIMEOUT=None,
|
||||||
|
))
|
||||||
def test_default_never_expiring_timeout(self):
|
def test_default_never_expiring_timeout(self):
|
||||||
# Regression test for #22845
|
# Regression test for #22845
|
||||||
cache.set('infinite_foo', 'bar')
|
cache.set('infinite_foo', 'bar')
|
||||||
self.assertEqual(cache.get('infinite_foo'), 'bar')
|
self.assertEqual(cache.get('infinite_foo'), 'bar')
|
||||||
|
|
||||||
@override_settings(CACHES=caches_setting_for_tests(base=memcached_far_future_params))
|
@override_settings(CACHES=caches_setting_for_tests(
|
||||||
|
base=memcached_params,
|
||||||
|
exclude=memcached_excluded_caches,
|
||||||
|
TIMEOUT=31536000, # 60*60*24*365, 1 year
|
||||||
|
))
|
||||||
def test_default_far_future_timeout(self):
|
def test_default_far_future_timeout(self):
|
||||||
# Regression test for #22845
|
# Regression test for #22845
|
||||||
cache.set('future_foo', 'bar')
|
cache.set('future_foo', 'bar')
|
||||||
|
|
Loading…
Reference in New Issue