"regexpp": "^3.0.0",
"semver": "^7.3.2",
"tsutils": "^3.17.1"
- },
- "dependencies": {
- "@typescript-eslint/scope-manager": {
- "version": "4.17.0",
- "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-4.17.0.tgz",
- "integrity": "sha512-OJ+CeTliuW+UZ9qgULrnGpPQ1bhrZNFpfT/Bc0pzNeyZwMik7/ykJ0JHnQ7krHanFN9wcnPK89pwn84cRUmYjw==",
- "dev": true,
- "requires": {
- "@typescript-eslint/types": "4.17.0",
- "@typescript-eslint/visitor-keys": "4.17.0"
- }
- },
- "@typescript-eslint/types": {
- "version": "4.17.0",
- "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-4.17.0.tgz",
- "integrity": "sha512-RN5z8qYpJ+kXwnLlyzZkiJwfW2AY458Bf8WqllkondQIcN2ZxQowAToGSd9BlAUZDB5Ea8I6mqL2quGYCLT+2g==",
- "dev": true
- },
- "@typescript-eslint/visitor-keys": {
- "version": "4.17.0",
- "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-4.17.0.tgz",
- "integrity": "sha512-WfuMN8mm5SSqXuAr9NM+fItJ0SVVphobWYkWOwQ1odsfC014Vdxk/92t4JwS1Q6fCA/ABfCKpa3AVtpUKTNKGQ==",
- "dev": true,
- "requires": {
- "@typescript-eslint/types": "4.17.0",
- "eslint-visitor-keys": "^2.0.0"
- }
- }
}
},
"@typescript-eslint/experimental-utils": {
"@typescript-eslint/typescript-estree": "4.17.0",
"eslint-scope": "^5.0.0",
"eslint-utils": "^2.0.0"
- },
- "dependencies": {
- "@typescript-eslint/scope-manager": {
- "version": "4.17.0",
- "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-4.17.0.tgz",
- "integrity": "sha512-OJ+CeTliuW+UZ9qgULrnGpPQ1bhrZNFpfT/Bc0pzNeyZwMik7/ykJ0JHnQ7krHanFN9wcnPK89pwn84cRUmYjw==",
- "dev": true,
- "requires": {
- "@typescript-eslint/types": "4.17.0",
- "@typescript-eslint/visitor-keys": "4.17.0"
- }
- },
- "@typescript-eslint/types": {
- "version": "4.17.0",
- "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-4.17.0.tgz",
- "integrity": "sha512-RN5z8qYpJ+kXwnLlyzZkiJwfW2AY458Bf8WqllkondQIcN2ZxQowAToGSd9BlAUZDB5Ea8I6mqL2quGYCLT+2g==",
- "dev": true
- },
- "@typescript-eslint/typescript-estree": {
- "version": "4.17.0",
- "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-4.17.0.tgz",
- "integrity": "sha512-lRhSFIZKUEPPWpWfwuZBH9trYIEJSI0vYsrxbvVvNyIUDoKWaklOAelsSkeh3E2VBSZiNe9BZ4E5tYBZbUczVQ==",
- "dev": true,
- "requires": {
- "@typescript-eslint/types": "4.17.0",
- "@typescript-eslint/visitor-keys": "4.17.0",
- "debug": "^4.1.1",
- "globby": "^11.0.1",
- "is-glob": "^4.0.1",
- "semver": "^7.3.2",
- "tsutils": "^3.17.1"
- }
- },
- "@typescript-eslint/visitor-keys": {
- "version": "4.17.0",
- "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-4.17.0.tgz",
- "integrity": "sha512-WfuMN8mm5SSqXuAr9NM+fItJ0SVVphobWYkWOwQ1odsfC014Vdxk/92t4JwS1Q6fCA/ABfCKpa3AVtpUKTNKGQ==",
- "dev": true,
- "requires": {
- "@typescript-eslint/types": "4.17.0",
- "eslint-visitor-keys": "^2.0.0"
- }
- }
}
},
"@typescript-eslint/parser": {
numberOfWorkers,
'./tests/worker-files/thread/testWorker.js'
)
- expect(pool.opts.enableEvents).toEqual(true)
+ expect(pool.opts.enableEvents).toBe(true)
expect(pool.emitter).toBeDefined()
expect(pool.opts.workerChoiceStrategy).toBe(
WorkerChoiceStrategies.ROUND_ROBIN
enableEvents: false
}
)
- expect(pool.opts.enableEvents).toEqual(false)
+ expect(pool.opts.enableEvents).toBe(false)
expect(pool.emitter).toBeUndefined()
expect(pool.opts.workerChoiceStrategy).toBe(
WorkerChoiceStrategies.LESS_RECENTLY_USED
for (let i = 0; i < numberOfWorkers * 2; i++) {
promises.push(pool.execute({ test: 'test' }))
}
- expect(poolBusy).toEqual(numberOfWorkers)
+ expect(poolBusy).toBe(numberOfWorkers)
pool.destroy()
})
})
}
expect(pool.workers.length).toBeLessThanOrEqual(max)
expect(pool.workers.length).toBeGreaterThan(min)
- expect(poolBusy).toEqual(max + 1)
+ expect(poolBusy).toBe(max + 1)
const numberOfExitEvents = await TestUtils.waitExits(pool, max - min)
expect(numberOfExitEvents).toBe(max - min)
})
'./tests/worker-files/cluster/testWorker.js'
)
const result = await pool1.execute({ test: 'test' })
+ expect(result).toBeDefined()
expect(result).toBeFalsy()
// We need to clean up the resources after our test
await pool1.destroy()
for (let i = 0; i < numberOfWorkers * 2; i++) {
promises.push(pool.execute({ test: 'test' }))
}
- expect(poolBusy).toEqual(numberOfWorkers)
+ expect(poolBusy).toBe(numberOfWorkers)
})
it('Verify that is possible to have a worker that return undefined', async () => {
inError = e
}
expect(inError).toBeDefined()
- expect(typeof inError === 'string').toEqual(true)
+ expect(typeof inError === 'string').toBe(true)
expect(inError).toBe('Error Message from ClusterWorker')
})
inError = e
}
expect(inError).toBeDefined()
- expect(typeof inError === 'string').toEqual(true)
+ expect(typeof inError === 'string').toBe(true)
expect(inError).toBe('Error Message from ClusterWorker:async')
})
promises.push(pool.execute({ test: 'test' }))
}
expect(pool.workers.length).toBe(max)
- expect(poolBusy).toEqual(max + 1)
+ expect(poolBusy).toBe(max + 1)
const res = await TestUtils.waitExits(pool, max - min)
expect(res).toBe(max - min)
})
'./tests/worker-files/thread/testWorker.js'
)
const res = await pool1.execute({ test: 'test' })
+ expect(res).toBeDefined()
expect(res).toBeFalsy()
// We need to clean up the resources after our test
await pool1.destroy()
for (let i = 0; i < numberOfThreads * 2; i++) {
promises.push(pool.execute({ test: 'test' }))
}
- expect(poolBusy).toEqual(numberOfThreads)
+ expect(poolBusy).toBe(numberOfThreads)
})
it('Verify that is possible to have a worker that return undefined', async () => {
expect(inError).toBeDefined()
expect(inError).toBeInstanceOf(Error)
expect(inError.message).toBeDefined()
- expect(typeof inError.message === 'string').toEqual(true)
+ expect(typeof inError.message === 'string').toBe(true)
})
it('Verify that error handling is working properly:async', async () => {
expect(inError).toBeDefined()
expect(inError).toBeInstanceOf(Error)
expect(inError.message).toBeDefined()
- expect(typeof inError.message === 'string').toEqual(true)
+ expect(typeof inError.message === 'string').toBe(true)
})
it('Verify that async function is working properly', async () => {
const expect = require('expect')
-const { ClusterWorker, ThreadWorker } = require('../../lib')
+const { ClusterWorker, KillBehaviors, ThreadWorker } = require('../../lib')
class StubPoolWithIsMainWorker extends ThreadWorker {
constructor (fn, opts) {
)
})
+ it('Verify worker default values', () => {
+ const worker = new ThreadWorker(() => {})
+ expect(worker.maxInactiveTime).toBe(1000 * 60)
+ expect(worker.killBehavior).toBe(KillBehaviors.SOFT)
+ expect(worker.async).toBe(false)
+ })
+
+ it('Verify that worker options are set at worker creation', () => {
+ const worker = new ClusterWorker(() => {}, {
+ maxInactiveTime: 6000,
+ async: true,
+ killBehavior: KillBehaviors.HARD
+ })
+ expect(worker.maxInactiveTime).toBe(6000)
+ expect(worker.killBehavior).toBe(KillBehaviors.HARD)
+ expect(worker.async).toBe(true)
+ })
+
it('Verify that handleError function is working properly', () => {
const error = new Error('My error')
const worker = new ThreadWorker(() => {})