1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00

use fake timers for ttl test

This commit is contained in:
ivaosthu 2016-12-17 12:55:28 +01:00
parent d4ddb24b1d
commit 2c46672784

View File

@ -3,6 +3,7 @@
const test = require('ava');
const TTLList = require('./ttl-list');
const moment = require('moment');
const sinon = require('sinon');
test.cb('should emit expire', (t) => {
const list = new TTLList({
@ -21,6 +22,8 @@ test.cb('should emit expire', (t) => {
});
test.cb('should slice off list', (t) => {
const clock = sinon.useFakeTimers();
const list = new TTLList({
interval: 10,
expireAmount: 10,
@ -40,18 +43,21 @@ test.cb('should slice off list', (t) => {
expired.push(entry);
});
setTimeout(() => {
t.true(expired.length === 1);
}, 30);
setTimeout(() => {
t.true(expired.length === 2);
}, 71);
setTimeout(() => {
t.true(expired.length === 3);
}, 221);
setTimeout(() => {
t.true(expired.length === 4);
list.destroy();
t.end();
}, 330);
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.restore();
sinon.restore();
t.end();
});