1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/lib/services/client-metrics/ttl-list.test.js
Ivar Conradi Østhus cdfba8f7b1 feat: Adds last-seen dat on toggles
When an application updates metrics for a toggle we now
stores the timestamp on the toggle when it was last seen
used by an application. This will make it much easier to
detect toggles not in use anymore.

closes #642
2020-12-22 11:05:00 +01:00

64 lines
1.3 KiB
JavaScript

'use strict';
const test = require('ava');
const moment = require('moment');
const lolex = require('lolex');
const TTLList = require('./ttl-list');
test.cb('should emit expire', t => {
const clock = lolex.install();
const list = new TTLList({
interval: 20,
expireAmount: 10,
expireType: 'milliseconds',
});
list.on('expire', entry => {
list.destroy();
t.true(entry.n === 1);
t.end();
});
list.add({ n: 1 });
clock.tick(21);
});
test.cb('should slice off list', t => {
const clock = lolex.install();
const list = new TTLList({
interval: 10,
expireAmount: 10,
expireType: 'milliseconds',
});
list.add({ n: '1' }, moment().add(1, 'milliseconds'));
list.add({ n: '2' }, moment().add(50, 'milliseconds'));
list.add({ n: '3' }, moment().add(200, 'milliseconds'));
list.add({ n: '4' }, moment().add(300, 'milliseconds'));
const expired = [];
list.on('expire', entry => {
// console.timeEnd(entry.n);
expired.push(entry);
});
clock.tick(21);
t.true(expired.length === 1);
clock.tick(51);
t.true(expired.length === 2);
clock.tick(201);
t.true(expired.length === 3);
clock.tick(301);
t.true(expired.length === 4);
list.destroy();
clock.uninstall();
t.end();
});