Skip to content

Commit 54d916d

Browse files
committed
test: attempt to add test for ttl close to 0 returning 0
1 parent c34fb8c commit 54d916d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

test/store-test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,28 @@ describe('redis store test', () => {
200200
expect(await client.get('rl:test-store-two')).toEqual(null)
201201
})
202202

203+
it.skip('do not reset the expiration when the ttl is very close to 0', async () => {
204+
const store = new RedisStore({ sendCommand })
205+
const windowMs = 60
206+
store.init({ windowMs } as Options)
207+
208+
const key = 'test-store'
209+
await store.increment(key)
210+
211+
// FIXME: This makes the mock client return ttl = 1, not 0. So does setting
212+
// the ttl via client.pexpire to 1. Setting the ttl to 0 makes it expire
213+
// instantly, so the ttl returned is -2. If you can figure out a way to
214+
// consistently reproduce the close-to-0 behaviour with the mock client,
215+
// replace the advanceTimersByTime call with it.
216+
jest.advanceTimersByTime(59)
217+
await store.increment(key)
218+
219+
// Ensure the hit count is 2, and the expiry is not reset
220+
expect(Number(await client.pttl('rl:test-store'))).not.toEqual(windowMs)
221+
expect(Number(await client.pttl('rl:test-store'))).toBeLessThanOrEqual(0)
222+
expect(Number(await client.get('rl:test-store'))).toEqual(2)
223+
})
224+
203225
it('default export works', async () => {
204226
const store = new DefaultExportRedisStore({ sendCommand })
205227
store.init({ windowMs: 10 } as Options)

0 commit comments

Comments
 (0)