diff options
author | cjihrig <cjihrig@gmail.com> | 2019-03-03 12:05:38 -0500 |
---|---|---|
committer | cjihrig <cjihrig@gmail.com> | 2019-03-05 15:35:58 -0500 |
commit | 30ee27784c935dd174238edecbd93edb4aab8972 (patch) | |
tree | 3f098f45a3d7e226268f45b64954657221bcb8ff /test/report | |
parent | c78788a0219cc950be7159e65b9e8db01e9c1a7a (diff) | |
download | android-node-v8-30ee27784c935dd174238edecbd93edb4aab8972.tar.gz android-node-v8-30ee27784c935dd174238edecbd93edb4aab8972.tar.bz2 android-node-v8-30ee27784c935dd174238edecbd93edb4aab8972.zip |
report: refactor configuration management
This commit removes process.report.setOptions(). Instead of
using complex configuration synchronization between C++ and
JS, this commit introduces individual getters and setters.
PR-URL: https://github.com/nodejs/node/pull/26414
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Wyatt Preul <wpreul@gmail.com>
Diffstat (limited to 'test/report')
-rw-r--r-- | test/report/test-report-config.js | 87 | ||||
-rw-r--r-- | test/report/test-report-signal.js | 1 | ||||
-rw-r--r-- | test/report/test-report-triggerreport.js | 8 | ||||
-rw-r--r-- | test/report/test-report-uncaught-exception.js | 2 |
4 files changed, 93 insertions, 5 deletions
diff --git a/test/report/test-report-config.js b/test/report/test-report-config.js new file mode 100644 index 0000000000..796f63d2b8 --- /dev/null +++ b/test/report/test-report-config.js @@ -0,0 +1,87 @@ +// Flags: --experimental-report --diagnostic-report-on-fatalerror --diagnostic-report-on-signal --diagnostic-report-uncaught-exception +'use strict'; +const common = require('../common'); +common.skipIfReportDisabled(); +const assert = require('assert'); + +common.expectWarning('ExperimentalWarning', + 'report is an experimental feature. This feature could ' + + 'change at any time'); + +// Verify that process.report.directory behaves properly. +assert.strictEqual(process.report.directory, ''); +process.report.directory = __dirname; +assert.strictEqual(process.report.directory, __dirname); +common.expectsError(() => { + process.report.directory = {}; +}, { code: 'ERR_INVALID_ARG_TYPE' }); +assert.strictEqual(process.report.directory, __dirname); + +// Verify that process.report.filename behaves properly. +assert.strictEqual(process.report.filename, ''); +process.report.filename = 'test-report.json'; +assert.strictEqual(process.report.filename, 'test-report.json'); +common.expectsError(() => { + process.report.filename = {}; +}, { code: 'ERR_INVALID_ARG_TYPE' }); +assert.strictEqual(process.report.filename, 'test-report.json'); + +// Verify that process.report.reportOnFatalError behaves properly. +assert.strictEqual(process.report.reportOnFatalError, true); +process.report.reportOnFatalError = false; +assert.strictEqual(process.report.reportOnFatalError, false); +process.report.reportOnFatalError = true; +assert.strictEqual(process.report.reportOnFatalError, true); +common.expectsError(() => { + process.report.reportOnFatalError = {}; +}, { code: 'ERR_INVALID_ARG_TYPE' }); +assert.strictEqual(process.report.reportOnFatalError, true); + + +// Verify that process.report.reportOnUncaughtException behaves properly. +assert.strictEqual(process.report.reportOnUncaughtException, true); +process.report.reportOnUncaughtException = false; +assert.strictEqual(process.report.reportOnUncaughtException, false); +process.report.reportOnUncaughtException = true; +assert.strictEqual(process.report.reportOnUncaughtException, true); +common.expectsError(() => { + process.report.reportOnUncaughtException = {}; +}, { code: 'ERR_INVALID_ARG_TYPE' }); +assert.strictEqual(process.report.reportOnUncaughtException, true); + +// Verify that process.report.reportOnSignal behaves properly. +assert.strictEqual(process.report.reportOnSignal, true); +process.report.reportOnSignal = false; +assert.strictEqual(process.report.reportOnSignal, false); +process.report.reportOnSignal = true; +assert.strictEqual(process.report.reportOnSignal, true); +common.expectsError(() => { + process.report.reportOnSignal = {}; +}, { code: 'ERR_INVALID_ARG_TYPE' }); +assert.strictEqual(process.report.reportOnSignal, true); + +if (!common.isWindows) { + // Verify that process.report.signal behaves properly. + assert.strictEqual(process.report.signal, 'SIGUSR2'); + common.expectsError(() => { + process.report.signal = {}; + }, { code: 'ERR_INVALID_ARG_TYPE' }); + common.expectsError(() => { + process.report.signal = 'foo'; + }, { code: 'ERR_UNKNOWN_SIGNAL' }); + assert.strictEqual(process.report.signal, 'SIGUSR2'); + process.report.signal = 'SIGUSR1'; + assert.strictEqual(process.report.signal, 'SIGUSR1'); + + // Verify that the interaction between reportOnSignal and signal is correct. + process.report.signal = 'SIGUSR2'; + process.report.reportOnSignal = false; + assert.strictEqual(process.listenerCount('SIGUSR2'), 0); + process.report.reportOnSignal = true; + assert.strictEqual(process.listenerCount('SIGUSR2'), 1); + process.report.signal = 'SIGUSR1'; + assert.strictEqual(process.listenerCount('SIGUSR2'), 0); + assert.strictEqual(process.listenerCount('SIGUSR1'), 1); + process.report.reportOnSignal = false; + assert.strictEqual(process.listenerCount('SIGUSR1'), 0); +} diff --git a/test/report/test-report-signal.js b/test/report/test-report-signal.js index 129933b546..68f5c25402 100644 --- a/test/report/test-report-signal.js +++ b/test/report/test-report-signal.js @@ -64,6 +64,7 @@ if (process.argv[2] === 'child') { }); 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'; diff --git a/test/report/test-report-triggerreport.js b/test/report/test-report-triggerreport.js index 4ac8f1a9a5..c9ad8cdee0 100644 --- a/test/report/test-report-triggerreport.js +++ b/test/report/test-report-triggerreport.js @@ -14,7 +14,7 @@ common.expectWarning('ExperimentalWarning', 'report is an experimental feature. This feature could ' + 'change at any time'); tmpdir.refresh(); -process.report.setOptions({ path: tmpdir.path }); +process.report.directory = tmpdir.path; function validate() { const reports = helper.findReports(process.pid, tmpdir.path); @@ -59,11 +59,11 @@ function validate() { { // Test with a filename option. - const filename = path.join(tmpdir.path, 'custom-name-3.json'); - process.report.setOptions({ filename }); + process.report.filename = 'custom-name-3.json'; const file = process.report.triggerReport(); assert.strictEqual(helper.findReports(process.pid, tmpdir.path).length, 0); - assert.strictEqual(file, filename); + const filename = path.join(process.report.directory, 'custom-name-3.json'); + assert.strictEqual(file, process.report.filename); helper.validate(filename); fs.unlinkSync(filename); } diff --git a/test/report/test-report-uncaught-exception.js b/test/report/test-report-uncaught-exception.js index b3da7c4244..34e4759ea2 100644 --- a/test/report/test-report-uncaught-exception.js +++ b/test/report/test-report-uncaught-exception.js @@ -12,7 +12,7 @@ common.expectWarning('ExperimentalWarning', 'report is an experimental feature. This feature could ' + 'change at any time'); tmpdir.refresh(); -process.report.setOptions({ path: tmpdir.path }); +process.report.directory = tmpdir.path; process.on('uncaughtException', common.mustCall((err) => { assert.strictEqual(err, error); |