diff --git a/lib/client-metrics/ttl-list.test.js b/lib/client-metrics/ttl-list.test.js index fec8e922e2..0687ea929a 100644 --- a/lib/client-metrics/ttl-list.test.js +++ b/lib/client-metrics/ttl-list.test.js @@ -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(); });