Skip to content

Commit

Permalink
Merge pull request elastic#7841 from thomasneirynck/fix/windows_has_n…
Browse files Browse the repository at this point in the history
…o_SIGHUP_signal

Do not run a UNIX test on a Windows system.
  • Loading branch information
thomasneirynck authored Jul 27, 2016
2 parents da1187f + a700b8e commit 4943033
Showing 1 changed file with 60 additions and 55 deletions.
115 changes: 60 additions & 55 deletions src/cli/serve/__tests__/reload_logging_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { safeDump } from 'js-yaml';
import es from 'event-stream';
import readYamlConfig from '../read_yaml_config';
import expect from 'expect.js';

const testConfigFile = follow(`fixtures/reload_logging_config/kibana.test.yml`);
const cli = follow(`../../../../bin/kibana`);

Expand All @@ -22,69 +23,73 @@ function setLoggingJson(enabled) {
}

describe(`Server logging configuration`, function () {
it(`should be reloadable via SIGHUP process signaling`, function (done) {
this.timeout(60000);

let asserted = false;
let json = Infinity;
const conf = setLoggingJson(true);
const child = spawn(cli, [`--config`, testConfigFile]);
const isWindows = /^win/.test(process.platform);
if (isWindows) {
it('SIGHUP is not a feature of Windows.');
} else {
it(`should be reloadable via SIGHUP process signaling`, function (done) {
this.timeout(60000);

child.on('error', err => {
done(new Error(`error in child process while attempting to reload config.
${err.stack || err.message || err}`));
});
let asserted = false;
let json = Infinity;
const conf = setLoggingJson(true);
const child = spawn(cli, [`--config`, testConfigFile]);

child.on('exit', code => {
expect(asserted).to.eql(true);
expect(code === null || code === 0).to.eql(true);
done();
});
child.on('error', err => {
done(new Error(`error in child process while attempting to reload config. ${err.stack || err.message || err}`));
});

child.stdout
.pipe(es.split())
.pipe(es.mapSync(function (line) {
if (!line) {
return line; // ignore empty lines
}
if (json--) {
expect(parseJsonLogLine).withArgs(line).to.not.throwError();
} else {
expectPlainTextLogLine(line);
}
}));
child.on('exit', code => {
expect(asserted).to.eql(true);
expect(code === null || code === 0).to.eql(true);
done();
});

function parseJsonLogLine(line) {
try {
const data = JSON.parse(line);
const listening = data.tags.indexOf(`listening`) !== -1;
if (listening) {
switchToPlainTextLog();
child.stdout
.pipe(es.split())
.pipe(es.mapSync(function (line) {
if (!line) {
return line; // ignore empty lines
}
if (json--) {
expect(parseJsonLogLine).withArgs(line).to.not.throwError();
} else {
expectPlainTextLogLine(line);
}
}));

function parseJsonLogLine(line) {
try {
const data = JSON.parse(line);
const listening = data.tags.indexOf(`listening`) !== -1;
if (listening) {
switchToPlainTextLog();
}
} catch (err) {
expect(`Error parsing log line as JSON\n ${err.stack || err.message || err}`).to.eql(true);
}
} catch (err) {
expect(`Error parsing log line as JSON\n
${err.stack || err.message || err}`).to.eql(true);
}
}

function switchToPlainTextLog() {
json = 3; // ignore both "reloading" messages + ui settings status message
setLoggingJson(false);
child.kill(`SIGHUP`); // reload logging config
}
function switchToPlainTextLog() {
json = 3; // ignore both "reloading" messages + ui settings status message
setLoggingJson(false);
child.kill(`SIGHUP`); // reload logging config
}

function expectPlainTextLogLine(line) {
// assert
const tags = `[\u001b[32minfo\u001b[39m][\u001b[36mconfig\u001b[39m]`;
const status = `Reloaded logging configuration due to SIGHUP.`;
const expected = `${tags} ${status}`;
const actual = line.slice(-expected.length);
expect(actual).to.eql(expected);
function expectPlainTextLogLine(line) {
// assert
const tags = `[\u001b[32minfo\u001b[39m][\u001b[36mconfig\u001b[39m]`;
const status = `Reloaded logging configuration due to SIGHUP.`;
const expected = `${tags} ${status}`;
const actual = line.slice(-expected.length);
expect(actual).to.eql(expected);

// cleanup
asserted = true;
setLoggingJson(true);
child.kill();
}
});
// cleanup
asserted = true;
setLoggingJson(true);
child.kill();
}
});
}
});

0 comments on commit 4943033

Please sign in to comment.