From d944ed0dfa71d79420283c43bff496f603d18328 Mon Sep 17 00:00:00 2001 From: jbigman Date: Thu, 3 Aug 2023 20:06:54 +0200 Subject: [PATCH] Updated throttle to 2000ms interval and assertions checks results +/- 1000ms --- test/utils.throttle.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/utils.throttle.js b/test/utils.throttle.js index 2a266e11..fe25721f 100644 --- a/test/utils.throttle.js +++ b/test/utils.throttle.js @@ -4,6 +4,7 @@ const sinon = require('sinon'); const assert = require('chai').assert; describe('Throttle tests', function () { + this.timeout(6000); let server; // Create a fake http server to emulate http call and responses. @@ -18,13 +19,13 @@ describe('Throttle tests', function () { const url = 'https://yesno.wtf/api'; // Fake url used in this test, it could be anything. - it('Should make three requests with 1000ms interval. (Throttle function)', function () { + it('Should make three requests with 2000ms interval. (Throttle function)', function () { // If we don't want to rely on the availability of a particular api we can use mocks. // The fake server intercept http calls and return specified objects if it mach the same method/url. server.respondWith('GET', url, JSON.stringify({ test: 'this works' })); const req = throttled(requestLib, { limit: 1, - interval: 1000 + interval: 2000 }); return Promise.all([req({ url }), req({ url }), req({ url })]) .then((response) => response.map(req => new Date(req.headers.date).getTime())) @@ -33,9 +34,9 @@ describe('Throttle tests', function () { const secondAndThirdReq = dates[2] - dates[1]; assert.isAtLeast(firstAndSecondReq, 1000); - assert.isAtMost(firstAndSecondReq, 2000); + assert.isAtMost(firstAndSecondReq, 3000); assert.isAtLeast(secondAndThirdReq, 1000); - assert.isAtMost(secondAndThirdReq, 2000); + assert.isAtMost(secondAndThirdReq, 3000); }); }); });