From e436ca3d4279f20667b2320a9b45ffbe39f9141e Mon Sep 17 00:00:00 2001 From: Sven Schmit Date: Thu, 25 Apr 2024 15:19:33 -0700 Subject: [PATCH] clear config store before loading new config --- eppo_client/configuration_store.py | 1 + test/configuration_store_test.py | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/eppo_client/configuration_store.py b/eppo_client/configuration_store.py index b54ff7c..fec7689 100644 --- a/eppo_client/configuration_store.py +++ b/eppo_client/configuration_store.py @@ -23,6 +23,7 @@ def get_configuration(self, key: str) -> Optional[T]: def set_configurations(self, configs: Dict[str, T]): try: self.__lock.acquire_write() + self.__cache.clear() for key, config in configs.items(): self.__cache[key] = config finally: diff --git a/test/configuration_store_test.py b/test/configuration_store_test.py index 0cc0d4a..a88ceab 100644 --- a/test/configuration_store_test.py +++ b/test/configuration_store_test.py @@ -37,3 +37,16 @@ def test_evicts_old_entries_when_max_size_exceeded(): assert ( store.get_configuration("test-entry-{}".format(TEST_MAX_SIZE - 1)) == mock_flag ) + + +def test_evicts_old_entries_when_setting_new_flags(): + store: ConfigurationStore[str] = ConfigurationStore(max_size=TEST_MAX_SIZE) + + store.set_configurations({"flag": mock_flag, "second_flag": mock_flag}) + assert store.get_configuration("flag") == mock_flag + assert store.get_configuration("second_flag") == mock_flag + + # Updating the flags should evict flags that no longer exist + store.set_configurations({"flag": mock_flag}) + assert store.get_configuration("flag") == mock_flag + assert store.get_configuration("second_flag") is None