1414
1515from unittest .mock import patch
1616
17- from synapse .config .cache import CacheConfig , add_resizable_cache
17+ from synapse .config .cache import CacheConfig , CacheProperties , add_resizable_cache
1818from synapse .util .caches .lrucache import LruCache
1919
2020from tests .unittest import TestCase
2121
2222
23- # Patch the global _CACHES so that each test runs against its own state .
23+ # Patch the global state so that each test runs in an isolated environment .
2424@patch ("synapse.config.cache._CACHES" , new_callable = dict )
25+ @patch ("synapse.config.cache.properties" , new_callable = CacheProperties )
2526class CacheConfigTests (TestCase ):
2627 def setUp (self ):
2728 # Reset caches before each test
@@ -30,7 +31,7 @@ def setUp(self):
3031 def tearDown (self ):
3132 self .config .reset ()
3233
33- def test_individual_caches_from_environ (self , _caches ):
34+ def test_individual_caches_from_environ (self , _caches , _properties ):
3435 """
3536 Individual cache factors will be loaded from the environment.
3637 """
@@ -43,7 +44,7 @@ def test_individual_caches_from_environ(self, _caches):
4344
4445 self .assertEqual (dict (self .config .cache_factors ), {"something_or_other" : 2.0 })
4546
46- def test_config_overrides_environ (self , _caches ):
47+ def test_config_overrides_environ (self , _caches , _properties ):
4748 """
4849 Individual cache factors defined in the environment will take precedence
4950 over those in the config.
@@ -60,7 +61,7 @@ def test_config_overrides_environ(self, _caches):
6061 {"foo" : 1.0 , "bar" : 3.0 , "something_or_other" : 2.0 },
6162 )
6263
63- def test_individual_instantiated_before_config_load (self , _caches ):
64+ def test_individual_instantiated_before_config_load (self , _caches , _properties ):
6465 """
6566 If a cache is instantiated before the config is read, it will be given
6667 the default cache size in the interim, and then resized once the config
@@ -76,7 +77,7 @@ def test_individual_instantiated_before_config_load(self, _caches):
7677
7778 self .assertEqual (cache .max_size , 300 )
7879
79- def test_individual_instantiated_after_config_load (self , _caches ):
80+ def test_individual_instantiated_after_config_load (self , _caches , _properties ):
8081 """
8182 If a cache is instantiated after the config is read, it will be
8283 immediately resized to the correct size given the per_cache_factor if
@@ -89,7 +90,7 @@ def test_individual_instantiated_after_config_load(self, _caches):
8990 add_resizable_cache ("foo" , cache_resize_callback = cache .set_cache_factor )
9091 self .assertEqual (cache .max_size , 200 )
9192
92- def test_global_instantiated_before_config_load (self , _caches ):
93+ def test_global_instantiated_before_config_load (self , _caches , _properties ):
9394 """
9495 If a cache is instantiated before the config is read, it will be given
9596 the default cache size in the interim, and then resized to the new
@@ -104,7 +105,7 @@ def test_global_instantiated_before_config_load(self, _caches):
104105
105106 self .assertEqual (cache .max_size , 400 )
106107
107- def test_global_instantiated_after_config_load (self , _caches ):
108+ def test_global_instantiated_after_config_load (self , _caches , _properties ):
108109 """
109110 If a cache is instantiated after the config is read, it will be
110111 immediately resized to the correct size given the global factor if there
@@ -117,7 +118,7 @@ def test_global_instantiated_after_config_load(self, _caches):
117118 add_resizable_cache ("foo" , cache_resize_callback = cache .set_cache_factor )
118119 self .assertEqual (cache .max_size , 150 )
119120
120- def test_cache_with_asterisk_in_name (self , _caches ):
121+ def test_cache_with_asterisk_in_name (self , _caches , _properties ):
121122 """Some caches have asterisks in their name, test that they are set correctly."""
122123
123124 config = {
@@ -143,7 +144,7 @@ def test_cache_with_asterisk_in_name(self, _caches):
143144 add_resizable_cache ("*cache_c*" , cache_resize_callback = cache_c .set_cache_factor )
144145 self .assertEqual (cache_c .max_size , 200 )
145146
146- def test_apply_cache_factor_from_config (self , _caches ):
147+ def test_apply_cache_factor_from_config (self , _caches , _properties ):
147148 """Caches can disable applying cache factor updates, mainly used by
148149 event cache size.
149150 """
0 commit comments