1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-05 02:29:26 +02:00

Add a test to verify that older entries get dropped from TtlSet.

This commit is contained in:
Simo Kinnunen 2015-06-02 15:56:39 +09:00
parent 9130717e0e
commit 2ec03798a4

View file

@ -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) {