Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(node): enable more child_process testing #3185

Merged
merged 7 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions node/_tools/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
NOTE: This file should not be manually edited. Please edit `config.json` and run
`deno task node:setup` instead.

Total: 2810
Total: 2793

- [abort/test-abort-backtrace.js](https://github.com/nodejs/node/tree/v18.12.1/test/abort/test-abort-backtrace.js)
- [abort/test-abort-fatal-error.js](https://github.com/nodejs/node/tree/v18.12.1/test/abort/test-abort-fatal-error.js)
Expand Down Expand Up @@ -266,21 +266,12 @@ Total: 2810
- [parallel/test-child-process-advanced-serialization-largebuffer.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-advanced-serialization-largebuffer.js)
- [parallel/test-child-process-advanced-serialization.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-advanced-serialization.js)
- [parallel/test-child-process-bad-stdio.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-bad-stdio.js)
- [parallel/test-child-process-can-write-to-stdout.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-can-write-to-stdout.js)
- [parallel/test-child-process-constructor.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-constructor.js)
- [parallel/test-child-process-cwd.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-cwd.js)
- [parallel/test-child-process-default-options.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-default-options.js)
- [parallel/test-child-process-detached.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-detached.js)
- [parallel/test-child-process-disconnect.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-disconnect.js)
- [parallel/test-child-process-double-pipe.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-double-pipe.js)
- [parallel/test-child-process-env.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-env.js)
- [parallel/test-child-process-exec-any-shells-windows.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-exec-any-shells-windows.js)
- [parallel/test-child-process-exec-timeout-expire.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-exec-timeout-expire.js)
- [parallel/test-child-process-exec-timeout-kill.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-exec-timeout-kill.js)
- [parallel/test-child-process-exec-timeout-not-expired.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-exec-timeout-not-expired.js)
- [parallel/test-child-process-execfile-maxbuf.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-execfile-maxbuf.js)
- [parallel/test-child-process-exit-code.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-exit-code.js)
- [parallel/test-child-process-flush-stdio.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-flush-stdio.js)
- [parallel/test-child-process-fork-abort-signal.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-fork-abort-signal.js)
- [parallel/test-child-process-fork-and-spawn.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-fork-and-spawn.js)
- [parallel/test-child-process-fork-args.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-fork-args.js)
Expand All @@ -305,7 +296,6 @@ Total: 2810
- [parallel/test-child-process-http-socket-leak.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-http-socket-leak.js)
- [parallel/test-child-process-internal.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-internal.js)
- [parallel/test-child-process-ipc-next-tick.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-ipc-next-tick.js)
- [parallel/test-child-process-ipc.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-ipc.js)
- [parallel/test-child-process-no-deprecation.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-no-deprecation.js)
- [parallel/test-child-process-pipe-dataflow.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-pipe-dataflow.js)
- [parallel/test-child-process-promisified.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-promisified.js)
Expand All @@ -317,13 +307,10 @@ Total: 2810
- [parallel/test-child-process-send-type-error.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-send-type-error.js)
- [parallel/test-child-process-send-utf8.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-send-utf8.js)
- [parallel/test-child-process-server-close.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-server-close.js)
- [parallel/test-child-process-set-blocking.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-set-blocking.js)
- [parallel/test-child-process-silent.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-silent.js)
- [parallel/test-child-process-spawn-args.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-spawn-args.js)
- [parallel/test-child-process-spawn-argv0.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-spawn-argv0.js)
- [parallel/test-child-process-spawn-controller.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-spawn-controller.js)
- [parallel/test-child-process-spawn-error.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-spawn-error.js)
- [parallel/test-child-process-spawn-event.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-spawn-event.js)
- [parallel/test-child-process-spawn-shell.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-spawn-shell.js)
- [parallel/test-child-process-spawn-timeout-kill-signal.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-spawn-timeout-kill-signal.js)
- [parallel/test-child-process-spawn-typeerror.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-spawn-typeerror.js)
Expand All @@ -334,13 +321,10 @@ Total: 2810
- [parallel/test-child-process-stdin-ipc.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-stdin-ipc.js)
- [parallel/test-child-process-stdin.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-stdin.js)
- [parallel/test-child-process-stdio-big-write-end.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-stdio-big-write-end.js)
- [parallel/test-child-process-stdio-inherit.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-stdio-inherit.js)
- [parallel/test-child-process-stdio-merge-stdouts-into-cat.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-stdio-merge-stdouts-into-cat.js)
- [parallel/test-child-process-stdio-overlapped.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-stdio-overlapped.js)
- [parallel/test-child-process-stdio-reuse-readable-stdio.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-stdio-reuse-readable-stdio.js)
- [parallel/test-child-process-stdio.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-stdio.js)
- [parallel/test-child-process-stdout-flush-exit.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-stdout-flush-exit.js)
- [parallel/test-child-process-stdout-flush.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-stdout-flush.js)
- [parallel/test-child-process-stdout-ipc.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-stdout-ipc.js)
- [parallel/test-child-process-uid-gid.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-uid-gid.js)
- [parallel/test-child-process-validate-stdio.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-validate-stdio.js)
Expand Down Expand Up @@ -2670,7 +2654,6 @@ Total: 2810
- [sequential/test-buffer-creation-regression.js](https://github.com/nodejs/node/tree/v18.12.1/test/sequential/test-buffer-creation-regression.js)
- [sequential/test-child-process-emfile.js](https://github.com/nodejs/node/tree/v18.12.1/test/sequential/test-child-process-emfile.js)
- [sequential/test-child-process-execsync.js](https://github.com/nodejs/node/tree/v18.12.1/test/sequential/test-child-process-execsync.js)
- [sequential/test-child-process-exit.js](https://github.com/nodejs/node/tree/v18.12.1/test/sequential/test-child-process-exit.js)
- [sequential/test-child-process-pass-fd.js](https://github.com/nodejs/node/tree/v18.12.1/test/sequential/test-child-process-pass-fd.js)
- [sequential/test-cli-syntax-bad.js](https://github.com/nodejs/node/tree/v18.12.1/test/sequential/test-cli-syntax-bad.js)
- [sequential/test-cli-syntax-file-not-found.js](https://github.com/nodejs/node/tree/v18.12.1/test/sequential/test-cli-syntax-file-not-found.js)
Expand Down
39 changes: 38 additions & 1 deletion node/_tools/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
"common": ["index.js", "internet.js", "tmpdir.js"],
"fixtures": [
"child-process-spawn-node.js",
"echo.js",
"elipses.txt",
"empty.txt",
"exit.js",
"print-chars.js",
"x.txt"
],
"internet": [
Expand All @@ -27,9 +30,18 @@
"test-child-process-exec-kill-throws.js",
"test-child-process-exec-maxbuf.js",
"test-child-process-exec-std-encoding.js",
"test-child-process-exec-timeout-expire.js",
"test-child-process-exec-timeout-kill.js",
"test-child-process-exec-timeout-not-expired.js",
"test-child-process-execFile-promisified-abortController.js",
"test-child-process-execfile.js",
"test-child-process-execsync-maxbuf.js",
"test-child-process-exit-code.js",
"test-child-process-ipc.js",
"test-child-process-spawnsync-env.js",
"test-child-process-stdio-inherit.js",
"test-child-process-stdout-flush-exit.js",
"test-child-process-stdout-flush.js",
"test-console-instance.js",
"test-crypto-hmac.js",
"test-dgram-custom-lookup.js",
Expand Down Expand Up @@ -91,10 +103,14 @@
"pummel": [
"test-net-bytes-per-incoming-chunk-overhead.js",
"test-net-write-callbacks.js"
],
"sequential": [
"test-child-process-exit.js"
]
},
"tests": {
"common": [
"child_process.js",
"countdown.js",
"dns.js",
"duplexpair.js",
Expand All @@ -104,13 +120,16 @@
"internet.js"
],
"fixtures": [
"GH-1899-output.js",
"a.js",
"child-process-spawn-node.js",
"child_process_should_emit_error.js",
"echo.js",
"elipses.txt",
"empty.txt",
"exit.js",
"loop.js",
"print-chars.js",
"x.txt"
],
"fixtures/keys": [
Expand Down Expand Up @@ -183,6 +202,9 @@
"test-buffer-zero-fill-cli.js",
"test-buffer-zero-fill-reset.js",
"test-buffer-zero-fill.js",
"test-child-process-can-write-to-stdout.js",
"test-child-process-default-options.js",
"test-child-process-double-pipe.js",
"test-child-process-exec-abortcontroller-promisified.js",
"test-child-process-exec-cwd.js",
"test-child-process-exec-encoding.js",
Expand All @@ -192,16 +214,29 @@
"test-child-process-exec-maxbuf.js",
"test-child-process-exec-std-encoding.js",
"test-child-process-exec-stdout-stderr-data-string.js",
"test-child-process-exec-timeout-expire.js",
"test-child-process-exec-timeout-kill.js",
"test-child-process-exec-timeout-not-expired.js",
"test-child-process-execFile-promisified-abortController.js",
"test-child-process-execfile-maxbuf.js",
"test-child-process-execfile.js",
"test-child-process-execfilesync-maxbuf.js",
"test-child-process-execsync-maxbuf.js",
"test-child-process-exit-code.js",
"test-child-process-flush-stdio.js",
"test-child-process-ipc.js",
"test-child-process-kill.js",
"test-child-process-set-blocking.js",
"test-child-process-spawn-args.js",
"test-child-process-spawn-event.js",
"test-child-process-spawnsync-args.js",
"test-child-process-spawnsync-env.js",
"test-child-process-spawnsync-maxbuf.js",
"test-child-process-spawnsync-validation-errors.js",
"test-child-process-spawnsync.js",
"test-child-process-stdio-inherit.js",
"test-child-process-stdout-flush-exit.js",
"test-child-process-stdout-flush.js",
"test-client-request-destroy.js",
"test-console-async-write-error.js",
"test-console-group.js",
Expand Down Expand Up @@ -768,7 +803,9 @@
"test-net-pingpong-delay.js",
"test-net-write-callbacks.js"
],
"sequential": []
"sequential": [
"test-child-process-exit.js"
]
},
"windowsIgnore": {
"parallel": [
Expand Down
56 changes: 56 additions & 0 deletions node/_tools/test/common/child_process.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file

// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually

'use strict';

const assert = require('assert');
const common = require('./');

// Workaround for Windows Server 2008R2
// When CMD is used to launch a process and CMD is killed too quickly, the
// process can stay behind running in suspended state, never completing.
function cleanupStaleProcess(filename) {
if (!common.isWindows) {
return;
}
process.once('beforeExit', () => {
const basename = filename.replace(/.*[/\\]/g, '');
try {
require('child_process')
.execFileSync(`${process.env.SystemRoot}\\System32\\wbem\\WMIC.exe`, [
'process',
'where',
`commandline like '%${basename}%child'`,
'delete',
'/nointeractive',
]);
} catch {
// Ignore failures, there might not be any stale process to clean up.
}
});
}

// This should keep the child process running long enough to expire
// the timeout.
const kExpiringChildRunTime = common.platformTimeout(20 * 1000);
const kExpiringParentTimer = 1;
assert(kExpiringChildRunTime > kExpiringParentTimer);

function logAfterTime(time) {
setTimeout(() => {
// The following console statements are part of the test.
console.log('child stdout');
console.error('child stderr');
}, time);
}

module.exports = {
cleanupStaleProcess,
logAfterTime,
kExpiringChildRunTime,
kExpiringParentTimer
};
30 changes: 30 additions & 0 deletions node/_tools/test/fixtures/GH-1899-output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file

// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually

// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

console.log('hello, world!');

36 changes: 36 additions & 0 deletions node/_tools/test/fixtures/child_process_should_emit_error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file

// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually

// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

const exec = require('child_process').exec;

[0, 1].forEach(function(i) {
exec('ls', function(err, stdout, stderr) {
console.log(i);
throw new Error('hello world');
});
});
5 changes: 4 additions & 1 deletion node/_tools/test/fixtures/echo.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ const assert = require('assert');

process.stdout.write('hello world\r\n');

var stdin = process.openStdin();
// TODO(PolarETech): process.openStdin() is not yet implemented.
// Use process.stdin instead.
var stdin = process.stdin;
// var stdin = process.openStdin();

stdin.on('data', function(data) {
process.stdout.write(data.toString());
Expand Down
4 changes: 3 additions & 1 deletion node/_tools/test/fixtures/exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

process.exit(process.argv[2] || 1);
// TODO(PolarETech): The process.argv[3] should be argv[2].

process.exit(process.argv[3] || 1);
35 changes: 35 additions & 0 deletions node/_tools/test/fixtures/print-chars.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file

// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually

// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

// TODO(PolarETech): The process.argv[3] should be argv[2].

const assert = require('assert');

var n = parseInt(process.argv[3]);

process.stdout.write('c'.repeat(n));
Loading