diff options
author | Refael Ackermann <refack@gmail.com> | 2017-06-04 14:25:44 -0400 |
---|---|---|
committer | Refael Ackermann <refack@gmail.com> | 2017-06-07 16:27:00 -0400 |
commit | 8d2bd5fa88c9ebb9b1416d819b4a29b01c712424 (patch) | |
tree | 18ecc50dda566c367ea36bc55c0d10a7648769f1 /benchmark/child_process | |
parent | 47b9772f52aba7693eed4df535b35de65ac22c49 (diff) | |
download | android-node-v8-8d2bd5fa88c9ebb9b1416d819b4a29b01c712424.tar.gz android-node-v8-8d2bd5fa88c9ebb9b1416d819b4a29b01c712424.tar.bz2 android-node-v8-8d2bd5fa88c9ebb9b1416d819b4a29b01c712424.zip |
test,benchmark: stabilize child-process
also some cleanup
PR-URL: https://github.com/nodejs/node/pull/13457
Refs: https://github.com/nodejs/node/issues/12817
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Diffstat (limited to 'benchmark/child_process')
-rw-r--r-- | benchmark/child_process/child-process-exec-stdout.js | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/benchmark/child_process/child-process-exec-stdout.js b/benchmark/child_process/child-process-exec-stdout.js index a30eb92f6a..dcd352cfcf 100644 --- a/benchmark/child_process/child-process-exec-stdout.js +++ b/benchmark/child_process/child-process-exec-stdout.js @@ -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 { + 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); } |