Skip to content

Commit

Permalink
test: preserve env in test cases
Browse files Browse the repository at this point in the history
Allows env vars to be passed through to child processes. This is needed
for things like NODE_TEST_DIR or LD_LIBRARY_PATH if testing the shared
library.

PR-URL: #14822
Refs: #13390
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
BethGriggs authored and MylesBorins committed Sep 11, 2017
1 parent 02020ef commit ff1b64a
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 15 deletions.
4 changes: 3 additions & 1 deletion test/parallel/test-benchmark-crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ const argv = ['--set', 'algo=sha256',
'--set', 'writes=1',
'crypto'];

const child = fork(runjs, argv, {env: {NODEJS_BENCHMARK_ZERO_ALLOWED: 1}});
const env = Object.assign({}, process.env,
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });
const child = fork(runjs, argv, { env });
child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
Expand Down
5 changes: 4 additions & 1 deletion test/parallel/test-benchmark-timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ const argv = ['--set', 'type=depth',
'--set', 'thousands=0.001',
'timers'];

const child = fork(runjs, argv, {env: {NODEJS_BENCHMARK_ZERO_ALLOWED: 1}});
const env = Object.assign({}, process.env,
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });

const child = fork(runjs, argv, { env });
child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-env-var-no-warnings.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const cp = require('child_process');
if (process.argv[2] === 'child') {
process.emitWarning('foo');
} else {
function test(env) {
function test(newEnv) {
const env = Object.assign({}, process.env, newEnv);
const cmd = `"${process.execPath}" "${__filename}" child`;

cp.exec(cmd, { env }, common.mustCall((err, stdout, stderr) => {
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-tls-env-bad-extra-ca.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ if (process.env.CHILD) {
return tls.createServer({});
}

const env = {
const env = Object.assign({}, process.env, {
CHILD: 'yes',
NODE_EXTRA_CA_CERTS: `${common.fixturesDir}/no-such-file-exists`,
};
});

const opts = {
env: env,
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-tls-env-extra-ca.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ const server = tls.createServer(options, common.mustCall(function(s) {
s.end('bye');
server.close();
})).listen(0, common.mustCall(function() {
const env = {
const env = Object.assign({}, process.env, {
CHILD: 'yes',
PORT: this.address().port,
NODE_EXTRA_CA_CERTS: fixtures.path('keys', 'ca1-cert.pem')
};
});

fork(__filename, {env: env}).on('exit', common.mustCall(function(status) {
assert.strictEqual(status, 0, 'client did not succeed in connecting');
Expand Down
23 changes: 16 additions & 7 deletions test/sequential/test-benchmark-child-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,22 @@ const path = require('path');

const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js');

const child = fork(runjs, ['--set', 'dur=0',
'--set', 'n=1',
'--set', 'len=1',
'--set', 'params=1',
'--set', 'methodName=execSync',
'child_process'],
{env: {NODEJS_BENCHMARK_ZERO_ALLOWED: 1}});
const env = Object.assign({}, process.env,
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });

const child = fork(
runjs,
[
'--set', 'dur=0',
'--set', 'n=1',
'--set', 'len=1',
'--set', 'params=1',
'--set', 'methodName=execSync',
'child_process'
],
{ env }
);

child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
Expand Down
4 changes: 3 additions & 1 deletion test/sequential/test-benchmark-net.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ const path = require('path');

const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js');

const env = Object.assign({}, process.env,
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });
const child = fork(runjs,
['--set', 'dur=0',
'--set', 'len=1024',
'--set', 'type=buf',
'net'],
{env: {NODEJS_BENCHMARK_ZERO_ALLOWED: 1}});
{ env });
child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
Expand Down

0 comments on commit ff1b64a

Please sign in to comment.