From 485f17737bc0f138210044286d0ebfbeaf030e4d Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Fri, 1 May 2020 18:22:15 +0100 Subject: [PATCH] fix tests --- synapse/config/cache.py | 19 +++++++++---------- tests/config/test_cache.py | 6 +++--- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/synapse/config/cache.py b/synapse/config/cache.py index a8dc93c225..ffce1d0a0d 100644 --- a/synapse/config/cache.py +++ b/synapse/config/cache.py @@ -103,20 +103,12 @@ class CacheConfig(Config): # Set the global one so that it's reflected in new caches properties.default_factor_size = self.global_factor - # Load cache factors from the config, but override them with the - # environment if they exist + # Load cache factors from the config individual_factors = cache_config.get("per_cache_factors", {}) or {} if not isinstance(individual_factors, dict): raise ConfigError("caches.per_cache_factors must be a dictionary") - for cache, factor in individual_factors.items(): - if not isinstance(factor, (int, float)): - raise ConfigError( - "caches.per_cache_factors.%s must be a number" % (cache.lower(),) - ) - self.cache_factors[cache.lower()] = factor - - # Override with environment + # Override factors from environment if necessary individual_factors.update( { key[len(_CACHE_PREFIX) + 1 :].lower(): float(val) @@ -125,6 +117,13 @@ class CacheConfig(Config): } ) + for cache, factor in individual_factors.items(): + if not isinstance(factor, (int, float)): + raise ConfigError( + "caches.per_cache_factors.%s must be a number" % (cache.lower(),) + ) + self.cache_factors[cache.lower()] = factor + # Resize all caches (if necessary) with the new factors we've loaded self.resize_all_caches() diff --git a/tests/config/test_cache.py b/tests/config/test_cache.py index 88d5302643..2920279125 100644 --- a/tests/config/test_cache.py +++ b/tests/config/test_cache.py @@ -49,8 +49,8 @@ class CacheConfigTests(TestCase): def test_config_overrides_environ(self): """ - Individual cache factors defined in config will take precedence over - ones in the environment. + Individual cache factors defined in the environment will take precedence + over those in the config. """ config = {"caches": {"per_cache_factors": {"foo": 2, "bar": 3}}} t = TestConfig() @@ -62,7 +62,7 @@ class CacheConfigTests(TestCase): self.assertEqual( dict(t.caches.cache_factors), - {"foo": 2.0, "bar": 3.0, "something_or_other": 2.0}, + {"foo": 1.0, "bar": 3.0, "something_or_other": 2.0}, ) def test_individual_instantiated_before_config_load(self):