diff --git a/src/environment_data.cc b/src/environment_data.cc index a3e971f..1db1494 100644 --- a/src/environment_data.cc +++ b/src/environment_data.cc @@ -55,7 +55,8 @@ EnvironmentData::EnvironmentData(v8::Isolate* isolate, uv_loop_t* loop) void EnvironmentData::AtExit(void* arg) { // TODO(legendecas): environment registry. - per_process::environment_data.reset(); + // TODO(hyj1991): avoid 0xC0000005 on windows + // per_process::environment_data.reset(); } void EnvironmentData::SendCollectStatistics() { diff --git a/test/commands.test.js b/test/commands.test.js index d1885d1..28adfb3 100644 --- a/test/commands.test.js +++ b/test/commands.test.js @@ -44,6 +44,7 @@ for (let i = 0; i < testConfig.length; i++) { let resByXctl = ''; let resByXprofctl = ''; let pid = 0; + let exitInfo = { code: null, signal: null }; before(async function () { mm(os, 'homedir', () => tmphome); console.log(`[${moment().format('YYYY-MM-DD HH:mm:ss')}]`, 'start fork.'); @@ -72,7 +73,7 @@ for (let i = 0; i < testConfig.length; i++) { }); resByXprofctl = resByXprofctl.stderr.trim() + resByXprofctl.stdout.trim(); console.log(`[${moment().format('YYYY-MM-DD HH:mm:ss')}]`, 'wait for child process done.'); - await new Promise(resolve => p.on('close', resolve)); + exitInfo = await utils.getChildProcessExitInfo(p); }); after(function () { @@ -83,6 +84,11 @@ for (let i = 0; i < testConfig.length; i++) { } }); + it(`child process should be exited with code 0`, function () { + console.log(`[${moment().format('YYYY-MM-DD HH:mm:ss')}]`, `exit info: ${JSON.stringify(exitInfo)}`); + utils.checkChildProcessExitInfo(expect, exitInfo); + }); + it(`response with xctl should be ok`, function () { console.log('xtcl:', JSON.stringify(resByXctl)); expect(resByXctl).to.be.ok(); diff --git a/test/fixtures/utils.js b/test/fixtures/utils.js index be4b112..782002c 100644 --- a/test/fixtures/utils.js +++ b/test/fixtures/utils.js @@ -57,6 +57,17 @@ exports.getNestingValue = function (origin, key) { return origin; }; -exports.arrayEqual = function arrayEqual(arr1, arr2) { +exports.arrayEqual = function (arr1, arr2) { return arr1.every(a1 => arr2.includes(a1)) && arr2.every(a2 => arr1.includes(a2)); +}; + +exports.getChildProcessExitInfo = function (proc) { + return new Promise(resolve => proc.on('close', (code, signal) => resolve({ code, signal }))); +}; + +exports.checkChildProcessExitInfo = function (expect, exitInfo) { + const { code, signal } = exitInfo; + // One of the code | signal will always be non-null. + expect(code === 0).to.be.ok(); + expect(signal === null).to.be.ok(); }; \ No newline at end of file diff --git a/test/logbypass.test.js b/test/logbypass.test.js index d4da569..c8dd470 100644 --- a/test/logbypass.test.js +++ b/test/logbypass.test.js @@ -3,6 +3,7 @@ const fs = require('fs'); const cp = require('child_process'); const expect = require('expect.js'); +const moment = require('moment'); const pack = require('../package.json'); const utils = require('./fixtures/utils'); const getTestCases = require('./fixtures/logbypass.test'); @@ -77,10 +78,11 @@ for (const testCase of cases) { /*eslint no-loop-func: "off" */ let logContent; let pid; + let exitInfo = { code: null, signal: null }; before(async function () { const p = cp.fork(target.file, { env: Object.assign({ XPROFILER_LOG_TYPE: 1 }, testCase.env, target.env) }); pid = p.pid; - await new Promise(resolve => p.on('close', resolve)); + exitInfo = await utils.getChildProcessExitInfo(p); logContent = fs.readFileSync(target.logfile, 'utf8'); }); @@ -98,6 +100,11 @@ for (const testCase of cases) { } }); + it(`child process should be exited with code 0`, function () { + console.log(`[${moment().format('YYYY-MM-DD HH:mm:ss')}]`, `exit info: ${JSON.stringify(exitInfo)}`); + utils.checkChildProcessExitInfo(expect, exitInfo); + }); + const types = Object.keys(testCase.struct); for (const type of types) { describe(`parse log type [${type}] with content`, function () {