node/test/parallel/test-tick-processor-arguments.js
kohta ito eb8a51a35c child_process: use non-infinite maxBuffer defaults
Set the default maxBuffer size to 204,800 bytes for execSync,
execFileSync, and spawnSync.

APIs that return the child output as a string should have non-infinite
defaults for maxBuffer sizes to avoid out-of-memory error conditions. A
non-infinite default used to be the documented behaviour for all
relevant APIs, but the implemented behaviour for execSync, execFileSync
and spawnSync was to have no maxBuffer limits.

PR-URL: https://github.com/nodejs/node/pull/23027
Refs: https://github.com/nodejs/node/pull/22894
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2019-04-09 13:57:04 -07:00

33 lines
1.0 KiB
JavaScript

'use strict';
const common = require('../common');
const tmpdir = require('../common/tmpdir');
const fs = require('fs');
const assert = require('assert');
const { spawnSync } = require('child_process');
if (!common.enoughTestMem)
common.skip('skipped due to memory requirements');
if (common.isAIX)
common.skip('does not work on AIX');
tmpdir.refresh();
// Generate log file.
spawnSync(process.execPath, [ '--prof', '-p', '42' ], { cwd: tmpdir.path });
const files = fs.readdirSync(tmpdir.path);
const logfile = files.filter((name) => /\.log$/.test(name))[0];
assert(logfile);
// Make sure that the --preprocess argument is passed through correctly,
// as an example flag listed in deps/v8/tools/tickprocessor.js.
// Any of the other flags there should work for this test too, if --preprocess
// is ever removed.
const { stdout } = spawnSync(
process.execPath,
[ '--prof-process', '--preprocess', logfile ],
{ cwd: tmpdir.path, encoding: 'utf8', maxBuffer: Infinity });
// Make sure that the result is valid JSON.
JSON.parse(stdout);