Skip to content

Commit 4f8b497

Browse files
refackdanbev
authored andcommitted
test: try to stabalize test-child-process-fork-exec-path.js
PR-URL: #27277 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
1 parent 002dacb commit 4f8b497

File tree

1 file changed

+27
-31
lines changed

1 file changed

+27
-31
lines changed

‎test/parallel/test-child-process-fork-exec-path.js‎

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,45 +21,41 @@
2121

2222
'use strict';
2323
constcommon=require('../common');
24+
25+
// Test that `fork()` respects the `execPath` option.
26+
27+
consttmpdir=require('../common/tmpdir');
28+
const{ addLibraryPath }=require('../common/shared-lib-util');
2429
constassert=require('assert');
25-
constfs=require('fs');
26-
const{COPYFILE_FICLONE}=fs.constants;
2730
constpath=require('path');
28-
consttmpdir=require('../common/tmpdir');
31+
constfs=require('fs');
32+
const{ fork }=require('child_process');
33+
2934
constmsg={test: 'this'};
3035
constnodePath=process.execPath;
3136
constcopyPath=path.join(tmpdir.path,'node-copy.exe');
32-
const{ addLibraryPath }=require('../common/shared-lib-util');
3337

3438
addLibraryPath(process.env);
3539

40+
// Child
3641
if(process.env.FORK){
37-
assert(process.send);
38-
assert.strictEqual(process.argv[0],copyPath);
42+
assert.strictEqual(process.execPath,copyPath);
43+
assert.ok(process.send);
3944
process.send(msg);
40-
process.exit();
41-
}else{
42-
tmpdir.refresh();
43-
try{
44-
fs.unlinkSync(copyPath);
45-
}catch(e){
46-
if(e.code!=='ENOENT')throwe;
47-
}
48-
fs.copyFileSync(nodePath,copyPath,COPYFILE_FICLONE);
49-
fs.chmodSync(copyPath,'0755');
50-
51-
// slow but simple
52-
constenvCopy=JSON.parse(JSON.stringify(process.env));
53-
envCopy.FORK='true';
54-
constchild=require('child_process').fork(__filename,{
55-
execPath: copyPath,
56-
env: envCopy
57-
});
58-
child.on('message',common.mustCall(function(recv){
59-
assert.deepStrictEqual(msg,recv);
60-
}));
61-
child.on('exit',common.mustCall(function(code){
62-
fs.unlinkSync(copyPath);
63-
assert.strictEqual(code,0);
64-
}));
45+
returnprocess.exit();
6546
}
47+
48+
// Parent
49+
tmpdir.refresh();
50+
assert.strictEqual(fs.existsSync(copyPath),false);
51+
fs.copyFileSync(nodePath,copyPath,fs.constants.COPYFILE_FICLONE);
52+
fs.chmodSync(copyPath,'0755');
53+
54+
constenvCopy=Object.assign({},process.env,{'FORK': 'true'});
55+
constchild=fork(__filename,{execPath: copyPath,env: envCopy});
56+
child.on('message',common.mustCall(function(recv){
57+
assert.deepStrictEqual(recv,msg);
58+
}));
59+
child.on('exit',common.mustCall(function(code){
60+
assert.strictEqual(code,0);
61+
}));

0 commit comments

Comments
(0)