mirror of
https://github.com/openstf/stf
synced 2025-10-05 19:42:01 +02:00
Add a test to verify that older entries get dropped from TtlSet.
This commit is contained in:
parent
9130717e0e
commit
2ec03798a4
1 changed files with 24 additions and 0 deletions
|
@ -1,10 +1,34 @@
|
|||
var chai = require('chai')
|
||||
var sinon = require('sinon')
|
||||
var expect = chai.expect
|
||||
chai.use(require('sinon-chai'))
|
||||
|
||||
var TtlSet = require('../../lib/util/ttlset')
|
||||
|
||||
describe('TtlSet', function() {
|
||||
|
||||
it.only('should timeout old entries', function(done) {
|
||||
var ttlset = new TtlSet(50)
|
||||
|
||||
var spy = sinon.spy()
|
||||
ttlset.on('timeout', spy)
|
||||
|
||||
ttlset.bump(1, Date.now())
|
||||
ttlset.bump(2, Date.now() + 100)
|
||||
ttlset.bump(3, Date.now() + 200)
|
||||
ttlset.bump(4, Date.now() + 1000)
|
||||
|
||||
setTimeout(function() {
|
||||
expect(spy).to.have.been.calledThrice
|
||||
expect(spy).to.have.been.calledWith(1)
|
||||
expect(spy).to.have.been.calledWith(2)
|
||||
expect(spy).to.have.been.calledWith(3)
|
||||
expect(ttlset.head).to.equal(ttlset.tail)
|
||||
ttlset.stop()
|
||||
done()
|
||||
}, 300)
|
||||
})
|
||||
|
||||
describe('bump', function() {
|
||||
|
||||
it('should create an item for the value if none exists', function(done) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue