diff options
author | cjihrig <cjihrig@gmail.com> | 2019-03-04 21:04:31 -0500 |
---|---|---|
committer | cjihrig <cjihrig@gmail.com> | 2019-03-07 15:48:06 -0500 |
commit | c1a9c5000803b2b22843cf665f0582f8f21e7d20 (patch) | |
tree | 770c9eb6331f2d3cb08f2111f5f9bdd744ae1e38 /test/report/test-report-signal.js | |
parent | 3e4e51870ce988b2e9f116607b51f4affdb17357 (diff) | |
download | android-node-v8-c1a9c5000803b2b22843cf665f0582f8f21e7d20.tar.gz android-node-v8-c1a9c5000803b2b22843cf665f0582f8f21e7d20.tar.bz2 android-node-v8-c1a9c5000803b2b22843cf665f0582f8f21e7d20.zip |
test: refactor test/report/test-report-signal.js
PR-URL: https://github.com/nodejs/node/pull/26446
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Masashi Hirano <shisama07@gmail.com>
Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'test/report/test-report-signal.js')
-rw-r--r-- | test/report/test-report-signal.js | 97 |
1 files changed, 27 insertions, 70 deletions
diff --git a/test/report/test-report-signal.js b/test/report/test-report-signal.js index 68f5c25402..a71530a520 100644 --- a/test/report/test-report-signal.js +++ b/test/report/test-report-signal.js @@ -1,79 +1,36 @@ +// Flags: --experimental-report --diagnostic-report-on-signal 'use strict'; -// Testcase to produce report on signal interrupting a js busy-loop, -// showing it is interruptible. +// Test producing a report via signal. const common = require('../common'); common.skipIfReportDisabled(); +if (common.isWindows) + return common.skip('Unsupported on Windows.'); -if (common.isWindows) return common.skip('Unsupported on Windows.'); +if (!common.isMainThread) + common.skip('Signal reporting is only supported in the main thread'); -if (process.argv[2] === 'child') { - // Exit on loss of parent process - const exit = () => process.exit(2); - process.on('disconnect', exit); +const assert = require('assert'); +const helper = require('../common/report'); +const tmpdir = require('../common/tmpdir'); - function busyLoop() { - setInterval(() => { - const list = []; - for (let i = 0; i < 1e3; i++) { - for (let j = 0; j < 1000; j++) { - list.push(new MyRecord()); - } - for (let k = 0; k < 1000; k++) { - list[k].id += 1; - list[k].account += 2; - } - for (let l = 0; l < 1000; l++) { - list.pop(); - } - } - }, 1000); - } +common.expectWarning('ExperimentalWarning', + 'report is an experimental feature. This feature could ' + + 'change at any time'); +tmpdir.refresh(); +process.report.directory = tmpdir.path; - function MyRecord() { - this.name = 'foo'; - this.id = 128; - this.account = 98454324; - } - process.send('child started', busyLoop); +assert.strictEqual(process.listenerCount('SIGUSR2'), 1); +process.kill(process.pid, 'SIGUSR2'); +// Asynchronously wait for the report. In development, a single setImmediate() +// appears to be enough. Use an async loop to be a bit more robust in case +// platform or machine differences throw off the timing. +(function validate() { + const reports = helper.findReports(process.pid, tmpdir.path); -} else { - const helper = require('../common/report.js'); - const fork = require('child_process').fork; - const tmpdir = require('../common/tmpdir'); - tmpdir.refresh(); - const assert = require('assert'); - if (common.isWindows) { - assert.fail('Unsupported on Windows', { skip: true }); - return; - } - console.log(tmpdir.path); - const options = { stdio: 'pipe', encoding: 'utf8', cwd: tmpdir.path }; - const child = fork('--experimental-report', - ['--diagnostic-report-on-signal', __filename, 'child'], - options); - // Wait for child to indicate it is ready before sending signal - child.on('message', () => child.kill('SIGUSR2')); - let stderr = ''; - child.stderr.on('data', (chunk) => { - stderr += chunk; - // Terminate the child after the report has been written - if (stderr.includes('Node.js report completed')) { - child.kill('SIGTERM'); - } - }); - child.on('exit', common.mustCall((code, signal) => { - console.log('child exited'); - console.log(stderr); - const report_msg = 'No reports found'; - const process_msg = 'Process exited unexpectedly'; - const signal_msg = 'Process exited with unexpected signal'; - assert.strictEqual(code, null, process_msg + ':' + code); - assert.deepStrictEqual(signal, 'SIGTERM', - signal_msg + ':' + signal); - const reports = helper.findReports(child.pid, tmpdir.path); - assert.deepStrictEqual(reports.length, 1, report_msg); - const report = reports[0]; - helper.validate(report); - })); -} + if (reports.length === 0) + return setImmediate(validate); + + assert.strictEqual(reports.length, 1); + helper.validate(reports[0]); +})(); |