@@ -200,6 +200,28 @@ describe('redis store test', () => {
200
200
expect ( await client . get ( 'rl:test-store-two' ) ) . toEqual ( null )
201
201
} )
202
202
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
+
203
225
it ( 'default export works' , async ( ) => {
204
226
const store = new DefaultExportRedisStore ( { sendCommand } )
205
227
store . init ( { windowMs : 10 } as Options )
0 commit comments