Skip to content

Commit 710f650

Browse files
Fishrock123MylesBorins
authored andcommitted
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: #24951 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent de26866 commit 710f650

File tree

1 file changed

+35
-12
lines changed

1 file changed

+35
-12
lines changed

‎test/parallel/test-child-process-exec-maxBuffer.js‎

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ const common = require('../common');
33
constassert=require('assert');
44
constcp=require('child_process');
55

6-
functioncheckFactory(streamName){
7-
returncommon.mustCall((err)=>{
8-
assert.strictEqual(err.message,`${streamName} maxBuffer length exceeded`);
9-
assert(errinstanceofRangeError);
10-
assert.strictEqual(err.code,'ERR_CHILD_PROCESS_STDIO_MAXBUFFER');
11-
});
6+
functionrunChecks(err,stdio,streamName,expected){
7+
assert.strictEqual(err.message,`${streamName} maxBuffer length exceeded`);
8+
assert(errinstanceofRangeError);
9+
assert.strictEqual(err.code,'ERR_CHILD_PROCESS_STDIO_MAXBUFFER');
10+
assert.deepStrictEqual(stdio[streamName],expected);
1211
}
1312

1413
{
@@ -25,21 +24,39 @@ function checkFactory(streamName){
2524
{
2625
constcmd='echo "hello world"';
2726

28-
cp.exec(cmd,{maxBuffer: 5},checkFactory('stdout'));
27+
cp.exec(
28+
cmd,
29+
{maxBuffer: 5},
30+
common.mustCall((err,stdout,stderr)=>{
31+
runChecks(err,{ stdout, stderr },'stdout','');
32+
})
33+
);
2934
}
3035

3136
constunicode='中文测试';// length = 4, byte length = 12
3237

3338
{
3439
constcmd=`"${process.execPath}" -e "console.log('${unicode}');"`;
3540

36-
cp.exec(cmd,{maxBuffer: 10},checkFactory('stdout'));
41+
cp.exec(
42+
cmd,
43+
{maxBuffer: 10},
44+
common.mustCall((err,stdout,stderr)=>{
45+
runChecks(err,{ stdout, stderr },'stdout','');
46+
})
47+
);
3748
}
3849

3950
{
4051
constcmd=`"${process.execPath}" -e "console.error('${unicode}');"`;
4152

42-
cp.exec(cmd,{maxBuffer: 10},checkFactory('stderr'));
53+
cp.exec(
54+
cmd,
55+
{maxBuffer: 3},
56+
common.mustCall((err,stdout,stderr)=>{
57+
runChecks(err,{ stdout, stderr },'stderr','');
58+
})
59+
);
4360
}
4461

4562
{
@@ -48,7 +65,10 @@ const unicode = '中文测试' // length = 4, byte length = 12
4865
constchild=cp.exec(
4966
cmd,
5067
{encoding: null,maxBuffer: 10},
51-
checkFactory('stdout'));
68+
common.mustCall((err,stdout,stderr)=>{
69+
runChecks(err,{ stdout, stderr },'stdout','');
70+
})
71+
);
5272

5373
child.stdout.setEncoding('utf-8');
5474
}
@@ -58,8 +78,11 @@ const unicode = '中文测试' // length = 4, byte length = 12
5878

5979
constchild=cp.exec(
6080
cmd,
61-
{encoding: null,maxBuffer: 10},
62-
checkFactory('stderr'));
81+
{encoding: null,maxBuffer: 3},
82+
common.mustCall((err,stdout,stderr)=>{
83+
runChecks(err,{ stdout, stderr },'stderr','');
84+
})
85+
);
6386

6487
child.stderr.setEncoding('utf-8');
6588
}

0 commit comments

Comments
(0)