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