diff options
| author | Emre Yilmaz <emre.yilmaz@markafoni.com> | 2015-12-02 12:34:31 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-12-04 12:28:34 -0500 |
| commit | 9733ff5f991356ac98d499f24f2241141863a555 (patch) | |
| tree | 423497aeef1f25ad33d87d4713768eb343e9a3e9 /tests/cache | |
| parent | dcac10061245bbbe00d574194e9b4aebd67e0ac6 (diff) | |
[1.9.x] Fixed #25840 -- Fixed BaseCache.get_or_set() on the DummyCache backend.
This also fixes a possible data eviction race condition between
setting and getting a key. Another thread could remove the key
before get_and_set() accesses it again. In this case, now the
default value will be returned instead of None.
Backport of 8e838d9c869083597dc9e161ae2fe37acaa90de9 from master
Diffstat (limited to 'tests/cache')
| -rw-r--r-- | tests/cache/tests.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/tests/cache/tests.py b/tests/cache/tests.py index dca08ee081..7fd9808ca6 100644 --- a/tests/cache/tests.py +++ b/tests/cache/tests.py @@ -197,6 +197,15 @@ class DummyCacheTests(SimpleTestCase): self.assertRaises(ValueError, cache.decr_version, 'answer') self.assertRaises(ValueError, cache.decr_version, 'does_not_exist') + def test_get_or_set(self): + self.assertEqual(cache.get_or_set('mykey', 'default'), 'default') + + def test_get_or_set_callable(self): + def my_callable(): + return 'default' + + self.assertEqual(cache.get_or_set('mykey', my_callable), 'default') + def custom_key_func(key, key_prefix, version): "A customized cache key function" |
