Pool busy event emitting on all pool types (#241)
[poolifier.git] / tests / worker / abstract-worker.test.js
index ddb8427b82f5dd41c5273815a6dfd51446ebd45e..1d0c03d9c398c75a5c88b21cb8a7ff1cb0dfc2c1 100644 (file)
@@ -1,10 +1,29 @@
 const expect = require('expect')
-const { ThreadWorker } = 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', () => {
-    expect(() => {
-      const worker = new ThreadWorker()
-    }).toThrowError()
+    expect(() => new ClusterWorker()).toThrowError(
+      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()
   })
 })