Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
clear config store before loading new config (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
schmit authored and leoromanovsky committed May 23, 2024
1 parent a52c582 commit 46d1701
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions eppo_client/configuration_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 13 additions & 0 deletions test/configuration_store_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,16 @@ def test_evicts_old_entries_when_max_size_exceeded():
assert (
store.get_configuration("test-entry-{}".format(TEST_MAX_SIZE - 1)) == test_exp
)


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

0 comments on commit 46d1701

Please sign in to comment.