Use JsDoc default regexp
[poolifier.git] / tests / worker / abstract-worker.test.js
index 1d0c03d9c398c75a5c88b21cb8a7ff1cb0dfc2c1..4788e5c6964916873f53ab34bd15b45b0c3dc966 100644 (file)
@@ -1,5 +1,5 @@
 const expect = require('expect')
-const { ClusterWorker, ThreadWorker } = require('../../lib')
+const { ClusterWorker, KillBehaviors, ThreadWorker } = require('../../lib')
 
 class StubPoolWithIsMainWorker extends ThreadWorker {
   constructor (fn, opts) {
@@ -15,7 +15,25 @@ describe('Abstract worker test suite', () => {
     )
   })
 
-  it('Verify that handle Error function is working properly', () => {
+  it('Verify worker options default values', () => {
+    const worker = new ThreadWorker(() => {})
+    expect(worker.opts.maxInactiveTime).toBe(1000 * 60)
+    expect(worker.opts.killBehavior).toBe(KillBehaviors.SOFT)
+    expect(worker.opts.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.opts.maxInactiveTime).toBe(6000)
+    expect(worker.opts.killBehavior).toBe(KillBehaviors.HARD)
+    expect(worker.opts.async).toBe(true)
+  })
+
+  it('Verify that handleError function is working properly', () => {
     const error = new Error('My error')
     const worker = new ThreadWorker(() => {})
     expect(worker.handleError(error)).toBe(error)
@@ -24,6 +42,6 @@ describe('Abstract worker test suite', () => {
   it('Verify that get main worker throw error if main worker is not set', () => {
     expect(() =>
       new StubPoolWithIsMainWorker(() => {}).getMainWorker()
-    ).toThrowError()
+    ).toThrowError(new Error('Main worker was not set'))
   })
 })