Skip to content

Commit 9831466

Browse files
committed
Added a test for out-of-sync ttls
1 parent 3fca4d6 commit 9831466

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/index.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,30 @@ var Limiter = require('..');
133133
done();
134134
});
135135
});
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+
});
136160
});
137161

138162
describe('when trying to decrease before setting value', function() {

0 commit comments

Comments
 (0)