From 710f650032f93dfcb2b6c5e14d539e82fb220094 Mon Sep 17 00:00:00 2001 From: Jeremiah Senkpiel Date: Mon, 10 Dec 2018 16:30:43 -0800 Subject: [PATCH] test: add stdio checks to cp-exec-maxBuffer Expands this test case to check what happens to stdout/stderr when maxBuffer is exceeded. Also changes how cases are checked so that assertion stacks are tracable to their test case, aka 'make it actually debuggable'. PR-URL: https://github.com/nodejs/node/pull/24951 Reviewed-By: Ruben Bridgewater Reviewed-By: Anna Henningsen --- .../test-child-process-exec-maxBuffer.js | 47 ++++++++++++++----- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/test/parallel/test-child-process-exec-maxBuffer.js b/test/parallel/test-child-process-exec-maxBuffer.js index 94545e719ba2d7..569efb5deba699 100644 --- a/test/parallel/test-child-process-exec-maxBuffer.js +++ b/test/parallel/test-child-process-exec-maxBuffer.js @@ -3,12 +3,11 @@ const common = require('../common'); const assert = require('assert'); const cp = require('child_process'); -function checkFactory(streamName) { - return common.mustCall((err) => { - assert.strictEqual(err.message, `${streamName} maxBuffer length exceeded`); - assert(err instanceof RangeError); - assert.strictEqual(err.code, 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER'); - }); +function runChecks(err, stdio, streamName, expected) { + assert.strictEqual(err.message, `${streamName} maxBuffer length exceeded`); + assert(err instanceof RangeError); + assert.strictEqual(err.code, 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER'); + assert.deepStrictEqual(stdio[streamName], expected); } { @@ -25,7 +24,13 @@ function checkFactory(streamName) { { const cmd = 'echo "hello world"'; - cp.exec(cmd, { maxBuffer: 5 }, checkFactory('stdout')); + cp.exec( + cmd, + { maxBuffer: 5 }, + common.mustCall((err, stdout, stderr) => { + runChecks(err, { stdout, stderr }, 'stdout', ''); + }) + ); } const unicode = '中文测试'; // length = 4, byte length = 12 @@ -33,13 +38,25 @@ const unicode = '中文测试'; // length = 4, byte length = 12 { const cmd = `"${process.execPath}" -e "console.log('${unicode}');"`; - cp.exec(cmd, { maxBuffer: 10 }, checkFactory('stdout')); + cp.exec( + cmd, + { maxBuffer: 10 }, + common.mustCall((err, stdout, stderr) => { + runChecks(err, { stdout, stderr }, 'stdout', ''); + }) + ); } { const cmd = `"${process.execPath}" -e "console.error('${unicode}');"`; - cp.exec(cmd, { maxBuffer: 10 }, checkFactory('stderr')); + cp.exec( + cmd, + { maxBuffer: 3 }, + common.mustCall((err, stdout, stderr) => { + runChecks(err, { stdout, stderr }, 'stderr', ''); + }) + ); } { @@ -48,7 +65,10 @@ const unicode = '中文测试'; // length = 4, byte length = 12 const child = cp.exec( cmd, { encoding: null, maxBuffer: 10 }, - checkFactory('stdout')); + common.mustCall((err, stdout, stderr) => { + runChecks(err, { stdout, stderr }, 'stdout', ''); + }) + ); child.stdout.setEncoding('utf-8'); } @@ -58,8 +78,11 @@ const unicode = '中文测试'; // length = 4, byte length = 12 const child = cp.exec( cmd, - { encoding: null, maxBuffer: 10 }, - checkFactory('stderr')); + { encoding: null, maxBuffer: 3 }, + common.mustCall((err, stdout, stderr) => { + runChecks(err, { stdout, stderr }, 'stderr', ''); + }) + ); child.stderr.setEncoding('utf-8'); }