summaryrefslogtreecommitdiff
path: root/tests/cache
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2014-02-08 05:49:27 -0500
committerTim Graham <timograham@gmail.com>2014-02-08 05:49:27 -0500
commit6c5a30b4e7f51e8c255dc104714d5748e5b5870c (patch)
tree3fe2494150532847a22b807cc00ab0a83cf34d67 /tests/cache
parent02add43568b694ef25afeae474b5b1da883826c6 (diff)
Added tests for LocalMemCache deadlocks. refs #20613 and refs #18541.
Thanks Zach Smith for the patch.
Diffstat (limited to 'tests/cache')
-rw-r--r--tests/cache/tests.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/cache/tests.py b/tests/cache/tests.py
index 8087f91713..f5d213e759 100644
--- a/tests/cache/tests.py
+++ b/tests/cache/tests.py
@@ -990,6 +990,18 @@ class CreateCacheTableForDBCacheTests(TestCase):
router.routers = old_routers
+class PicklingSideEffect(object):
+
+ def __init__(self, cache):
+ self.cache = cache
+ self.locked = False
+
+ def __getstate__(self):
+ if self.cache._lock.active_writers:
+ self.locked = True
+ return {}
+
+
@override_settings(CACHES=caches_setting_for_tests(
BACKEND='django.core.cache.backends.locmem.LocMemCache',
))
@@ -1025,6 +1037,15 @@ class LocMemCacheTests(BaseCacheTests, TestCase):
self.assertEqual(caches['default'].get('value'), 42)
self.assertEqual(caches['other'].get('value'), None)
+ def test_locking_on_pickle(self):
+ """#20613/#18541 -- Ensures pickling is done outside of the lock."""
+ bad_obj = PicklingSideEffect(cache)
+ cache.set('set', bad_obj)
+ self.assertFalse(bad_obj.locked, "Cache was locked during pickling")
+
+ cache.add('add', bad_obj)
+ self.assertFalse(bad_obj.locked, "Cache was locked during pickling")
+
def test_incr_decr_timeout(self):
"""incr/decr does not modify expiry time (matches memcached behavior)"""
key = 'value'