Browse Source

test: scope redeclared vars in test-child-process*

A handful of child process tests had variables declared multiple times
in the same scope using `var`. This change scopes those declarations.

PR-URL: https://github.com/nodejs/node/pull/4944
Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
process-exit-stdio-flushing
Rich Trott 9 years ago
parent
commit
185f8497e5
  1. 5
      test/parallel/test-child-process-default-options.js
  2. 5
      test/parallel/test-child-process-env.js
  3. 5
      test/parallel/test-child-process-fork-dgram.js
  4. 8
      test/parallel/test-child-process-silent.js
  5. 2
      test/parallel/test-child-process-stdio-big-write-end.js
  6. 44
      test/parallel/test-child-process-validate-stdio.js

5
test/parallel/test-child-process-default-options.js

@ -6,10 +6,11 @@ var spawn = require('child_process').spawn;
process.env.HELLO = 'WORLD'; process.env.HELLO = 'WORLD';
var child;
if (common.isWindows) { if (common.isWindows) {
var child = spawn('cmd.exe', ['/c', 'set'], {}); child = spawn('cmd.exe', ['/c', 'set'], {});
} else { } else {
var child = spawn('/usr/bin/env', [], {}); child = spawn('/usr/bin/env', [], {});
} }
var response = ''; var response = '';

5
test/parallel/test-child-process-env.js

@ -11,10 +11,11 @@ env.__proto__ = {
'FOO': 'BAR' 'FOO': 'BAR'
}; };
var child;
if (common.isWindows) { if (common.isWindows) {
var child = spawn('cmd.exe', ['/c', 'set'], {env: env}); child = spawn('cmd.exe', ['/c', 'set'], {env: env});
} else { } else {
var child = spawn('/usr/bin/env', [], {env: env}); child = spawn('/usr/bin/env', [], {env: env});
} }

5
test/parallel/test-child-process-fork-dgram.js

@ -24,9 +24,8 @@ if (common.isWindows) {
return; return;
} }
var server;
if (process.argv[2] === 'child') { if (process.argv[2] === 'child') {
var server;
process.on('message', function removeMe(msg, clusterServer) { process.on('message', function removeMe(msg, clusterServer) {
if (msg === 'server') { if (msg === 'server') {
server = clusterServer; server = clusterServer;
@ -42,7 +41,7 @@ if (process.argv[2] === 'child') {
}); });
} else { } else {
var server = dgram.createSocket('udp4'); server = dgram.createSocket('udp4');
var client = dgram.createSocket('udp4'); var client = dgram.createSocket('udp4');
var child = fork(__filename, ['child']); var child = fork(__filename, ['child']);

8
test/parallel/test-child-process-silent.js

@ -4,11 +4,11 @@ var assert = require('assert');
var childProcess = require('child_process'); var childProcess = require('child_process');
// Child pipe test // Child pipe test
if (process.argv[2] === 'pipetest') { if (process.argv[2] === 'pipe') {
process.stdout.write('stdout message'); process.stdout.write('stdout message');
process.stderr.write('stderr message'); process.stderr.write('stderr message');
} else if (process.argv[2] === 'ipctest') { } else if (process.argv[2] === 'ipc') {
// Child IPC test // Child IPC test
process.send('message from child'); process.send('message from child');
process.on('message', function() { process.on('message', function() {
@ -18,7 +18,7 @@ if (process.argv[2] === 'pipetest') {
} else if (process.argv[2] === 'parent') { } else if (process.argv[2] === 'parent') {
// Parent | start child pipe test // 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 // Allow child process to self terminate
child._channel.close(); child._channel.close();
@ -46,7 +46,7 @@ if (process.argv[2] === 'pipetest') {
}); });
// testing: do message system work when using silent // 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 // Manual pipe so we will get errors
child.stderr.pipe(process.stderr, {end: false}); child.stderr.pipe(process.stderr, {end: false});

2
test/parallel/test-child-process-stdio-big-write-end.js

@ -36,7 +36,7 @@ function parent() {
// then write a bunch more times. // then write a bunch more times.
for (var i = 0; i < 100; i++) { for (var i = 0; i < 100; i++) {
var buf = new Buffer(BUFSIZE); const buf = new Buffer(BUFSIZE);
buf.fill('.'); buf.fill('.');
sent += BUFSIZE; sent += BUFSIZE;
child.stdin.write(buf); child.stdin.write(buf);

44
test/parallel/test-child-process-validate-stdio.js

@ -2,8 +2,8 @@
// Flags: --expose_internals // Flags: --expose_internals
require('../common'); require('../common');
var assert = require('assert'); const assert = require('assert');
var _validateStdio = require('internal/child_process')._validateStdio; const _validateStdio = require('internal/child_process')._validateStdio;
// should throw if string and not ignore, pipe, or inherit // should throw if string and not ignore, pipe, or inherit
assert.throws(function() { assert.throws(function() {
@ -16,27 +16,31 @@ assert.throws(function() {
}, /Incorrect value of stdio option/); }, /Incorrect value of stdio option/);
// should populate stdio with undefined if len < 3 // should populate stdio with undefined if len < 3
var stdio1 = []; {
var result = _validateStdio(stdio1, false); const stdio1 = [];
assert.equal(stdio1.length, 3); const result = _validateStdio(stdio1, false);
assert.equal(result.hasOwnProperty('stdio'), true); assert.equal(stdio1.length, 3);
assert.equal(result.hasOwnProperty('ipc'), true); assert.equal(result.hasOwnProperty('stdio'), true);
assert.equal(result.hasOwnProperty('ipcFd'), true); assert.equal(result.hasOwnProperty('ipc'), true);
assert.equal(result.hasOwnProperty('ipcFd'), true);
}
// should throw if stdio has ipc and sync is true // should throw if stdio has ipc and sync is true
var stdio2 = ['ipc', 'ipc', 'ipc']; const stdio2 = ['ipc', 'ipc', 'ipc'];
assert.throws(function() { assert.throws(function() {
_validateStdio(stdio2, true); _validateStdio(stdio2, true);
}, /You cannot use IPC with synchronous forks/); }, /You cannot use IPC with synchronous forks/);
const stdio3 = [process.stdin, process.stdout, process.stderr]; {
var result = _validateStdio(stdio3, false); const stdio3 = [process.stdin, process.stdout, process.stderr];
assert.deepStrictEqual(result, { const result = _validateStdio(stdio3, false);
stdio: [ assert.deepStrictEqual(result, {
{ type: 'fd', fd: 0 }, stdio: [
{ type: 'fd', fd: 1 }, { type: 'fd', fd: 0 },
{ type: 'fd', fd: 2 } { type: 'fd', fd: 1 },
], { type: 'fd', fd: 2 }
ipc: undefined, ],
ipcFd: undefined ipc: undefined,
}); ipcFd: undefined
});
}

Loading…
Cancel
Save