1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15- from unittest .mock import patch
16-
1715from synapse .config .cache import CacheConfig , add_resizable_cache
1816from synapse .util .caches .lrucache import LruCache
1917
2018from tests .unittest import TestCase
2119
2220
23- # Patch the global _CACHES so that each test runs against its own state.
24- @patch ("synapse.config.cache._CACHES" , new_callable = dict )
2521class CacheConfigTests (TestCase ):
2622 def setUp (self ):
27- # Reset caches before each test
23+ # Reset caches before each test since there's global state involved.
2824 self .config = CacheConfig ()
25+ self .config .reset ()
2926
3027 def tearDown (self ):
28+ # Also reset the caches after each test to leave state pristine.
3129 self .config .reset ()
3230
33- def test_individual_caches_from_environ (self , _caches ):
31+ def test_individual_caches_from_environ (self ):
3432 """
3533 Individual cache factors will be loaded from the environment.
3634 """
@@ -43,7 +41,7 @@ def test_individual_caches_from_environ(self, _caches):
4341
4442 self .assertEqual (dict (self .config .cache_factors ), {"something_or_other" : 2.0 })
4543
46- def test_config_overrides_environ (self , _caches ):
44+ def test_config_overrides_environ (self ):
4745 """
4846 Individual cache factors defined in the environment will take precedence
4947 over those in the config.
@@ -60,7 +58,7 @@ def test_config_overrides_environ(self, _caches):
6058 {"foo" : 1.0 , "bar" : 3.0 , "something_or_other" : 2.0 },
6159 )
6260
63- def test_individual_instantiated_before_config_load (self , _caches ):
61+ def test_individual_instantiated_before_config_load (self ):
6462 """
6563 If a cache is instantiated before the config is read, it will be given
6664 the default cache size in the interim, and then resized once the config
@@ -76,7 +74,7 @@ def test_individual_instantiated_before_config_load(self, _caches):
7674
7775 self .assertEqual (cache .max_size , 300 )
7876
79- def test_individual_instantiated_after_config_load (self , _caches ):
77+ def test_individual_instantiated_after_config_load (self ):
8078 """
8179 If a cache is instantiated after the config is read, it will be
8280 immediately resized to the correct size given the per_cache_factor if
@@ -89,7 +87,7 @@ def test_individual_instantiated_after_config_load(self, _caches):
8987 add_resizable_cache ("foo" , cache_resize_callback = cache .set_cache_factor )
9088 self .assertEqual (cache .max_size , 200 )
9189
92- def test_global_instantiated_before_config_load (self , _caches ):
90+ def test_global_instantiated_before_config_load (self ):
9391 """
9492 If a cache is instantiated before the config is read, it will be given
9593 the default cache size in the interim, and then resized to the new
@@ -104,7 +102,7 @@ def test_global_instantiated_before_config_load(self, _caches):
104102
105103 self .assertEqual (cache .max_size , 400 )
106104
107- def test_global_instantiated_after_config_load (self , _caches ):
105+ def test_global_instantiated_after_config_load (self ):
108106 """
109107 If a cache is instantiated after the config is read, it will be
110108 immediately resized to the correct size given the global factor if there
@@ -117,7 +115,7 @@ def test_global_instantiated_after_config_load(self, _caches):
117115 add_resizable_cache ("foo" , cache_resize_callback = cache .set_cache_factor )
118116 self .assertEqual (cache .max_size , 150 )
119117
120- def test_cache_with_asterisk_in_name (self , _caches ):
118+ def test_cache_with_asterisk_in_name (self ):
121119 """Some caches have asterisks in their name, test that they are set correctly."""
122120
123121 config = {
@@ -143,7 +141,7 @@ def test_cache_with_asterisk_in_name(self, _caches):
143141 add_resizable_cache ("*cache_c*" , cache_resize_callback = cache_c .set_cache_factor )
144142 self .assertEqual (cache_c .max_size , 200 )
145143
146- def test_apply_cache_factor_from_config (self , _caches ):
144+ def test_apply_cache_factor_from_config (self ):
147145 """Caches can disable applying cache factor updates, mainly used by
148146 event cache size.
149147 """
0 commit comments