From c9084074b5112f37e260678f9d1902fda3e2f82e Mon Sep 17 00:00:00 2001 From: Shashank Khare Date: Mon, 19 Aug 2019 14:08:54 +0100 Subject: [PATCH] Fix test broken by changing the default Also fix the get_caching_state function and comment. --- arctic/_cache.py | 19 ++++++++----------- tests/integration/test_arctic.py | 1 - 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/arctic/_cache.py b/arctic/_cache.py index 932877143..ab2e079fb 100644 --- a/arctic/_cache.py +++ b/arctic/_cache.py @@ -10,9 +10,9 @@ CACHE_SETTINGS = 'settings' CACHE_SETTINGS_KEY = 'cache' """ -Sample cache_settings collection entry: -meta_db.cache_settings.insertOne({"type": "cache", "enabled": true, "cache_expiry": 600}) -meta_db.cache_settings.find(): { "_id" : ObjectId("5cd5388b9fddfbe6e968f11b"), "type": "cache", "enabled" : false, "cache_expiry" : 600 } +Sample settings collection entry: +meta_db.settings.insertOne({"type": "cache", "enabled": true, "cache_expiry": 600}) +meta_db.settings.find(): { "_id" : ObjectId("5cd5388b9fddfbe6e968f11b"), "type": "cache", "enabled" : false, "cache_expiry" : 600 } """ DEFAULT_CACHE_EXPIRY = 3600 @@ -46,7 +46,7 @@ def set_caching_state(self, enabled): logging.error("Enabled should be a boolean type.") return - if CACHE_SETTINGS not in self._cachedb.list_collection_names(): + if (CACHE_SETTINGS not in self._cachedb.list_collection_names()) or self._cachedb[CACHE_SETTINGS].count() == 0: logging.info("Creating %s collection for cache settings" % CACHE_SETTINGS) self._cachedb[CACHE_SETTINGS].insert_one({ 'type': CACHE_SETTINGS_KEY, @@ -129,10 +129,7 @@ def update_item_for_key(self, key, old, new): def is_caching_enabled(self, cache_enabled_in_env): cache_settings = self._get_cache_settings() - # Caching is enabled unless explicitly disabled. Can be disabled either by an env variable or config in mongo. - if cache_settings and not cache_settings['enabled']: - return False - # Disabling from Mongo Setting take precedence over this env variable - if not cache_enabled_in_env: - return False - return True + # Explicitly setting the setting takes precedence over env. + if cache_settings: + return cache_settings['enabled'] + return cache_enabled_in_env diff --git a/tests/integration/test_arctic.py b/tests/integration/test_arctic.py index 535d4f0d3..8a7a9177c 100644 --- a/tests/integration/test_arctic.py +++ b/tests/integration/test_arctic.py @@ -323,7 +323,6 @@ def test_disable_cache_by_settings(arctic): # Should be enabled by default assert arctic._list_libraries_cached() == arctic._list_libraries() - arctic._cache.set_caching_state(enabled=False) # Should not return cached results now.