• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Flags: --report-on-signal
2'use strict';
3// Test producing a report via signal.
4const common = require('../common');
5
6if (common.isWindows)
7  return common.skip('Unsupported on Windows.');
8
9if (!common.isMainThread)
10  common.skip('Signal reporting is only supported in the main thread');
11
12const assert = require('assert');
13const helper = require('../common/report');
14const tmpdir = require('../common/tmpdir');
15
16tmpdir.refresh();
17process.report.directory = tmpdir.path;
18
19assert.strictEqual(process.listenerCount('SIGUSR2'), 1);
20process.kill(process.pid, 'SIGUSR2');
21
22// Asynchronously wait for the report. In development, a single setImmediate()
23// appears to be enough. Use an async loop to be a bit more robust in case
24// platform or machine differences throw off the timing.
25(function validate() {
26  const reports = helper.findReports(process.pid, tmpdir.path);
27
28  if (reports.length === 0)
29    return setImmediate(validate);
30
31  assert.strictEqual(reports.length, 1);
32  helper.validate(reports[0]);
33})();
34