mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00

There are several cleanups here that are not just style nits... 1. The `common.isMainThread` was just a passthrough to the `isMainThread` export on the worker_thread module. It's use was inconsistent and just obfuscated the fact that the test file depend on the `worker_threads` built-in. By eliminating it we simplify the test harness a bit and make it clearer which tests depend on the worker_threads check. 2. The `common.isDumbTerminal` is fairly unnecesary since that just wraps a public API check. 3. Several of the `common.skipIf....` checks were inconsistently used and really don't need to be separate utility functions. A key part of the motivation here is to work towards making more of the tests more self-contained and less reliant on the common test harness where possible. PR-URL: https://github.com/nodejs/node/pull/56712 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
37 lines
1 KiB
JavaScript
37 lines
1 KiB
JavaScript
// Flags: --report-on-signal
|
|
'use strict';
|
|
// Test producing a report via signal.
|
|
const common = require('../common');
|
|
|
|
if (common.isWindows) {
|
|
return common.skip('Unsupported on Windows.');
|
|
}
|
|
|
|
const { isMainThread } = require('worker_threads');
|
|
|
|
if (!isMainThread) {
|
|
common.skip('Signal reporting is only supported in the main thread');
|
|
}
|
|
|
|
const assert = require('assert');
|
|
const helper = require('../common/report');
|
|
const tmpdir = require('../common/tmpdir');
|
|
|
|
tmpdir.refresh();
|
|
process.report.directory = tmpdir.path;
|
|
|
|
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);
|
|
|
|
if (reports.length === 0)
|
|
return setImmediate(validate);
|
|
|
|
assert.strictEqual(reports.length, 1);
|
|
helper.validate(reports[0]);
|
|
})();
|