)
const emptyPool = new FixedThreadPool(
1,
- './tests/worker-files/thread/emptyWorker.js'
+ './tests/worker-files/thread/emptyWorker.js',
+ { exitHandler: () => console.log('WORKER EXITED') }
)
const echoPool = new FixedThreadPool(
1,
const expect = require('expect')
-const { ClusterWorker } = require('../../lib')
+const { ClusterWorker, ThreadWorker } = require('../../lib')
+
+class StubPoolWithIsMainWorker extends ThreadWorker {
+ constructor (fn, opts) {
+ super(fn, opts)
+ this.mainWorker = false
+ }
+}
describe('Abstract worker test suite', () => {
it('Verify that fn function is mandatory', () => {
new Error('fn parameter is mandatory')
)
})
+
+ it('Verify that handle Error function is working properly', () => {
+ const error = new Error('My error')
+ const worker = new ThreadWorker(() => {})
+ expect(worker.handleError(error)).toBe(error)
+ })
+
+ it('Verify that get main worker throw error if main worker is not set', () => {
+ expect(() =>
+ new StubPoolWithIsMainWorker(() => {}).getMainWorker()
+ ).toThrowError()
+ })
})
const worker = new ClusterWorker(() => {})
expect(worker.maxInactiveTime).toEqual(60_000)
})
+
+ it('Verify that handleError function works properly', () => {
+ const errorMessage = 'Error as a string'
+ const worker = new ClusterWorker(() => {})
+ expect(worker.handleError(errorMessage)).toBe(errorMessage)
+ })
})