Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

End cleanup #419

Merged
merged 2 commits into from Dec 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/monitor.js
Expand Up @@ -192,8 +192,10 @@ class Monitor extends Events.EventEmitter {
this._server.removeListener(event, handler);
});

this.emit('stop');
return callback();
this._dataStream.push(null);
// Do a setImmediate here so that all the streams listening for "end" have a chance to run
// https://github.com/nodejs/node/blob/master/lib/_stream_readable.js#L894-L897
return setImmediate(callback);
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -30,7 +30,7 @@
"code": "2.x.x",
"hapi": "10.x.x",
"insync": "2.1.x",
"lab": "7.x.x"
"lab": "7.3.x"
},
"scripts": {
"test": "lab -m 5000 -t 100 -v -La code",
Expand Down
4 changes: 2 additions & 2 deletions test/helper.js
Expand Up @@ -19,12 +19,12 @@ class Reporter {
}
});

emitter.once('stop', () => {
stream.on('end', () => {

this.stopped = true;
});

callback();
process.nextTick(callback);
}
}

Expand Down
19 changes: 6 additions & 13 deletions test/monitor.js
Expand Up @@ -123,14 +123,7 @@ describe('Monitor', () => {

it(`attaches events for 'ops', 'tail', 'log', and 'request-error'`, (done) => {

const one = new GoodReporter();
one.start = (emitter, callback) => {

callback(null);
};
const monitor = internals.monitorFactory(new Hapi.Server(), {
reporters: [one]
});
const monitor = internals.monitorFactory(new Hapi.Server(), { reporters: [new GoodReporter()] } );
monitor.start((error) => {

expect(error).to.not.exist();
Expand Down Expand Up @@ -213,16 +206,15 @@ describe('Monitor', () => {

describe('stop()', () => {

it('cleans up open timeouts, removes event handlers, and emits a stop event', (done) => {
it('cleans up open timeouts, removes event handlers, and pushes null to the read stream', (done) => {

const one = new GoodReporter({ log: '*' });
const two = new GoodReporter({ ops: '*' });
const monitor = internals.monitorFactory(new Hapi.Server(), {
reporters: [one, two],
extensions: ['stop']
extensions: ['request-internal']
});


Insync.series([
monitor.start.bind(monitor),
(callback) => {
Expand All @@ -243,10 +235,11 @@ describe('Monitor', () => {
expect(monitor._server.listeners('internalError')).to.have.length(0);
expect(monitor._server.listeners('tail')).to.have.length(0);
expect(monitor._server.listeners('stop')).to.have.length(0);
done();

callback();
});
}
]);
], done);
});
});

Expand Down