From 9064f5917138702fcea83d1cb078ebca371b1737 Mon Sep 17 00:00:00 2001 From: Eirik Stanghelle Morland Date: Fri, 27 Dec 2024 22:43:21 +0100 Subject: [PATCH] Make the tests less flaky (#150) --- test/mainLoop.test.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/mainLoop.test.ts b/test/mainLoop.test.ts index 3226a50..65ac378 100644 --- a/test/mainLoop.test.ts +++ b/test/mainLoop.test.ts @@ -6,6 +6,12 @@ var port = 25212 var lastReq var smallestInterval const server = http.createServer(function (req, res) { + if (counter % 4 === 0) { + counter++ + res.writeHead(404) + res.end() + return + } if (req.url === "/http-queue/get-a-job") { if (!lastReq) { lastReq = Date.now() @@ -114,8 +120,9 @@ describe('Main cloud loop', () => { } stopIt() server.close() - if (smallestInterval < sleepTime) { - throw new Error('Smallest interval (' + smallestInterval + ') was smaller than the smallest pause (' + sleepTime + ')') + // Allow a small offset. Seems tests are failing with 99ms flakily. + if (smallestInterval < (sleepTime - 20)) { + throw new Error('Smallest interval (' + smallestInterval + ') was smaller than the smallest pause (' + sleepTime + ') well minus the offset') } resolve(null) })