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

[UFC] Clear config store before loading new config #30

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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
Loading