+const { EventEmitter } = require('events')
const { expect } = require('expect')
const sinon = require('sinon')
const {
numberOfWorkers,
'./tests/worker-files/thread/testWorker.js'
)
- expect(pool.emitter).toBeDefined()
+ expect(pool.emitter).toBeInstanceOf(EventEmitter)
expect(pool.opts.enableEvents).toBe(true)
expect(pool.opts.restartWorkerOnError).toBe(true)
expect(pool.opts.enableTasksQueue).toBe(false)
}
module.exports = new ClusterWorker(error, {
- maxInactiveTime: 500,
- killBehavior: KillBehaviors.HARD
+ killBehavior: KillBehaviors.HARD,
+ maxInactiveTime: 500
})
}
module.exports = new ClusterWorker(sleep, {
- maxInactiveTime: 500,
- killBehavior: KillBehaviors.HARD
+ killBehavior: KillBehaviors.HARD,
+ maxInactiveTime: 500
})
function test () {}
module.exports = new ClusterWorker(test, {
- maxInactiveTime: 500,
- killBehavior: KillBehaviors.HARD
+ killBehavior: KillBehaviors.HARD,
+ maxInactiveTime: 500
})
}
module.exports = new ClusterWorker(error, {
- maxInactiveTime: 500,
- killBehavior: KillBehaviors.HARD
+ killBehavior: KillBehaviors.HARD,
+ maxInactiveTime: 500
})
}
module.exports = new ClusterWorker(sleep, {
- maxInactiveTime: 500,
- killBehavior: KillBehaviors.HARD
+ killBehavior: KillBehaviors.HARD,
+ maxInactiveTime: 500
})
fibonacci: (data) => fibonacci(data.n)
},
{
- maxInactiveTime: 500,
- killBehavior: KillBehaviors.HARD
+ killBehavior: KillBehaviors.HARD,
+ maxInactiveTime: 500
}
)
}
module.exports = new ClusterWorker(test, {
- maxInactiveTime: 500,
- killBehavior: KillBehaviors.HARD
+ killBehavior: KillBehaviors.HARD,
+ maxInactiveTime: 500
})
}
module.exports = new ThreadWorker(error, {
- maxInactiveTime: 500,
- killBehavior: KillBehaviors.HARD
+ killBehavior: KillBehaviors.HARD,
+ maxInactiveTime: 500
})
}
module.exports = new ThreadWorker(sleep, {
- maxInactiveTime: 500,
- killBehavior: KillBehaviors.HARD
+ killBehavior: KillBehaviors.HARD,
+ maxInactiveTime: 500
})
function test () {}
module.exports = new ThreadWorker(test, {
- maxInactiveTime: 500,
- killBehavior: KillBehaviors.HARD
+ killBehavior: KillBehaviors.HARD,
+ maxInactiveTime: 500
})
}
module.exports = new ThreadWorker(error, {
- maxInactiveTime: 500,
- killBehavior: KillBehaviors.HARD
+ killBehavior: KillBehaviors.HARD,
+ maxInactiveTime: 500
})
}
module.exports = new ThreadWorker(sleep, {
- maxInactiveTime: 500,
- killBehavior: KillBehaviors.HARD
+ killBehavior: KillBehaviors.HARD,
+ maxInactiveTime: 500
})
fibonacci: (data) => fibonacci(data.n)
},
{
- maxInactiveTime: 500,
- killBehavior: KillBehaviors.HARD
+ killBehavior: KillBehaviors.HARD,
+ maxInactiveTime: 500
}
)
}
module.exports = new ThreadWorker(test, {
- maxInactiveTime: 500,
- killBehavior: KillBehaviors.HARD
+ killBehavior: KillBehaviors.HARD,
+ maxInactiveTime: 500
})
it('Verify worker options default values', () => {
const worker = new ThreadWorker(() => {})
- expect(worker.opts.maxInactiveTime).toStrictEqual(60000)
- expect(worker.opts.killBehavior).toBe(KillBehaviors.SOFT)
- expect(worker.opts.killHandler).toStrictEqual(EMPTY_FUNCTION)
- expect(worker.opts.async).toBe(undefined)
+ expect(worker.opts).toStrictEqual({
+ killBehavior: KillBehaviors.SOFT,
+ maxInactiveTime: 60000,
+ killHandler: EMPTY_FUNCTION
+ })
})
it('Verify that worker options are set at worker creation', () => {
console.info('Worker received kill message')
}
const worker = new ClusterWorker(() => {}, {
- maxInactiveTime: 6000,
killBehavior: KillBehaviors.HARD,
+ maxInactiveTime: 6000,
killHandler,
async: true
})
- expect(worker.opts.maxInactiveTime).toStrictEqual(6000)
- expect(worker.opts.killBehavior).toBe(KillBehaviors.HARD)
- expect(worker.opts.killHandler).toStrictEqual(killHandler)
- expect(worker.opts.async).toBe(undefined)
+ expect(worker.opts).toStrictEqual({
+ killBehavior: KillBehaviors.HARD,
+ maxInactiveTime: 6000,
+ killHandler
+ })
})
it('Verify that taskFunctions parameter is mandatory', () => {
}
}
- it('Verify worker has default maxInactiveTime', () => {
- const worker = new ClusterWorker(() => {})
- expect(worker.opts.maxInactiveTime).toStrictEqual(60000)
- })
-
it('Verify worker invokes the getMainWorker() and send() methods', () => {
const worker = new SpyWorker(() => {})
worker.sendToMainWorker({ ok: 1 })
}
}
- it('Verify worker has default maxInactiveTime', () => {
- const worker = new ThreadWorker(() => {})
- expect(worker.opts.maxInactiveTime).toStrictEqual(60000)
- })
-
it('Verify that handleError() method is working properly', () => {
const error = new Error('Error as an error')
const worker = new ThreadWorker(() => {})