update, text, response
This commit is contained in:
2
node_modules/fastq/test/example.ts
generated
vendored
2
node_modules/fastq/test/example.ts
generated
vendored
@@ -32,6 +32,8 @@ queue.pause()
|
||||
|
||||
queue.resume()
|
||||
|
||||
queue.running()
|
||||
|
||||
queue.saturated = () => undefined
|
||||
|
||||
queue.unshift('world', (err, result) => {
|
||||
|
||||
43
node_modules/fastq/test/promise.js
generated
vendored
43
node_modules/fastq/test/promise.js
generated
vendored
@@ -246,3 +246,46 @@ test('no unhandledRejection (unshift)', async function (t) {
|
||||
await immediate()
|
||||
process.removeListener('unhandledRejection', handleRejection)
|
||||
})
|
||||
|
||||
test('drained should resolve after async tasks complete', async function (t) {
|
||||
const logs = []
|
||||
|
||||
async function processTask () {
|
||||
await new Promise(resolve => setTimeout(resolve, 0))
|
||||
logs.push('processed')
|
||||
}
|
||||
|
||||
const queue = buildQueue(processTask, 1)
|
||||
queue.drain = () => logs.push('called drain')
|
||||
|
||||
queue.drained().then(() => logs.push('drained promise resolved'))
|
||||
|
||||
await Promise.all([
|
||||
queue.push(),
|
||||
queue.push(),
|
||||
queue.push()
|
||||
])
|
||||
|
||||
t.deepEqual(logs, [
|
||||
'processed',
|
||||
'processed',
|
||||
'processed',
|
||||
'called drain',
|
||||
'drained promise resolved'
|
||||
], 'events happened in correct order')
|
||||
})
|
||||
|
||||
test('drained should handle undefined drain function', async function (t) {
|
||||
const queue = buildQueue(worker, 1)
|
||||
|
||||
async function worker (arg) {
|
||||
await sleep(10)
|
||||
return arg
|
||||
}
|
||||
|
||||
queue.drain = undefined
|
||||
queue.push(1)
|
||||
await queue.drained()
|
||||
|
||||
t.pass('drained resolved successfully with undefined drain')
|
||||
})
|
||||
|
||||
119
node_modules/fastq/test/test.js
generated
vendored
119
node_modules/fastq/test/test.js
generated
vendored
@@ -6,10 +6,22 @@ var test = require('tape')
|
||||
var buildQueue = require('../')
|
||||
|
||||
test('concurrency', function (t) {
|
||||
t.plan(2)
|
||||
t.plan(6)
|
||||
t.throws(buildQueue.bind(null, worker, 0))
|
||||
t.throws(buildQueue.bind(null, worker, NaN))
|
||||
t.doesNotThrow(buildQueue.bind(null, worker, 1))
|
||||
|
||||
var queue = buildQueue(worker, 1)
|
||||
t.throws(function () {
|
||||
queue.concurrency = 0
|
||||
})
|
||||
t.throws(function () {
|
||||
queue.concurrency = NaN
|
||||
})
|
||||
t.doesNotThrow(function () {
|
||||
queue.concurrency = 2
|
||||
})
|
||||
|
||||
function worker (arg, cb) {
|
||||
cb(null, true)
|
||||
}
|
||||
@@ -137,10 +149,11 @@ test('drain', function (t) {
|
||||
})
|
||||
|
||||
test('pause && resume', function (t) {
|
||||
t.plan(7)
|
||||
t.plan(13)
|
||||
|
||||
var queue = buildQueue(worker, 1)
|
||||
var worked = false
|
||||
var expected = [42, 24]
|
||||
|
||||
t.notOk(queue.paused, 'it should not be paused')
|
||||
|
||||
@@ -151,26 +164,33 @@ test('pause && resume', function (t) {
|
||||
t.equal(result, true, 'result matches')
|
||||
})
|
||||
|
||||
queue.push(24, function (err, result) {
|
||||
t.error(err, 'no error')
|
||||
t.equal(result, true, 'result matches')
|
||||
})
|
||||
|
||||
t.notOk(worked, 'it should be paused')
|
||||
t.ok(queue.paused, 'it should be paused')
|
||||
|
||||
queue.resume()
|
||||
queue.pause()
|
||||
queue.resume()
|
||||
queue.resume() // second resume is a no-op
|
||||
|
||||
t.notOk(queue.paused, 'it should not be paused')
|
||||
|
||||
function worker (arg, cb) {
|
||||
t.equal(arg, 42)
|
||||
t.notOk(queue.paused, 'it should not be paused')
|
||||
t.ok(queue.running() <= queue.concurrency, 'should respect the concurrency')
|
||||
t.equal(arg, expected.shift())
|
||||
worked = true
|
||||
cb(null, true)
|
||||
process.nextTick(function () { cb(null, true) })
|
||||
}
|
||||
})
|
||||
|
||||
test('pause in flight && resume', function (t) {
|
||||
t.plan(9)
|
||||
t.plan(16)
|
||||
|
||||
var queue = buildQueue(worker, 1)
|
||||
var expected = [42, 24]
|
||||
var expected = [42, 24, 12]
|
||||
|
||||
t.notOk(queue.paused, 'it should not be paused')
|
||||
|
||||
@@ -178,7 +198,11 @@ test('pause in flight && resume', function (t) {
|
||||
t.error(err, 'no error')
|
||||
t.equal(result, true, 'result matches')
|
||||
t.ok(queue.paused, 'it should be paused')
|
||||
process.nextTick(function () { queue.resume() })
|
||||
process.nextTick(function () {
|
||||
queue.resume()
|
||||
queue.pause()
|
||||
queue.resume()
|
||||
})
|
||||
})
|
||||
|
||||
queue.push(24, function (err, result) {
|
||||
@@ -187,40 +211,60 @@ test('pause in flight && resume', function (t) {
|
||||
t.notOk(queue.paused, 'it should not be paused')
|
||||
})
|
||||
|
||||
queue.push(12, function (err, result) {
|
||||
t.error(err, 'no error')
|
||||
t.equal(result, true, 'result matches')
|
||||
t.notOk(queue.paused, 'it should not be paused')
|
||||
})
|
||||
|
||||
queue.pause()
|
||||
|
||||
function worker (arg, cb) {
|
||||
t.ok(queue.running() <= queue.concurrency, 'should respect the concurrency')
|
||||
t.equal(arg, expected.shift())
|
||||
process.nextTick(function () { cb(null, true) })
|
||||
}
|
||||
})
|
||||
|
||||
test('altering concurrency', function (t) {
|
||||
t.plan(7)
|
||||
t.plan(24)
|
||||
|
||||
var queue = buildQueue(worker, 1)
|
||||
var count = 0
|
||||
|
||||
queue.push(24, workDone)
|
||||
queue.push(24, workDone)
|
||||
queue.push(24, workDone)
|
||||
|
||||
queue.pause()
|
||||
|
||||
queue.push(24, workDone)
|
||||
queue.push(24, workDone)
|
||||
|
||||
queue.concurrency = 3 // concurrency changes are ignored while paused
|
||||
queue.concurrency = 2
|
||||
|
||||
queue.resume()
|
||||
|
||||
t.equal(queue.running(), 2, '2 jobs running')
|
||||
|
||||
queue.concurrency = 3
|
||||
|
||||
t.equal(queue.running(), 3, '3 jobs running')
|
||||
|
||||
queue.concurrency = 1
|
||||
|
||||
t.equal(queue.running(), 3, '3 jobs running') // running jobs can't be killed
|
||||
|
||||
queue.push(24, workDone)
|
||||
queue.push(24, workDone)
|
||||
queue.push(24, workDone)
|
||||
queue.push(24, workDone)
|
||||
|
||||
function workDone (err, result) {
|
||||
t.error(err, 'no error')
|
||||
t.equal(result, true, 'result matches')
|
||||
}
|
||||
|
||||
function worker (arg, cb) {
|
||||
t.equal(0, count, 'works in parallel')
|
||||
t.ok(queue.running() <= queue.concurrency, 'should respect the concurrency')
|
||||
setImmediate(function () {
|
||||
count++
|
||||
cb(null, true)
|
||||
})
|
||||
}
|
||||
@@ -564,3 +608,46 @@ test('push with worker throwing error', function (t) {
|
||||
t.match(err.message, /test error/, 'error message should be "test error"')
|
||||
})
|
||||
})
|
||||
|
||||
test('unshift with worker throwing error', function (t) {
|
||||
t.plan(5)
|
||||
var q = buildQueue(function (task, cb) {
|
||||
cb(new Error('test error'), null)
|
||||
}, 1)
|
||||
q.error(function (err, task) {
|
||||
t.ok(err instanceof Error, 'global error handler should catch the error')
|
||||
t.match(err.message, /test error/, 'error message should be "test error"')
|
||||
t.equal(task, 42, 'The task executed should be passed')
|
||||
})
|
||||
q.unshift(42, function (err) {
|
||||
t.ok(err instanceof Error, 'unshift callback should catch the error')
|
||||
t.match(err.message, /test error/, 'error message should be "test error"')
|
||||
})
|
||||
})
|
||||
|
||||
test('pause/resume should trigger drain event', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
var queue = buildQueue(worker, 1)
|
||||
queue.pause()
|
||||
queue.drain = function () {
|
||||
t.pass('drain should be called')
|
||||
}
|
||||
|
||||
function worker (arg, cb) {
|
||||
cb(null, true)
|
||||
}
|
||||
|
||||
queue.resume()
|
||||
})
|
||||
|
||||
test('paused flag', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
var queue = buildQueue(function (arg, cb) {
|
||||
cb(null)
|
||||
}, 1)
|
||||
t.equal(queue.paused, false)
|
||||
queue.pause()
|
||||
t.equal(queue.paused, true)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user