Skip to content

Commit

Permalink
fix hanging tests
Browse files Browse the repository at this point in the history
mocha has been bumped to the version required for Tool Kit.
After mocha v4 tests are not forced to exit if they hang (https://mochajs.org/#-exit). The poller tests hang because many of them start a poller process but don't end it so they never exit.
The commit stops all the pollers that are started in tests so that they exit successfully.
  • Loading branch information
jkerr321 committed Jan 16, 2023
1 parent d75e85e commit 510d33d
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions test/poller.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global it, describe, xit */
/* global it, describe */

const mockery = require ('mockery');
const chai = require ('chai');
Expand Down Expand Up @@ -30,6 +30,7 @@ describe ('Poller', function () {
const poller = new Poller( { url: '/' } );
poller.start ();
expect (poller.isRunning ()).to.equal (true);
poller.stop ();
});

it ('Should avoid starting a job twice', function () {
Expand All @@ -38,6 +39,7 @@ describe ('Poller', function () {
expect (function () {
poller.start ();
}).to.throw ('Could not start job because the service is already running');
poller.stop ();
});

it ('Should stop a job', function () {
Expand Down Expand Up @@ -122,14 +124,15 @@ describe ('Poller', function () {
poller.start ();
clock.tick (6000); // fast-forward 6 seconds
clock.restore ();

poller.stop ();
});

it ('Should allow the first scheduled poll to happen immediately', function () {
const poller = new Poller( { url: '/' } );
const spy = sinon.spy (poller, 'fetch');
poller.start ({ initialRequest: true });
expect (spy.callCount).to.equal (1);
poller.stop ();
});

it ('Should return a promise which resolves when initial fetch happens', function (done) {
Expand All @@ -143,6 +146,7 @@ describe ('Poller', function () {
done ();
});
expect (spy.callCount).to.equal (1);
poller.stop ();
});

it ('Should resolve start with a promise immediately when not doing an initial fetch', function (done) {
Expand All @@ -156,6 +160,7 @@ describe ('Poller', function () {
done ();
});
expect (spy.callCount).to.equal (0);
poller.stop ();
});

it ('Should fire an event when a error is received from the server', function (done) {
Expand Down Expand Up @@ -205,7 +210,7 @@ describe ('Poller', function () {
expect(eventEmitterStub.getCall (0).args[1]).to.be.an.instanceOf(HttpError);
done ();
}, 10);

p.stop ();
});

it ('Should annotate the polling response with latency information', function (done) {
Expand Down Expand Up @@ -351,11 +356,9 @@ describe ('Poller', function () {
expect (p.start.calledOnce).to.be.true;
expect (p.start.args[0][0]).to.deep.equal ({initialRequest: true});
stub.restore ();
p.stop ();
});

xit ('Should allow a maximum HTTP timeout of 4000ms');
xit ('Should respond to receiving a Retry-After header');

it ('Should fire a "data" event when new data is received and parsed', (done) => {
const stub = { 'foo': 1 };
nock ('http://example.com')
Expand All @@ -372,6 +375,7 @@ describe ('Poller', function () {
expect (data).to.deep.equal (stub);
done ();
});
p.stop ();
});

it ('Should have the ability to manually retry', done => {
Expand All @@ -398,6 +402,7 @@ describe ('Poller', function () {
const onFirst = () => {
p.once ('data', onSecond);
p.retry ();
p.stop ();
};

p.once ('data', onFirst);
Expand Down

0 comments on commit 510d33d

Please sign in to comment.