|
| 1 | +'use strict'; |
| 2 | +const common = require('../common'); |
| 3 | +const tmpdir = require('../common/tmpdir'); |
| 4 | + |
| 5 | +if (common.isWindows) |
| 6 | + common.skip('test not supported on Windows'); |
| 7 | + |
| 8 | +const assert = require('assert'); |
| 9 | + |
| 10 | +if (process.argv[2] === 'child') { |
| 11 | + const fs = require('fs'); |
| 12 | + const path = require('path'); |
| 13 | + |
| 14 | + assert.strictEqual(process.listenerCount('SIGUSR2'), 1); |
| 15 | + process.kill(process.pid, 'SIGUSR2'); |
| 16 | + process.kill(process.pid, 'SIGUSR2'); |
| 17 | + |
| 18 | + // Asynchronously wait for the snapshot. Use an async loop to be a bit more |
| 19 | + // robust in case platform or machine differences throw off the timing. |
| 20 | + (function validate() { |
| 21 | + const files = fs.readdirSync(tmpdir.path); |
| 22 | + |
| 23 | + if (files.length === 0) |
| 24 | + return setImmediate(validate); |
| 25 | + |
| 26 | + assert.strictEqual(files.length, 2); |
| 27 | + |
| 28 | + for (let i = 0; i < files.length; i++) { |
| 29 | + assert.match(files[i], /^Heap\..+\.heapsnapshot$/); |
| 30 | + JSON.parse(fs.readFileSync(path.join(tmpdir.path, files[i]))); |
| 31 | + } |
| 32 | + })(); |
| 33 | +} else { |
| 34 | + const { spawnSync } = require('child_process'); |
| 35 | + |
| 36 | + tmpdir.refresh(); |
| 37 | + const args = [ |
| 38 | + '--heapsnapshot-signal', |
| 39 | + 'SIGUSR2', |
| 40 | + '--diagnostic-dir', |
| 41 | + tmpdir.path, |
| 42 | + __filename, |
| 43 | + 'child', |
| 44 | + ]; |
| 45 | + const child = spawnSync(process.execPath, args); |
| 46 | + |
| 47 | + assert.strictEqual(child.status, 0); |
| 48 | + assert.strictEqual(child.signal, null); |
| 49 | +} |
0 commit comments