Skip to content

Commit 96bb315

Browse files
TrottMyles Borins
authored andcommitted
test: ensure _handle property existence
`test-stdtout-close-unref.js` will fail if `process.stdin._handle` does not exist. On UNIX-like operating systems, you can see this failure this way: ./node test/parallel/test-stdout-close-unref.js < /dev/null This issue has been experienced by @bengl and @drewfish in a Docker container. I'm not sure why they are experiencing it in their environment, but since it is possible that the `_handle` property does not exist, let's use `child_process.spawn()` to make sure it exists. PR-URL: #5916 Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent 4f1fa2a commit 96bb315

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed
Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
'use strict';
2-
require('../common');
3-
varassert=require('assert');
2+
constcommon=require('../common');
3+
constassert=require('assert');
4+
constspawn=require('child_process').spawn;
45

5-
varerrs=0;
6+
if(process.argv[2]==='child'){
7+
varerrs=0;
68

7-
process.stdin.resume();
8-
process.stdin._handle.close();
9-
process.stdin._handle.unref();// Should not segfault.
10-
process.stdin.on('error',function(err){
11-
errs++;
12-
});
9+
process.stdin.resume();
10+
process.stdin._handle.close();
11+
process.stdin._handle.unref();// Should not segfault.
12+
process.stdin.on('error',function(err){
13+
errs++;
14+
});
1315

14-
process.on('exit',function(){
15-
assert.strictEqual(errs,1);
16-
});
16+
process.on('exit',function(){
17+
assert.strictEqual(errs,1);
18+
});
19+
return;
20+
}
21+
22+
// Use spawn so that we can be sure that stdin has a _handle property.
23+
// Refs: https://github.com/nodejs/node/pull/5916
24+
constproc=spawn(process.execPath,[__filename,'child'],{stdio: 'pipe'});
25+
26+
proc.stderr.pipe(process.stderr);
27+
proc.on('exit',common.mustCall(function(exitCode){
28+
if(exitCode!==0)
29+
process.exitCode=exitCode;
30+
}));

0 commit comments

Comments
(0)