Skip to content

Commit

Permalink
Merge 0afaadf into 4d00b77
Browse files Browse the repository at this point in the history
  • Loading branch information
awolden authored Jan 19, 2021
2 parents 4d00b77 + 0afaadf commit 28e9fa2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/globalStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ class GlobalStats {
/* listen to event and pipe to stream */
_globalListener(stats) {
if (!stats || typeof stats !== 'object') return;
if (!this._rawStream.isPaused()) {

// as of node 12.6 we need to check for readableFlowing as well since the behavior of isPaused() has changed
if (!this._rawStream.isPaused() || this._rawStream.readableFlowing) {
this._rawStream.push(JSON.stringify(stats));
}
}
Expand Down
23 changes: 23 additions & 0 deletions test/globalStats.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ describe('globalStats', () => {
expect(instance.removeListener.firstCall.args[1]).to.be.a('function');
});

it('_globalListener() should skip if not object', () => {
const data = '';
const stub = sinon.stub(globalStats._rawStream, 'push').callsFake(() => true);
globalStats._globalListener(data);
expect(stub.calledOnce).to.equal(false);
globalStats._rawStream.push.restore();
});

it('_globalListener() should push to rawStream', () => {
const data = {
foo: 'bar'
Expand All @@ -55,6 +63,21 @@ describe('globalStats', () => {
globalStats._rawStream.push.restore();
});

it('_globalListener() should push to rawStream if paused but readableFlowing', () => {
const data = {
foo: 'bar'
};
globalStats._rawStream.readableFlowing = true;
const stub = sinon.stub(globalStats._rawStream, 'push').callsFake(() => true);
const pausedStub = sinon.stub(globalStats._rawStream, 'isPaused').callsFake(() => true);
globalStats._globalListener(data);
expect(stub.calledOnce).to.equal(true);
expect(pausedStub.calledOnce).to.equal(true);
expect(stub.firstCall.args[0]).to.equal(JSON.stringify(data));
globalStats._rawStream.push.restore();
globalStats._rawStream.isPaused.restore();
});

it('_transformToHysterix() should transform to hysterix', done => {
const mock = {
foo: 'bar'
Expand Down

0 comments on commit 28e9fa2

Please sign in to comment.