2018-09-17 09:19:26 +00:00
|
|
|
'use strict';
|
|
|
|
require('../common');
|
|
|
|
|
2019-06-09 13:11:56 +00:00
|
|
|
// This test checks that the maxBuffer option for child_process.execFileSync()
|
2018-09-17 09:19:26 +00:00
|
|
|
// works as expected.
|
|
|
|
|
|
|
|
const assert = require('assert');
|
2019-06-09 13:04:51 +00:00
|
|
|
const { getSystemErrorName } = require('util');
|
2019-06-09 13:11:56 +00:00
|
|
|
const { execFileSync } = require('child_process');
|
2018-09-17 09:19:26 +00:00
|
|
|
const msgOut = 'this is stdout';
|
|
|
|
const msgOutBuf = Buffer.from(`${msgOut}\n`);
|
|
|
|
|
|
|
|
const args = [
|
|
|
|
'-e',
|
2021-03-26 15:51:08 +00:00
|
|
|
`console.log("${msgOut}");`,
|
2018-09-17 09:19:26 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
// Verify that an error is returned if maxBuffer is surpassed.
|
|
|
|
{
|
2019-06-09 13:11:56 +00:00
|
|
|
assert.throws(() => {
|
|
|
|
execFileSync(process.execPath, args, { maxBuffer: 1 });
|
|
|
|
}, (e) => {
|
|
|
|
assert.ok(e, 'maxBuffer should error');
|
2019-06-09 13:04:51 +00:00
|
|
|
assert.strictEqual(e.code, 'ENOBUFS');
|
|
|
|
assert.strictEqual(getSystemErrorName(e.errno), 'ENOBUFS');
|
2019-06-09 13:11:56 +00:00
|
|
|
// We can have buffers larger than maxBuffer because underneath we alloc 64k
|
|
|
|
// that matches our read sizes.
|
|
|
|
assert.deepStrictEqual(e.stdout, msgOutBuf);
|
|
|
|
return true;
|
|
|
|
});
|
2018-09-17 09:19:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Verify that a maxBuffer size of Infinity works.
|
|
|
|
{
|
|
|
|
const ret = execFileSync(process.execPath, args, { maxBuffer: Infinity });
|
|
|
|
|
|
|
|
assert.deepStrictEqual(ret, msgOutBuf);
|
|
|
|
}
|
|
|
|
|
2019-06-09 13:11:56 +00:00
|
|
|
// Default maxBuffer size is 1024 * 1024.
|
2018-09-17 09:19:26 +00:00
|
|
|
{
|
2019-06-09 13:11:56 +00:00
|
|
|
assert.throws(() => {
|
|
|
|
execFileSync(
|
|
|
|
process.execPath,
|
|
|
|
['-e', "console.log('a'.repeat(1024 * 1024))"]
|
|
|
|
);
|
|
|
|
}, (e) => {
|
|
|
|
assert.ok(e, 'maxBuffer should error');
|
2019-06-09 13:04:51 +00:00
|
|
|
assert.strictEqual(e.code, 'ENOBUFS');
|
|
|
|
assert.strictEqual(getSystemErrorName(e.errno), 'ENOBUFS');
|
2019-06-09 13:11:56 +00:00
|
|
|
return true;
|
|
|
|
});
|
2018-09-17 09:19:26 +00:00
|
|
|
}
|