From 0dfba93b4de4165c3cf34c56d3c73b4d63a41fc6 Mon Sep 17 00:00:00 2001 From: Siddharth VP Date: Sun, 14 Feb 2021 12:28:07 +0530 Subject: [PATCH] refactor eventstream tests to make them less fragile --- tests/suppl.bot.test.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/tests/suppl.bot.test.js b/tests/suppl.bot.test.js index fb9861e..91fd2e3 100644 --- a/tests/suppl.bot.test.js +++ b/tests/suppl.bot.test.js @@ -35,6 +35,7 @@ describe('supplementary functions', function() { }); it('eventstream', function (done) { + this.timeout(8000); let stream = new bot.stream('recentchange'); function messageHandler(data) { expect(data).to.be.an('object'); @@ -42,14 +43,17 @@ describe('supplementary functions', function() { } let spy = sinon.spy(messageHandler); stream.addListener({}, spy); - setTimeout(function () { - stream.close(); - expect(spy.callCount).to.be.greaterThan(2); - done(); - }, 2000); + let interval = setInterval(function () { + if (spy.callCount > 2) { + stream.close(); + clearInterval(interval); + done(); + } + }, 500); }); it('eventstream with since param', function (done) { + this.timeout(8000); let sinceTime = new bot.date().subtract(5, 'hours'); let stream = new bot.stream('recentchange', { since: sinceTime @@ -64,11 +68,13 @@ describe('supplementary functions', function() { } let spy = sinon.spy(messageHandler); stream.addListener({}, spy); - setTimeout(function () { - stream.close(); - expect(spy.callCount).to.be.greaterThan(2); - done(); - }, 2000); + let interval = setInterval(function () { + if (spy.callCount > 10) { + stream.close(); + clearInterval(interval); + done(); + } + }, 500); });