| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 991ea8a commit 153a29c
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,79 +1,36 @@ | |||
| 1 | + // Flags: --experimental-report --diagnostic-report-on-signal | ||
| 1 | 2 | 'use strict'; | |
| 2 | - // Testcase to produce report on signal interrupting a js busy-loop, | ||
| 3 | - // showing it is interruptible. | ||
| 3 | + // Test producing a report via signal. | ||
| 4 | 4 | const common = require('../common'); | |
| 5 | 5 | common.skipIfReportDisabled(); | |
| 6 | + if (common.isWindows) | ||
| 7 | + return common.skip('Unsupported on Windows.'); | ||
| 6 | 8 | ||
| 7 | - if (common.isWindows) return common.skip('Unsupported on Windows.'); | ||
| 9 | + if (!common.isMainThread) | ||
| 10 | + common.skip('Signal reporting is only supported in the main thread'); | ||
| 8 | 11 | ||
| 9 | - if (process.argv[2] === 'child') { | ||
| 10 | - // Exit on loss of parent process | ||
| 11 | - const exit = () => process.exit(2); | ||
| 12 | - process.on('disconnect', exit); | ||
| 12 | + const assert = require('assert'); | ||
| 13 | + const helper = require('../common/report'); | ||
| 14 | + const tmpdir = require('../common/tmpdir'); | ||
| 13 | 15 | ||
| 14 | - function busyLoop() { | ||
| 15 | - setInterval(() => { | ||
| 16 | - const list = []; | ||
| 17 | - for (let i = 0; i < 1e3; i++) { | ||
| 18 | - for (let j = 0; j < 1000; j++) { | ||
| 19 | - list.push(new MyRecord()); | ||
| 20 | - } | ||
| 21 | - for (let k = 0; k < 1000; k++) { | ||
| 22 | - list[k].id += 1; | ||
| 23 | - list[k].account += 2; | ||
| 24 | - } | ||
| 25 | - for (let l = 0; l < 1000; l++) { | ||
| 26 | - list.pop(); | ||
| 27 | - } | ||
| 28 | - } | ||
| 29 | - }, 1000); | ||
| 30 | - } | ||
| 16 | + common.expectWarning('ExperimentalWarning', | ||
| 17 | + 'report is an experimental feature. This feature could ' + | ||
| 18 | + 'change at any time'); | ||
| 19 | + tmpdir.refresh(); | ||
| 20 | + process.report.directory = tmpdir.path; | ||
| 31 | 21 | ||
| 32 | - function MyRecord() { | ||
| 33 | - this.name = 'foo'; | ||
| 34 | - this.id = 128; | ||
| 35 | - this.account = 98454324; | ||
| 36 | - } | ||
| 37 | - process.send('child started', busyLoop); | ||
| 22 | + assert.strictEqual(process.listenerCount('SIGUSR2'), 1); | ||
| 23 | + process.kill(process.pid, 'SIGUSR2'); | ||
| 38 | 24 | ||
| 25 | + // Asynchronously wait for the report. In development, a single setImmediate() | ||
| 26 | + // appears to be enough. Use an async loop to be a bit more robust in case | ||
| 27 | + // platform or machine differences throw off the timing. | ||
| 28 | + (function validate() { | ||
| 29 | + const reports = helper.findReports(process.pid, tmpdir.path); | ||
| 39 | 30 | ||
| 40 | - } else { | ||
| 41 | - const helper = require('../common/report.js'); | ||
| 42 | - const fork = require('child_process').fork; | ||
| 43 | - const tmpdir = require('../common/tmpdir'); | ||
| 44 | - tmpdir.refresh(); | ||
| 45 | - const assert = require('assert'); | ||
| 46 | - if (common.isWindows) { | ||
| 47 | - assert.fail('Unsupported on Windows', { skip: true }); | ||
| 48 | - return; | ||
| 49 | - } | ||
| 50 | - console.log(tmpdir.path); | ||
| 51 | - const options = { stdio: 'pipe', encoding: 'utf8', cwd: tmpdir.path }; | ||
| 52 | - const child = fork('--experimental-report', | ||
| 53 | - ['--diagnostic-report-on-signal', __filename, 'child'], | ||
| 54 | - options); | ||
| 55 | - // Wait for child to indicate it is ready before sending signal | ||
| 56 | - child.on('message', () => child.kill('SIGUSR2')); | ||
| 57 | - let stderr = ''; | ||
| 58 | - child.stderr.on('data', (chunk) => { | ||
| 59 | - stderr += chunk; | ||
| 60 | - // Terminate the child after the report has been written | ||
| 61 | - if (stderr.includes('Node.js report completed')) { | ||
| 62 | - child.kill('SIGTERM'); | ||
| 63 | - } | ||
| 64 | - }); | ||
| 65 | - child.on('exit', common.mustCall((code, signal) => { | ||
| 66 | - console.log('child exited'); | ||
| 67 | - console.log(stderr); | ||
| 68 | - const report_msg = 'No reports found'; | ||
| 69 | - const process_msg = 'Process exited unexpectedly'; | ||
| 70 | - const signal_msg = 'Process exited with unexpected signal'; | ||
| 71 | - assert.strictEqual(code, null, process_msg + ':' + code); | ||
| 72 | - assert.deepStrictEqual(signal, 'SIGTERM', | ||
| 73 | - signal_msg + ':' + signal); | ||
| 74 | - const reports = helper.findReports(child.pid, tmpdir.path); | ||
| 75 | - assert.deepStrictEqual(reports.length, 1, report_msg); | ||
| 76 | - const report = reports[0]; | ||
| 77 | - helper.validate(report); | ||
| 78 | - })); | ||
| 79 | - } | ||
| 31 | + if (reports.length === 0) | ||
| 32 | + return setImmediate(validate); | ||
| 33 | + | ||
| 34 | + assert.strictEqual(reports.length, 1); | ||
| 35 | + helper.validate(reports[0]); | ||
| 36 | + })(); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments