diff options
author | Patrick Cloke <clokep@users.noreply.github.com> | 2021-10-07 09:38:31 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-07 09:38:31 -0400 |
commit | 7301019d48f1a4ca7683b1745be55cecc6fe4be3 (patch) | |
tree | 1338a3ea315d036e40e424626ee7ba8da5d4dce2 /tests/config/test_cache.py | |
parent | Don't alter directory entries for local users when setting a per-room nicknam... (diff) | |
download | synapse-7301019d48f1a4ca7683b1745be55cecc6fe4be3.tar.xz |
Ensure each cache config test uses separate state. (#11019)
Hopefully this fixes these tests sometimes failing in CI.
Diffstat (limited to 'tests/config/test_cache.py')
-rw-r--r-- | tests/config/test_cache.py | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/tests/config/test_cache.py b/tests/config/test_cache.py index f518abdb7a..79d417568d 100644 --- a/tests/config/test_cache.py +++ b/tests/config/test_cache.py @@ -12,12 +12,16 @@ # See the License for the specific language governing permissions and # limitations under the License. +from unittest.mock import patch + from synapse.config.cache import CacheConfig, add_resizable_cache from synapse.util.caches.lrucache import LruCache from tests.unittest import TestCase +# Patch the global _CACHES so that each test runs against its own state. +@patch("synapse.config.cache._CACHES", new_callable=dict) class CacheConfigTests(TestCase): def setUp(self): # Reset caches before each test @@ -26,7 +30,7 @@ class CacheConfigTests(TestCase): def tearDown(self): self.config.reset() - def test_individual_caches_from_environ(self): + def test_individual_caches_from_environ(self, _caches): """ Individual cache factors will be loaded from the environment. """ @@ -39,7 +43,7 @@ class CacheConfigTests(TestCase): self.assertEqual(dict(self.config.cache_factors), {"something_or_other": 2.0}) - def test_config_overrides_environ(self): + def test_config_overrides_environ(self, _caches): """ Individual cache factors defined in the environment will take precedence over those in the config. @@ -56,7 +60,7 @@ class CacheConfigTests(TestCase): {"foo": 1.0, "bar": 3.0, "something_or_other": 2.0}, ) - def test_individual_instantiated_before_config_load(self): + def test_individual_instantiated_before_config_load(self, _caches): """ If a cache is instantiated before the config is read, it will be given the default cache size in the interim, and then resized once the config @@ -72,7 +76,7 @@ class CacheConfigTests(TestCase): self.assertEqual(cache.max_size, 300) - def test_individual_instantiated_after_config_load(self): + def test_individual_instantiated_after_config_load(self, _caches): """ If a cache is instantiated after the config is read, it will be immediately resized to the correct size given the per_cache_factor if @@ -85,7 +89,7 @@ class CacheConfigTests(TestCase): add_resizable_cache("foo", cache_resize_callback=cache.set_cache_factor) self.assertEqual(cache.max_size, 200) - def test_global_instantiated_before_config_load(self): + def test_global_instantiated_before_config_load(self, _caches): """ If a cache is instantiated before the config is read, it will be given the default cache size in the interim, and then resized to the new @@ -100,7 +104,7 @@ class CacheConfigTests(TestCase): self.assertEqual(cache.max_size, 400) - def test_global_instantiated_after_config_load(self): + def test_global_instantiated_after_config_load(self, _caches): """ If a cache is instantiated after the config is read, it will be immediately resized to the correct size given the global factor if there @@ -113,7 +117,7 @@ class CacheConfigTests(TestCase): add_resizable_cache("foo", cache_resize_callback=cache.set_cache_factor) self.assertEqual(cache.max_size, 150) - def test_cache_with_asterisk_in_name(self): + def test_cache_with_asterisk_in_name(self, _caches): """Some caches have asterisks in their name, test that they are set correctly.""" config = { @@ -139,7 +143,7 @@ class CacheConfigTests(TestCase): add_resizable_cache("*cache_c*", cache_resize_callback=cache_c.set_cache_factor) self.assertEqual(cache_c.max_size, 200) - def test_apply_cache_factor_from_config(self): + def test_apply_cache_factor_from_config(self, _caches): """Caches can disable applying cache factor updates, mainly used by event cache size. """ |