summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/worker-farm
diff options
context:
space:
mode:
authorKat Marchán <kzm@sykosomatic.org>2017-12-07 14:05:23 -0800
committerMyles Borins <mylesborins@google.com>2018-01-19 11:32:08 -0500
commitd3b1c971bcf0177b17c649c3aeca1a94cbc3fff5 (patch)
tree321928c015be00cdbe11715297d2d2fc45802263 /deps/npm/node_modules/worker-farm
parentbfe41fe88e7421f441067a79fb7512cf5935a2bb (diff)
downloadandroid-node-v8-d3b1c971bcf0177b17c649c3aeca1a94cbc3fff5.tar.gz
android-node-v8-d3b1c971bcf0177b17c649c3aeca1a94cbc3fff5.tar.bz2
android-node-v8-d3b1c971bcf0177b17c649c3aeca1a94cbc3fff5.zip
deps: upgrade npm to 5.6.0
PR-URL: https://github.com/nodejs/node/pull/17777 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Diffstat (limited to 'deps/npm/node_modules/worker-farm')
-rw-r--r--deps/npm/node_modules/worker-farm/.npmignore1
-rw-r--r--deps/npm/node_modules/worker-farm/lib/fork.js12
-rw-r--r--deps/npm/node_modules/worker-farm/package.json22
-rw-r--r--deps/npm/node_modules/worker-farm/tests/child.js85
-rw-r--r--deps/npm/node_modules/worker-farm/tests/debug.js11
-rw-r--r--deps/npm/node_modules/worker-farm/tests/index.js493
6 files changed, 16 insertions, 608 deletions
diff --git a/deps/npm/node_modules/worker-farm/.npmignore b/deps/npm/node_modules/worker-farm/.npmignore
deleted file mode 100644
index 3c3629e647..0000000000
--- a/deps/npm/node_modules/worker-farm/.npmignore
+++ /dev/null
@@ -1 +0,0 @@
-node_modules
diff --git a/deps/npm/node_modules/worker-farm/lib/fork.js b/deps/npm/node_modules/worker-farm/lib/fork.js
index cbd4011c73..46cf79b73e 100644
--- a/deps/npm/node_modules/worker-farm/lib/fork.js
+++ b/deps/npm/node_modules/worker-farm/lib/fork.js
@@ -15,17 +15,15 @@ function fork (forkModule) {
, cwd: process.cwd()
})
+ child.on('error', function() {
+ // this *should* be picked up by onExit and the operation requeued
+ })
+
child.send({ module: forkModule })
// return a send() function for this child
return {
- send : function (data) {
- try {
- child.send(data)
- } catch (e) {
- // this *should* be picked up by onExit and the operation requeued
- }
- }
+ send : child.send.bind(child)
, child : child
}
}
diff --git a/deps/npm/node_modules/worker-farm/package.json b/deps/npm/node_modules/worker-farm/package.json
index d3ff94a616..d60f581cff 100644
--- a/deps/npm/node_modules/worker-farm/package.json
+++ b/deps/npm/node_modules/worker-farm/package.json
@@ -1,28 +1,28 @@
{
- "_from": "worker-farm@1.5.0",
- "_id": "worker-farm@1.5.0",
+ "_from": "worker-farm@1.5.1",
+ "_id": "worker-farm@1.5.1",
"_inBundle": false,
- "_integrity": "sha512-DHRiUggxtbruaTwnLDm2/BRDKZIoOYvrgYUj5Bam4fU6Gtvc0FaEyoswFPBjMXAweGW2H4BDNIpy//1yXXuaqQ==",
+ "_integrity": "sha512-T5NH6Wqsd8MwGD4AK8BBllUy6LmHaqjEOyo/YIUEegZui6/v5Bqde//3jwyE3PGiGYMmWi06exFBi5LNhhPFNw==",
"_location": "/worker-farm",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
- "raw": "worker-farm@1.5.0",
+ "raw": "worker-farm@1.5.1",
"name": "worker-farm",
"escapedName": "worker-farm",
- "rawSpec": "1.5.0",
+ "rawSpec": "1.5.1",
"saveSpec": null,
- "fetchSpec": "1.5.0"
+ "fetchSpec": "1.5.1"
},
"_requiredBy": [
"#USER",
"/"
],
- "_resolved": "https://registry.npmjs.org/worker-farm/-/worker-farm-1.5.0.tgz",
- "_shasum": "adfdf0cd40581465ed0a1f648f9735722afd5c8d",
- "_spec": "worker-farm@1.5.0",
- "_where": "/Users/rebecca/code/npm",
+ "_resolved": "https://registry.npmjs.org/worker-farm/-/worker-farm-1.5.1.tgz",
+ "_shasum": "8e9f4a7da4f3c595aa600903051b969390423fa1",
+ "_spec": "worker-farm@1.5.1",
+ "_where": "/Users/zkat/Documents/code/npm",
"authors": [
"Rod Vagg @rvagg <rod@vagg.org> (https://github.com/rvagg)"
],
@@ -57,5 +57,5 @@
"test": "node ./tests/"
},
"types": "./index.d.ts",
- "version": "1.5.0"
+ "version": "1.5.1"
}
diff --git a/deps/npm/node_modules/worker-farm/tests/child.js b/deps/npm/node_modules/worker-farm/tests/child.js
deleted file mode 100644
index 0c0d68a846..0000000000
--- a/deps/npm/node_modules/worker-farm/tests/child.js
+++ /dev/null
@@ -1,85 +0,0 @@
-'use strict'
-
-const fs = require('fs')
-
-
-module.exports = function (timeout, callback) {
- callback = callback.bind(null, null, process.pid, Math.random(), timeout)
- if (timeout)
- return setTimeout(callback, timeout)
- callback()
-}
-
-
-module.exports.args = function (callback) {
- console.log(process.argv)
- console.log(process.execArgv)
- callback()
-}
-
-
-module.exports.run0 = function (callback) {
- module.exports(0, callback)
-}
-
-
-module.exports.killable = function (id, callback) {
- if (Math.random() < 0.5)
- return process.exit(-1)
- callback(null, id, process.pid)
-}
-
-
-module.exports.err = function (type, message, data, callback) {
- if (typeof data == 'function') {
- callback = data
- data = null
- } else {
- let err = new Error(message)
- Object.keys(data).forEach(function(key) {
- err[key] = data[key]
- })
- callback(err)
- return
- }
-
- if (type == 'TypeError')
- return callback(new TypeError(message))
- callback(new Error(message))
-}
-
-
-module.exports.block = function () {
- while (true);
-}
-
-
-// use provided file path to save retries count among terminated workers
-module.exports.stubborn = function (path, callback) {
- function isOutdated(path) {
- return ((new Date).getTime() - fs.statSync(path).mtime.getTime()) > 2000
- }
-
- // file may not be properly deleted, check if modified no earler than two seconds ago
- if (!fs.existsSync(path) || isOutdated(path)) {
- fs.writeFileSync(path, '1')
- process.exit(-1)
- }
-
- let retry = parseInt(fs.readFileSync(path, 'utf8'))
- if (Number.isNaN(retry))
- return callback(new Error('file contents is not a number'))
-
- if (retry > 4) {
- callback(null, 12)
- } else {
- fs.writeFileSync(path, String(retry + 1))
- process.exit(-1)
- }
-}
-
-
-let started = Date.now()
-module.exports.uptime = function(callback) {
- callback(null, Date.now() - started)
-}
diff --git a/deps/npm/node_modules/worker-farm/tests/debug.js b/deps/npm/node_modules/worker-farm/tests/debug.js
deleted file mode 100644
index 6ffd446489..0000000000
--- a/deps/npm/node_modules/worker-farm/tests/debug.js
+++ /dev/null
@@ -1,11 +0,0 @@
-'use strict'
-
-const workerFarm = require('../')
- , workers = workerFarm(require.resolve('./child'), ['args'])
-
-
-workers.args(function() {
- workerFarm.end(workers)
- console.log('FINISHED')
- process.exit(0)
-})
diff --git a/deps/npm/node_modules/worker-farm/tests/index.js b/deps/npm/node_modules/worker-farm/tests/index.js
deleted file mode 100644
index bc39c1081b..0000000000
--- a/deps/npm/node_modules/worker-farm/tests/index.js
+++ /dev/null
@@ -1,493 +0,0 @@
-'use strict'
-
-const tape = require('tape')
- , child_process = require('child_process')
- , workerFarm = require('../')
- , childPath = require.resolve('./child')
- , fs = require('fs')
-
-function uniq (ar) {
- let a = [], i, j
- o: for (i = 0; i < ar.length; ++i) {
- for (j = 0; j < a.length; ++j) if (a[j] == ar[i]) continue o
- a[a.length] = ar[i]
- }
- return a
-}
-
-
-// a child where module.exports = function ...
-tape('simple, exports=function test', function (t) {
- t.plan(4)
-
- let child = workerFarm(childPath)
- child(0, function (err, pid, rnd) {
- t.ok(pid > process.pid, 'pid makes sense')
- t.ok(pid < process.pid + 500, 'pid makes sense')
- t.ok(rnd >= 0 && rnd < 1, 'rnd result makes sense')
- })
-
- workerFarm.end(child, function () {
- t.ok(true, 'workerFarm ended')
- })
-})
-
-
-// a child where we have module.exports.fn = function ...
-tape('simple, exports.fn test', function (t) {
- t.plan(4)
-
- let child = workerFarm(childPath, [ 'run0' ])
- child.run0(function (err, pid, rnd) {
- t.ok(pid > process.pid, 'pid makes sense')
- t.ok(pid < process.pid + 500, 'pid makes sense')
- t.ok(rnd >= 0 && rnd < 1, 'rnd result makes sense')
- })
-
- workerFarm.end(child, function () {
- t.ok(true, 'workerFarm ended')
- })
-})
-
-
-// use the returned pids to check that we're using a single child process
-// when maxConcurrentWorkers = 1
-tape('single worker', function (t) {
- t.plan(2)
-
- let child = workerFarm({ maxConcurrentWorkers: 1 }, childPath)
- , pids = []
- , i = 10
-
- while (i--) {
- child(0, function (err, pid) {
- pids.push(pid)
- if (pids.length == 10) {
- t.equal(1, uniq(pids).length, 'only a single process (by pid)')
- } else if (pids.length > 10)
- t.fail('too many callbacks!')
- })
- }
-
- workerFarm.end(child, function () {
- t.ok(true, 'workerFarm ended')
- })
-})
-
-
-// use the returned pids to check that we're using two child processes
-// when maxConcurrentWorkers = 2
-tape('two workers', function (t) {
- t.plan(2)
-
- let child = workerFarm({ maxConcurrentWorkers: 2 }, childPath)
- , pids = []
- , i = 10
-
- while (i--) {
- child(0, function (err, pid) {
- pids.push(pid)
- if (pids.length == 10) {
- t.equal(2, uniq(pids).length, 'only two child processes (by pid)')
- } else if (pids.length > 10)
- t.fail('too many callbacks!')
- })
- }
-
- workerFarm.end(child, function () {
- t.ok(true, 'workerFarm ended')
- })
-})
-
-
-// use the returned pids to check that we're using a child process per
-// call when maxConcurrentWorkers = 10
-tape('many workers', function (t) {
- t.plan(2)
-
- let child = workerFarm({ maxConcurrentWorkers: 10 }, childPath)
- , pids = []
- , i = 10
-
- while (i--) {
- child(1, function (err, pid) {
- pids.push(pid)
- if (pids.length == 10) {
- t.equal(10, uniq(pids).length, 'pids are all the same (by pid)')
- } else if (pids.length > 10)
- t.fail('too many callbacks!')
- })
- }
-
- workerFarm.end(child, function () {
- t.ok(true, 'workerFarm ended')
- })
-})
-
-
-tape('auto start workers', function (t) {
- t.plan(4)
-
- let child = workerFarm({ maxConcurrentWorkers: 3, autoStart: true }, childPath, ['uptime'])
- , pids = []
- , i = 3
- , delay = 150
-
- setTimeout(function() {
- while (i--)
- child.uptime(function (err, uptime) {
- t.ok(uptime > 10, 'child has been up before the request')
- })
-
- workerFarm.end(child, function () {
- t.ok(true, 'workerFarm ended')
- })
- }, delay)
-})
-
-
-// use the returned pids to check that we're using a child process per
-// call when we set maxCallsPerWorker = 1 even when we have maxConcurrentWorkers = 1
-tape('single call per worker', function (t) {
- t.plan(2)
-
- let child = workerFarm({ maxConcurrentWorkers: 1, maxCallsPerWorker: 1 }, childPath)
- , pids = []
- , i = 10
-
- while (i--) {
- child(0, function (err, pid) {
- pids.push(pid)
- if (pids.length == 10) {
- t.equal(10, uniq(pids).length, 'one process for each call (by pid)')
- workerFarm.end(child, function () {
- t.ok(true, 'workerFarm ended')
- })
- } else if (pids.length > 10)
- t.fail('too many callbacks!')
- })
- }
-})
-
-
-// use the returned pids to check that we're using a child process per
-// two-calls when we set maxCallsPerWorker = 2 even when we have maxConcurrentWorkers = 1
-tape('two calls per worker', function (t) {
- t.plan(2)
-
- let child = workerFarm({ maxConcurrentWorkers: 1, maxCallsPerWorker: 2 }, childPath)
- , pids = []
- , i = 10
-
- while (i--) {
- child(0, function (err, pid) {
- pids.push(pid)
- if (pids.length == 10) {
- t.equal(5, uniq(pids).length, 'one process for each call (by pid)')
- workerFarm.end(child, function () {
- t.ok(true, 'workerFarm ended')
- })
- } else if (pids.length > 10)
- t.fail('too many callbacks!')
- })
- }
-})
-
-
-// use timing to confirm that one worker will process calls sequentially
-tape('many concurrent calls', function (t) {
- t.plan(2)
-
- let child = workerFarm({ maxConcurrentWorkers: 1 }, childPath)
- , i = 10
- , cbc = 0
- , start = Date.now()
-
- while (i--) {
- child(100, function () {
- if (++cbc == 10) {
- let time = Date.now() - start
- t.ok(time > 100 && time < 250, 'processed tasks concurrently (' + time + 'ms)')
- workerFarm.end(child, function () {
- t.ok(true, 'workerFarm ended')
- })
- } else if (cbc > 10)
- t.fail('too many callbacks!')
- })
- }
-})
-
-
-// use timing to confirm that one child processes calls sequentially with
-// maxConcurrentCallsPerWorker = 1
-tape('single concurrent call', function (t) {
- t.plan(2)
-
- let child = workerFarm(
- { maxConcurrentWorkers: 1, maxConcurrentCallsPerWorker: 1 }
- , childPath
- )
- , i = 10
- , cbc = 0
- , start = Date.now()
-
- while (i--) {
- child(20, function () {
- if (++cbc == 10) {
- let time = Date.now() - start
- t.ok(time > 200 && time < 400, 'processed tasks sequentially (' + time + 'ms)')
- workerFarm.end(child, function () {
- t.ok(true, 'workerFarm ended')
- })
- } else if (cbc > 10)
- t.fail('too many callbacks!')
- })
- }
-})
-
-
-// use timing to confirm that one child processes *only* 5 calls concurrently
-tape('multiple concurrent calls', function (t) {
- t.plan(2)
-
- let child = workerFarm({ maxConcurrentWorkers: 1, maxConcurrentCallsPerWorker: 5 }, childPath)
- , i = 10
- , cbc = 0
- , start = Date.now()
-
- while (i--) {
- child(100, function () {
- if (++cbc == 10) {
- let time = Date.now() - start
- t.ok(time > 200 && time < 350, 'processed tasks concurrently (' + time + 'ms)')
- workerFarm.end(child, function () {
- t.ok(true, 'workerFarm ended')
- })
- } else if (cbc > 10)
- t.fail('too many callbacks!')
- })
- }
-})
-
-
-// call a method that will die with a probability of 0.5 but expect that
-// we'll get results for each of our calls anyway
-tape('durability', function (t) {
- t.plan(3)
-
- let child = workerFarm({ maxConcurrentWorkers: 2 }, childPath, [ 'killable' ])
- , ids = []
- , pids = []
- , i = 10
-
- while (i--) {
- child.killable(i, function (err, id, pid) {
- ids.push(id)
- pids.push(pid)
- if (ids.length == 10) {
- t.ok(uniq(pids).length > 2, 'processed by many (' + uniq(pids).length + ') workers, but got there in the end!')
- t.ok(uniq(ids).length == 10, 'received a single result for each unique call')
- workerFarm.end(child, function () {
- t.ok(true, 'workerFarm ended')
- })
- } else if (ids.length > 10)
- t.fail('too many callbacks!')
- })
- }
-})
-
-
-// a callback provided to .end() can and will be called (uses "simple, exports=function test" to create a child)
-tape('simple, end callback', function (t) {
- t.plan(4)
-
- let child = workerFarm(childPath)
- child(0, function (err, pid, rnd) {
- t.ok(pid > process.pid, 'pid makes sense ' + pid + ' vs ' + process.pid)
- t.ok(pid < process.pid + 500, 'pid makes sense ' + pid + ' vs ' + process.pid)
- t.ok(rnd >= 0 && rnd < 1, 'rnd result makes sense')
- })
-
- workerFarm.end(child, function() {
- t.pass('an .end() callback was successfully called')
- })
-})
-
-
-tape('call timeout test', function (t) {
- t.plan(3 + 3 + 4 + 4 + 4 + 3 + 1)
-
- let child = workerFarm({ maxCallTime: 250, maxConcurrentWorkers: 1 }, childPath)
-
- // should come back ok
- child(50, function (err, pid, rnd) {
- t.ok(pid > process.pid, 'pid makes sense ' + pid + ' vs ' + process.pid)
- t.ok(pid < process.pid + 500, 'pid makes sense ' + pid + ' vs ' + process.pid)
- t.ok(rnd > 0 && rnd < 1, 'rnd result makes sense ' + rnd)
- })
-
- // should come back ok
- child(50, function (err, pid, rnd) {
- t.ok(pid > process.pid, 'pid makes sense ' + pid + ' vs ' + process.pid)
- t.ok(pid < process.pid + 500, 'pid makes sense ' + pid + ' vs ' + process.pid)
- t.ok(rnd > 0 && rnd < 1, 'rnd result makes sense ' + rnd)
- })
-
- // should die
- child(500, function (err, pid, rnd) {
- t.ok(err, 'got an error')
- t.equal(err.type, 'TimeoutError', 'correct error type')
- t.ok(pid === undefined, 'no pid')
- t.ok(rnd === undefined, 'no rnd')
- })
-
- // should die
- child(1000, function (err, pid, rnd) {
- t.ok(err, 'got an error')
- t.equal(err.type, 'TimeoutError', 'correct error type')
- t.ok(pid === undefined, 'no pid')
- t.ok(rnd === undefined, 'no rnd')
- })
-
- // should die even though it is only a 100ms task, it'll get caught up
- // in a dying worker
- setTimeout(function () {
- child(100, function (err, pid, rnd) {
- t.ok(err, 'got an error')
- t.equal(err.type, 'TimeoutError', 'correct error type')
- t.ok(pid === undefined, 'no pid')
- t.ok(rnd === undefined, 'no rnd')
- })
- }, 200)
-
- // should be ok, new worker
- setTimeout(function () {
- child(50, function (err, pid, rnd) {
- t.ok(pid > process.pid, 'pid makes sense ' + pid + ' vs ' + process.pid)
- t.ok(pid < process.pid + 500, 'pid makes sense ' + pid + ' vs ' + process.pid)
- t.ok(rnd > 0 && rnd < 1, 'rnd result makes sense ' + rnd)
- })
- workerFarm.end(child, function () {
- t.ok(true, 'workerFarm ended')
- })
- }, 400)
-})
-
-
-tape('test error passing', function (t) {
- t.plan(10)
-
- let child = workerFarm(childPath, [ 'err' ])
- child.err('Error', 'this is an Error', function (err) {
- t.ok(err instanceof Error, 'is an Error object')
- t.equal('Error', err.type, 'correct type')
- t.equal('this is an Error', err.message, 'correct message')
- })
- child.err('TypeError', 'this is a TypeError', function (err) {
- t.ok(err instanceof Error, 'is a TypeError object')
- t.equal('TypeError', err.type, 'correct type')
- t.equal('this is a TypeError', err.message, 'correct message')
- })
- child.err('Error', 'this is an Error with custom props', {foo: 'bar', 'baz': 1}, function (err) {
- t.ok(err instanceof Error, 'is an Error object')
- t.equal(err.foo, 'bar', 'passes data')
- t.equal(err.baz, 1, 'passes data')
- })
-
- workerFarm.end(child, function () {
- t.ok(true, 'workerFarm ended')
- })
-})
-
-
-tape('test maxConcurrentCalls', function (t) {
- t.plan(10)
-
- let child = workerFarm({ maxConcurrentCalls: 5 }, childPath)
-
- child(50, function (err) { t.notOk(err, 'no error') })
- child(50, function (err) { t.notOk(err, 'no error') })
- child(50, function (err) { t.notOk(err, 'no error') })
- child(50, function (err) { t.notOk(err, 'no error') })
- child(50, function (err) { t.notOk(err, 'no error') })
- child(50, function (err) {
- t.ok(err)
- t.equal(err.type, 'MaxConcurrentCallsError', 'correct error type')
- })
- child(50, function (err) {
- t.ok(err)
- t.equal(err.type, 'MaxConcurrentCallsError', 'correct error type')
- })
-
- workerFarm.end(child, function () {
- t.ok(true, 'workerFarm ended')
- })
-})
-
-
-// this test should not keep the process running! if the test process
-// doesn't die then the problem is here
-tape('test timeout kill', function (t) {
- t.plan(3)
-
- let child = workerFarm({ maxCallTime: 250, maxConcurrentWorkers: 1 }, childPath, [ 'block' ])
- child.block(function (err) {
- t.ok(err, 'got an error')
- t.equal(err.type, 'TimeoutError', 'correct error type')
- })
-
- workerFarm.end(child, function () {
- t.ok(true, 'workerFarm ended')
- })
-})
-
-
-tape('test max retries after process terminate', function (t) {
- t.plan(7)
-
- // temporary file is used to store the number of retries among terminating workers
- let filepath1 = '.retries1'
- let child1 = workerFarm({ maxConcurrentWorkers: 1, maxRetries: 5}, childPath, [ 'stubborn' ])
- child1.stubborn(filepath1, function (err, result) {
- t.notOk(err, 'no error')
- t.equal(result, 12, 'correct result')
- })
-
- workerFarm.end(child1, function () {
- fs.unlinkSync(filepath1)
- t.ok(true, 'workerFarm ended')
- })
-
- let filepath2 = '.retries2'
- let child2 = workerFarm({ maxConcurrentWorkers: 1, maxRetries: 3}, childPath, [ 'stubborn' ])
- child2.stubborn(filepath2, function (err, result) {
- t.ok(err, 'got an error')
- t.equal(err.type, 'ProcessTerminatedError', 'correct error type')
- t.equal(err.message, 'cancel after 3 retries!', 'correct message and number of retries')
- })
-
- workerFarm.end(child2, function () {
- fs.unlinkSync(filepath2)
- t.ok(true, 'workerFarm ended')
- })
-})
-
-
-tape('ensure --debug/--inspect not propagated to children', function (t) {
- t.plan(3)
-
- let script = __dirname + '/debug.js'
- , debugArg = process.version.replace(/^v(\d+)\..*$/, '$1') >= 8 ? '--inspect' : '--debug=8881'
- , child = child_process.spawn(process.execPath, [ debugArg, script ])
- , stdout = ''
-
- child.stdout.on('data', function (data) {
- stdout += data.toString()
- })
-
- child.on('close', function (code) {
- t.equal(code, 0, 'exited without error (' + code + ')')
- t.ok(stdout.indexOf('FINISHED') > -1, 'process finished')
- t.ok(stdout.indexOf('--debug') === -1, 'child does not receive debug flag')
- })
-})