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,benchmark: stabilize child-process #13457

Merged
merged 1 commit into from
Jun 7, 2017
Merged
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
39 changes: 20 additions & 19 deletions benchmark/child_process/child-process-exec-stdout.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
'use strict';
const common = require('../common.js');
const { exec, execSync } = require('child_process');
const isWindows = process.platform === 'win32';

var messagesLength = [64, 256, 1024, 4096];
// Windows does not support that long arguments
if (process.platform !== 'win32')
messagesLength.push(32768);
const bench = common.createBenchmark(main, {
// Windows does not support command lines longer than 8191 characters
if (!isWindows) messagesLength.push(32768);

const bench = common.createBenchmark(childProcessExecStdout, {
len: messagesLength,
dur: [5]
});

const child_process = require('child_process');
const exec = child_process.exec;
function main(conf) {
function childProcessExecStdout(conf) {
bench.start();

const dur = +conf.dur;
const maxDuration = conf.dur * 1000;
const len = +conf.len;

const msg = `"${'.'.repeat(len)}"`;
// eslint-disable-next-line no-unescaped-regexp-dot
msg.match(/./);
const options = {'stdio': ['ignore', 'pipe', 'ignore']};
const child = exec(`yes ${msg}`, options);
const cmd = `yes "${'.'.repeat(len)}"`;
const child = exec(cmd, { 'stdio': ['ignore', 'pipe', 'ignore'] });

var bytes = 0;
child.stdout.on('data', function(msg) {
child.stdout.on('data', (msg) => {
bytes += msg.length;
});

setTimeout(function() {
setTimeout(() => {
bench.end(bytes);
if (process.platform === 'win32') {
// Sometimes there's a yes.exe process left hanging around on Windows...
child_process.execSync(`taskkill /f /t /pid ${child.pid}`);
if (isWindows) {
// Sometimes there's a yes.exe process left hanging around on Windows.
try {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This try should get rid of this error, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, just wrote #13457 (comment)

execSync(`taskkill /f /t /pid ${child.pid}`);
} catch (_) {
// this is a best effort kill. stderr is piped to parent for tracing.
}
} else {
child.kill();
}
}, dur * 1000);
}, maxDuration);
}