Merge pull request #738 from log4js-node/passenger-fix

fix: #525 disableClustering broken on passenger
This commit is contained in:
Gareth Jones 2018-06-25 08:08:08 +10:00 committed by GitHub
commit 0735e55a37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 1 deletions

View File

@ -211,7 +211,7 @@ function configure(configurationFileOrObject) {
// just in case configure is called after shutdown
process.removeListener('message', receiver);
if (cluster) {
if (cluster && !config.disableClustering) {
cluster.removeListener('message', receiver);
}
if (config.disableClustering) {

View File

@ -0,0 +1,51 @@
const test = require('tap').test;
const sandbox = require('sandboxed-module');
// passenger provides a non-functional cluster module,
// but it does not implement the event emitter functions
// this is taken from https://github.com/phusion/passenger/blob/82bef697c0019c034faeb9b0f8c08a43ec4e1e22/src/helper-scripts/node-loader.js#L64
const passengerCluster = {
disconnect: function () { return false; },
fork: function () { return false; },
setupMaster: function () { return false; },
isWorker: true,
isMaster: false,
schedulingPolicy: false,
settings: false,
worker: false,
workers: false,
};
const vcr = require('../../lib/appenders/recording');
const log4js = sandbox.require(
'../../lib/log4js',
{
requires: {
cluster: passengerCluster,
'./appenders/recording': vcr
}
}
);
test('When running in Passenger', (batch) => {
batch.test('it should still log', (t) => {
log4js.configure({
appenders: {
vcr: { type: 'recording' }
},
categories: {
default: { appenders: ['vcr'], level: 'info' }
},
disableClustering: true
});
log4js.getLogger().info('This should still work');
const events = vcr.replay();
t.equal(events.length, 1);
t.equal(events[0].data[0], 'This should still work');
t.end();
});
batch.end();
});