File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -133,6 +133,30 @@ var Limiter = require('..');
133
133
done ( ) ;
134
134
} ) ;
135
135
} ) ;
136
+ it ( 'updating the count should keep all TTLs in sync' , function ( done ) {
137
+ var limit = new Limiter ( {
138
+ duration : 10000 ,
139
+ max : 2 ,
140
+ id : 'something' ,
141
+ db : db
142
+ } ) ;
143
+ limit . get ( function ( err , res ) { } ) ; // All good here.
144
+ limit . get ( function ( err , res ) {
145
+ db . multi ( )
146
+ . pttl ( [ 'limit:something:count' ] )
147
+ . pttl ( [ 'limit:something:limit' ] )
148
+ . pttl ( [ 'limit:something:reset' ] )
149
+ . exec ( function ( err , res ) {
150
+ if ( err ) return done ( err ) ;
151
+ var ttlCount = ( typeof res [ 0 ] === 'number' ) ? res [ 0 ] : res [ 0 ] [ 1 ] ;
152
+ var ttlLimit = ( typeof res [ 1 ] === 'number' ) ? res [ 1 ] : res [ 1 ] [ 1 ] ;
153
+ var ttlReset = ( typeof res [ 2 ] === 'number' ) ? res [ 2 ] : res [ 2 ] [ 1 ] ;
154
+ ttlLimit . should . equal ( ttlCount ) ;
155
+ ttlReset . should . equal ( ttlCount ) ;
156
+ done ( ) ;
157
+ } ) ;
158
+ } ) ;
159
+ } ) ;
136
160
} ) ;
137
161
138
162
describe ( 'when trying to decrease before setting value' , function ( ) {
You can’t perform that action at this time.
0 commit comments