From de0dcc59c4db0bbea04859d56e249a5e8e42390d Mon Sep 17 00:00:00 2001 From: Refael Ackermann Date: Wed, 17 Apr 2019 10:04:01 -0400 Subject: [PATCH 1/3] test: try to stabalize test-child-process-fork-exec-path.js --- test/parallel/test-child-process-fork-exec-path.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/parallel/test-child-process-fork-exec-path.js b/test/parallel/test-child-process-fork-exec-path.js index cabd8893475630..25e8c56014c04b 100644 --- a/test/parallel/test-child-process-fork-exec-path.js +++ b/test/parallel/test-child-process-fork-exec-path.js @@ -59,7 +59,6 @@ if (process.env.FORK) { assert.deepStrictEqual(msg, recv); })); child.on('exit', common.mustCall(function(code) { - fs.unlinkSync(copyPath); assert.strictEqual(code, 0); })); } From 907567e135bd08eb511d537553d869bdb74c87fe Mon Sep 17 00:00:00 2001 From: Refael Ackermann Date: Wed, 17 Apr 2019 15:47:33 -0400 Subject: [PATCH 2/3] sqaush! normalize --- .../test-child-process-fork-exec-path.js | 58 +++++++++---------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/test/parallel/test-child-process-fork-exec-path.js b/test/parallel/test-child-process-fork-exec-path.js index 25e8c56014c04b..6b276b85fccf68 100644 --- a/test/parallel/test-child-process-fork-exec-path.js +++ b/test/parallel/test-child-process-fork-exec-path.js @@ -21,44 +21,42 @@ '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) { - 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'); + +// slow but simple +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); +})); From f07570765e6aac02816d94b54cb8b784207a60b8 Mon Sep 17 00:00:00 2001 From: Refael Ackermann Date: Wed, 17 Apr 2019 20:47:12 -0400 Subject: [PATCH 3/3] Squash! remove old comment --- test/parallel/test-child-process-fork-exec-path.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/parallel/test-child-process-fork-exec-path.js b/test/parallel/test-child-process-fork-exec-path.js index 6b276b85fccf68..6a99c5a8f55d62 100644 --- a/test/parallel/test-child-process-fork-exec-path.js +++ b/test/parallel/test-child-process-fork-exec-path.js @@ -51,7 +51,6 @@ assert.strictEqual(fs.existsSync(copyPath), false); fs.copyFileSync(nodePath, copyPath, fs.constants.COPYFILE_FICLONE); fs.chmodSync(copyPath, '0755'); -// slow but simple const envCopy = Object.assign({}, process.env, { 'FORK': 'true' }); const child = fork(__filename, { execPath: copyPath, env: envCopy }); child.on('message', common.mustCall(function(recv) {