forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: fix --diagnostic-dir not working with --heapsnapshot-signal
Fixes: nodejs#47842
- Loading branch information
1 parent
6a5394e
commit 884855a
Showing
2 changed files
with
57 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const tmpdir = require('../common/tmpdir'); | ||
|
||
if (common.isWindows) | ||
common.skip('test not supported on Windows'); | ||
|
||
const assert = require('assert'); | ||
|
||
if (process.argv[2] === 'child') { | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
assert.strictEqual(process.listenerCount('SIGUSR2'), 1); | ||
process.kill(process.pid, 'SIGUSR2'); | ||
process.kill(process.pid, 'SIGUSR2'); | ||
|
||
// Asynchronously wait for the snapshot. Use an async loop to be a bit more | ||
// robust in case platform or machine differences throw off the timing. | ||
(function validate() { | ||
const files = fs.readdirSync(tmpdir.path); | ||
|
||
if (files.length === 0) | ||
return setImmediate(validate); | ||
|
||
assert.strictEqual(files.length, 2); | ||
|
||
for (let i = 0; i < files.length; i++) { | ||
assert.match(files[i], /^Heap\..+\.heapsnapshot$/); | ||
JSON.parse(fs.readFileSync(path.join(tmpdir.path, files[i]))); | ||
} | ||
})(); | ||
} else { | ||
const { spawnSync } = require('child_process'); | ||
|
||
tmpdir.refresh(); | ||
const args = [ | ||
'--heapsnapshot-signal', | ||
'SIGUSR2', | ||
'--diagnostic-dir', | ||
tmpdir.path, | ||
__filename, | ||
'child', | ||
]; | ||
const child = spawnSync(process.execPath, args); | ||
|
||
assert.strictEqual(child.status, 0); | ||
assert.strictEqual(child.signal, null); | ||
} |