-
Notifications
You must be signed in to change notification settings - Fork 1
Selki/ff3396 expiring bandit cache #128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
d0093fb
ffc0c59
90429c1
e4d1d26
001ae6e
c386303
e5c85cc
4b02b3e
4bdfa7f
d4a14bd
1cf7391
64c6729
1d1f7ee
7336c3e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,35 +50,41 @@ describe('TLRU Cache', () => { | |
it('should evict all expired entries on .keys() call', () => { | ||
jest.useFakeTimers(); | ||
|
||
cache = new TLRUCache(3, expectedCacheTimeoutMs); | ||
cache.set('a', 'avocado'); | ||
jest.advanceTimersByTime(expectedCacheTimeoutMs); | ||
cache.set('b', 'banana'); | ||
jest.advanceTimersByTime(expectedCacheTimeoutMs); | ||
cache.set('c', 'cherry'); | ||
|
||
const cacheKeys = []; | ||
|
||
for (const key of cache.keys()) { | ||
cacheKeys.push(key); | ||
} | ||
|
||
expect(cacheKeys.length).toBe(0); | ||
expect(cacheKeys.length).toBe(1); | ||
expect(cache.get('c')).toBe('cherry'); | ||
}); | ||
|
||
it('should evict all expired entries on .values() call', () => { | ||
jest.useFakeTimers(); | ||
cache = new TLRUCache(3, expectedCacheTimeoutMs); | ||
|
||
cache.set('a', 'avocado'); | ||
jest.advanceTimersByTime(expectedCacheTimeoutMs); | ||
cache.set('b', 'banana'); | ||
jest.advanceTimersByTime(expectedCacheTimeoutMs); | ||
cache.set('c', 'cherry'); | ||
|
||
const cacheValues = []; | ||
|
||
for (const value of cache.values()) { | ||
cacheValues.push(value); | ||
} | ||
|
||
expect(cacheValues.length).toBe(0); | ||
expect(cacheValues.length).toBe(1); | ||
expect(cache.get('c')).toBe('cherry'); | ||
Comment on lines
+86
to
+87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
}); | ||
|
||
it('should overwrite existing cache entry', () => { | ||
|
@@ -152,8 +158,18 @@ describe('TLRU Cache', () => { | |
cache.set('b', 'banana'); | ||
cache.set('c', 'cherry'); | ||
|
||
const keys = Array.from(cache.keys()); | ||
let keys = Array.from(cache.keys()); | ||
expect(keys[0]).toBe('b'); | ||
expect(keys[1]).toBe('c'); | ||
|
||
cache = new TLRUCache(2, expectedCacheTimeoutMs); | ||
cache.set('a', 'apple'); | ||
cache.set('b', 'banana'); | ||
cache.get('a'); | ||
cache.set('c', 'cherry'); | ||
|
||
keys = Array.from(cache.keys()); | ||
expect(keys[0]).toBe('a'); | ||
expect(keys[1]).toBe('c'); | ||
Comment on lines
+171
to
+173
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💪 |
||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need another test that does:
Then makes sure its |
||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍