2019-04-19 17:12:28 +02:00
|
|
|
// Flags: --experimental-report --report-on-signal
|
2018-09-05 16:39:08 +02:00
|
|
|
'use strict';
|
2019-03-05 03:04:31 +01:00
|
|
|
// Test producing a report via signal.
|
2018-09-05 16:39:08 +02:00
|
|
|
const common = require('../common');
|
|
|
|
common.skipIfReportDisabled();
|
2019-03-05 03:04:31 +01:00
|
|
|
if (common.isWindows)
|
|
|
|
return common.skip('Unsupported on Windows.');
|
2018-09-05 16:39:08 +02:00
|
|
|
|
2019-03-05 03:04:31 +01:00
|
|
|
if (!common.isMainThread)
|
|
|
|
common.skip('Signal reporting is only supported in the main thread');
|
2018-09-05 16:39:08 +02:00
|
|
|
|
2019-03-05 03:04:31 +01:00
|
|
|
const assert = require('assert');
|
|
|
|
const helper = require('../common/report');
|
|
|
|
const tmpdir = require('../common/tmpdir');
|
2018-09-05 16:39:08 +02:00
|
|
|
|
2019-03-05 03:04:31 +01:00
|
|
|
common.expectWarning('ExperimentalWarning',
|
|
|
|
'report is an experimental feature. This feature could ' +
|
|
|
|
'change at any time');
|
|
|
|
tmpdir.refresh();
|
|
|
|
process.report.directory = tmpdir.path;
|
2018-09-05 16:39:08 +02:00
|
|
|
|
2019-03-05 03:04:31 +01:00
|
|
|
assert.strictEqual(process.listenerCount('SIGUSR2'), 1);
|
|
|
|
process.kill(process.pid, 'SIGUSR2');
|
2018-09-05 16:39:08 +02:00
|
|
|
|
2019-03-05 03:04:31 +01:00
|
|
|
// 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);
|
2018-09-05 16:39:08 +02:00
|
|
|
|
2019-03-05 03:04:31 +01:00
|
|
|
if (reports.length === 0)
|
|
|
|
return setImmediate(validate);
|
|
|
|
|
|
|
|
assert.strictEqual(reports.length, 1);
|
|
|
|
helper.validate(reports[0]);
|
|
|
|
})();
|