Skip to content

Commit

Permalink
test: scope redeclared vars in test-child-process*
Browse files Browse the repository at this point in the history
A handful of child process tests had variables declared multiple times
in the same scope using `var`. This change scopes those declarations.

PR-URL: #4944
Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
  • Loading branch information
Trott authored and Myles Borins committed Feb 18, 2016
1 parent 7654c17 commit c6b4bf1
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 32 deletions.
5 changes: 3 additions & 2 deletions test/parallel/test-child-process-default-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ var spawn = require('child_process').spawn;

process.env.HELLO = 'WORLD';

var child;
if (common.isWindows) {
var child = spawn('cmd.exe', ['/c', 'set'], {});
child = spawn('cmd.exe', ['/c', 'set'], {});
} else {
var child = spawn('/usr/bin/env', [], {});
child = spawn('/usr/bin/env', [], {});
}

var response = '';
Expand Down
5 changes: 3 additions & 2 deletions test/parallel/test-child-process-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ env.__proto__ = {
'FOO': 'BAR'
};

var child;
if (common.isWindows) {
var child = spawn('cmd.exe', ['/c', 'set'], {env: env});
child = spawn('cmd.exe', ['/c', 'set'], {env: env});
} else {
var child = spawn('/usr/bin/env', [], {env: env});
child = spawn('/usr/bin/env', [], {env: env});
}


Expand Down
5 changes: 2 additions & 3 deletions test/parallel/test-child-process-fork-dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ if (common.isWindows) {
return;
}

var server;
if (process.argv[2] === 'child') {
var server;

process.on('message', function removeMe(msg, clusterServer) {
if (msg === 'server') {
server = clusterServer;
Expand All @@ -42,7 +41,7 @@ if (process.argv[2] === 'child') {
});

} else {
var server = dgram.createSocket('udp4');
server = dgram.createSocket('udp4');
var client = dgram.createSocket('udp4');
var child = fork(__filename, ['child']);

Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-child-process-silent.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ var assert = require('assert');
var childProcess = require('child_process');

// Child pipe test
if (process.argv[2] === 'pipetest') {
if (process.argv[2] === 'pipe') {
process.stdout.write('stdout message');
process.stderr.write('stderr message');

} else if (process.argv[2] === 'ipctest') {
} else if (process.argv[2] === 'ipc') {
// Child IPC test
process.send('message from child');
process.on('message', function() {
Expand All @@ -18,7 +18,7 @@ if (process.argv[2] === 'pipetest') {
} else if (process.argv[2] === 'parent') {
// Parent | start child pipe test

var child = childProcess.fork(process.argv[1], ['pipetest'], {silent: true});
const child = childProcess.fork(process.argv[1], ['pipe'], {silent: true});

// Allow child process to self terminate
child._channel.close();
Expand Down Expand Up @@ -46,7 +46,7 @@ if (process.argv[2] === 'pipetest') {
});

// testing: do message system work when using silent
var child = childProcess.fork(process.argv[1], ['ipctest'], {silent: true});
const child = childProcess.fork(process.argv[1], ['ipc'], {silent: true});

// Manual pipe so we will get errors
child.stderr.pipe(process.stderr, {end: false});
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-child-process-stdio-big-write-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function parent() {

// then write a bunch more times.
for (var i = 0; i < 100; i++) {
var buf = new Buffer(BUFSIZE);
const buf = new Buffer(BUFSIZE);
buf.fill('.');
sent += BUFSIZE;
child.stdin.write(buf);
Expand Down
44 changes: 24 additions & 20 deletions test/parallel/test-child-process-validate-stdio.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Flags: --expose_internals

require('../common');
var assert = require('assert');
var _validateStdio = require('internal/child_process')._validateStdio;
const assert = require('assert');
const _validateStdio = require('internal/child_process')._validateStdio;

// should throw if string and not ignore, pipe, or inherit
assert.throws(function() {
Expand All @@ -16,27 +16,31 @@ assert.throws(function() {
}, /Incorrect value of stdio option/);

// should populate stdio with undefined if len < 3
var stdio1 = [];
var result = _validateStdio(stdio1, false);
assert.equal(stdio1.length, 3);
assert.equal(result.hasOwnProperty('stdio'), true);
assert.equal(result.hasOwnProperty('ipc'), true);
assert.equal(result.hasOwnProperty('ipcFd'), true);
{
const stdio1 = [];
const result = _validateStdio(stdio1, false);
assert.equal(stdio1.length, 3);
assert.equal(result.hasOwnProperty('stdio'), true);
assert.equal(result.hasOwnProperty('ipc'), true);
assert.equal(result.hasOwnProperty('ipcFd'), true);
}

// should throw if stdio has ipc and sync is true
var stdio2 = ['ipc', 'ipc', 'ipc'];
const stdio2 = ['ipc', 'ipc', 'ipc'];
assert.throws(function() {
_validateStdio(stdio2, true);
}, /You cannot use IPC with synchronous forks/);

const stdio3 = [process.stdin, process.stdout, process.stderr];
var result = _validateStdio(stdio3, false);
assert.deepStrictEqual(result, {
stdio: [
{ type: 'fd', fd: 0 },
{ type: 'fd', fd: 1 },
{ type: 'fd', fd: 2 }
],
ipc: undefined,
ipcFd: undefined
});
{
const stdio3 = [process.stdin, process.stdout, process.stderr];
const result = _validateStdio(stdio3, false);
assert.deepStrictEqual(result, {
stdio: [
{ type: 'fd', fd: 0 },
{ type: 'fd', fd: 1 },
{ type: 'fd', fd: 2 }
],
ipc: undefined,
ipcFd: undefined
});
}

0 comments on commit c6b4bf1

Please sign in to comment.