WorkerChoiceStrategies,
DynamicThreadPool,
FixedThreadPool
-} = require('../../lib/index')
+} = require('../../../lib/index')
describe('Selection strategies test suite', () => {
it('Verify that WorkerChoiceStrategies enumeration provides string values', () => {
return new Promise(resolve => setTimeout(resolve, ms))
}
- static async workerSleepFunction (data, ms) {
- return new Promise(resolve => {
- setTimeout(() => resolve(data), ms)
+ static async workerSleepFunction (
+ data,
+ ms,
+ rejection = false,
+ rejectionMessage = ''
+ ) {
+ return new Promise((resolve, reject) => {
+ setTimeout(
+ () =>
+ rejection === true
+ ? reject(new Error(rejectionMessage))
+ : resolve(data),
+ ms
+ )
})
}
'use strict'
const { ClusterWorker, KillBehaviors } = require('../../../lib/index')
+const TestUtils = require('../../test-utils')
async function error (data) {
- return new Promise((resolve, reject) => {
- setTimeout(
- () => reject(new Error('Error Message from ClusterWorker:async')),
- 2000
- )
- })
+ return TestUtils.workerSleepFunction(
+ data,
+ 2000,
+ true,
+ 'Error Message from ClusterWorker:async'
+ )
}
module.exports = new ClusterWorker(error, {
'use strict'
const { ThreadWorker, KillBehaviors } = require('../../../lib/index')
+const TestUtils = require('../../test-utils')
async function error (data) {
- return new Promise((resolve, reject) => {
- setTimeout(() => reject(new Error(data)), 2000)
- })
+ return TestUtils.workerSleepFunction(
+ data,
+ 2000,
+ true,
+ 'Error Message from ThreadWorker:async'
+ )
}
module.exports = new ThreadWorker(error, {
const { ThreadWorker, KillBehaviors } = require('../../../lib/index')
function error (data) {
- throw new Error(data)
+ throw new Error('Error Message from ThreadWorker')
}
module.exports = new ThreadWorker(error, {