Merge branch 'master' into combined-prs-branch
[poolifier.git] / tests / worker / cluster-worker.test.mjs
index 3392d96cd1502ccdd90fd1f72a21381570d4976e..70d63639dab40d0a61622f73a8e5da18809c7ec7 100644 (file)
@@ -9,6 +9,14 @@ describe('Cluster worker test suite', () => {
     restore()
   })
 
+  it('Verify worker properties value after initialization', () => {
+    const worker = new ClusterWorker(() => {})
+    expect(worker.isMain).toBe(true)
+    expect(worker.mainWorker).toBe(undefined)
+    expect(worker.taskFunctions).toBeInstanceOf(Map)
+    expect(worker.taskFunctions.size).toBe(2)
+  })
+
   it('Verify that sync kill handler is called when worker is killed', () => {
     const worker = new ClusterWorker(() => {}, {
       killHandler: stub().returns()
@@ -44,9 +52,15 @@ describe('Cluster worker test suite', () => {
       status: false,
       error: new TypeError('name parameter is an empty string')
     })
-    expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toBeInstanceOf(Function)
-    expect(worker.taskFunctions.get('fn1')).toBeInstanceOf(Function)
-    expect(worker.taskFunctions.get('fn2')).toBeInstanceOf(Function)
+    expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toStrictEqual({
+      taskFunction: expect.any(Function)
+    })
+    expect(worker.taskFunctions.get('fn1')).toStrictEqual({
+      taskFunction: expect.any(Function)
+    })
+    expect(worker.taskFunctions.get('fn2')).toStrictEqual({
+      taskFunction: expect.any(Function)
+    })
     expect(worker.taskFunctions.size).toBe(3)
     expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toStrictEqual(
       worker.taskFunctions.get('fn1')
@@ -64,8 +78,12 @@ describe('Cluster worker test suite', () => {
       )
     })
     worker.removeTaskFunction('fn2')
-    expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toBeInstanceOf(Function)
-    expect(worker.taskFunctions.get('fn1')).toBeInstanceOf(Function)
+    expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toStrictEqual({
+      taskFunction: expect.any(Function)
+    })
+    expect(worker.taskFunctions.get('fn1')).toStrictEqual({
+      taskFunction: expect.any(Function)
+    })
     expect(worker.taskFunctions.get('fn2')).toBeUndefined()
     expect(worker.taskFunctions.size).toBe(2)
     expect(worker.getMainWorker.calledTwice).toBe(true)