Skip to content

Commit 4f7ecc6

Browse files
authored
Merge pull request #58 from launchdarkly/eb/ch18811/missing-clear
re-add missing clear method to user keys cache
2 parents 6395345 + 43b453d commit 4f7ecc6

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

ldclient/lru_cache.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,5 @@ def put(self, key, value):
4949
self.cache[key] = value
5050
return found
5151

52+
def clear(self):
53+
self.cache.clear()

testing/test_event_processor.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,44 @@ def test_index_event_is_still_generated_if_inline_users_is_true_but_feature_even
191191
check_index_event(output[0], e, user)
192192
check_summary_event(output[1])
193193

194+
def test_two_events_for_same_user_only_produce_one_index_event():
195+
setup_processor(Config(user_keys_flush_interval = 300))
196+
197+
e0 = {
198+
'kind': 'feature', 'key': 'flagkey', 'version': 11, 'user': user,
199+
'variation': 1, 'value': 'value', 'default': 'default', 'trackEvents': True
200+
}
201+
e1 = e0.copy();
202+
ep.send_event(e0)
203+
ep.send_event(e1)
204+
205+
output = flush_and_get_events()
206+
assert len(output) == 4
207+
check_index_event(output[0], e0, user)
208+
check_feature_event(output[1], e0, False, None)
209+
check_feature_event(output[2], e1, False, None)
210+
check_summary_event(output[3])
211+
212+
def test_new_index_event_is_added_if_user_cache_has_been_cleared():
213+
setup_processor(Config(user_keys_flush_interval = 0.1))
214+
215+
e0 = {
216+
'kind': 'feature', 'key': 'flagkey', 'version': 11, 'user': user,
217+
'variation': 1, 'value': 'value', 'default': 'default', 'trackEvents': True
218+
}
219+
e1 = e0.copy();
220+
ep.send_event(e0);
221+
time.sleep(0.2)
222+
ep.send_event(e1)
223+
224+
output = flush_and_get_events()
225+
assert len(output) == 5
226+
check_index_event(output[0], e0, user)
227+
check_feature_event(output[1], e0, False, None)
228+
check_index_event(output[2], e1, user)
229+
check_feature_event(output[3], e1, False, None)
230+
check_summary_event(output[4])
231+
194232
def test_event_kind_is_debug_if_flag_is_temporarily_in_debug_mode():
195233
setup_processor(Config())
196234

0 commit comments

Comments
 (0)