diff options
author | Refael Ackermann <refack@gmail.com> | 2019-04-17 17:04:01 +0300 |
---|---|---|
committer | Beth Griggs <Bethany.Griggs@uk.ibm.com> | 2020-02-20 19:07:15 +0300 |
commit | 2315270cb6bd54858fce2e669e23f34f5ddc2308 (patch) | |
tree | bbf32089bdff7cfc297ec28b3899541751c9a2e0 /test | |
parent | 7eac95981e099796037acae24db8db3899c125bd (diff) |
test: try to stabalize test-child-process-fork-exec-path.js
PR-URL: https://github.com/nodejs/node/pull/27277
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-child-process-fork-exec-path.js | 58 |
1 files changed, 27 insertions, 31 deletions
diff --git a/test/parallel/test-child-process-fork-exec-path.js b/test/parallel/test-child-process-fork-exec-path.js index cabd8893475..6a99c5a8f55 100644 --- a/test/parallel/test-child-process-fork-exec-path.js +++ b/test/parallel/test-child-process-fork-exec-path.js @@ -21,45 +21,41 @@ 'use strict'; const common = require('../common'); + +// Test that `fork()` respects the `execPath` option. + +const tmpdir = require('../common/tmpdir'); +const { addLibraryPath } = require('../common/shared-lib-util'); const assert = require('assert'); -const fs = require('fs'); -const { COPYFILE_FICLONE } = fs.constants; const path = require('path'); -const tmpdir = require('../common/tmpdir'); +const fs = require('fs'); +const { fork } = require('child_process'); + const msg = { test: 'this' }; const nodePath = process.execPath; const copyPath = path.join(tmpdir.path, 'node-copy.exe'); -const { addLibraryPath } = require('../common/shared-lib-util'); addLibraryPath(process.env); +// Child if (process.env.FORK) { - assert(process.send); - assert.strictEqual(process.argv[0], copyPath); + assert.strictEqual(process.execPath, copyPath); + assert.ok(process.send); process.send(msg); - process.exit(); -} else { - tmpdir.refresh(); - try { - fs.unlinkSync(copyPath); - } catch (e) { - if (e.code !== 'ENOENT') throw e; - } - fs.copyFileSync(nodePath, copyPath, COPYFILE_FICLONE); - fs.chmodSync(copyPath, '0755'); - - // slow but simple - const envCopy = JSON.parse(JSON.stringify(process.env)); - envCopy.FORK = 'true'; - const child = require('child_process').fork(__filename, { - execPath: copyPath, - env: envCopy - }); - child.on('message', common.mustCall(function(recv) { - assert.deepStrictEqual(msg, recv); - })); - child.on('exit', common.mustCall(function(code) { - fs.unlinkSync(copyPath); - assert.strictEqual(code, 0); - })); + return process.exit(); } + +// Parent +tmpdir.refresh(); +assert.strictEqual(fs.existsSync(copyPath), false); +fs.copyFileSync(nodePath, copyPath, fs.constants.COPYFILE_FICLONE); +fs.chmodSync(copyPath, '0755'); + +const envCopy = Object.assign({}, process.env, { 'FORK': 'true' }); +const child = fork(__filename, { execPath: copyPath, env: envCopy }); +child.on('message', common.mustCall(function(recv) { + assert.deepStrictEqual(recv, msg); +})); +child.on('exit', common.mustCall(function(code) { + assert.strictEqual(code, 0); +})); |