refactor: cleanup examples package.json scripts
[poolifier.git] / tests / pools / cluster / fixed.test.js
index 6edfcd67b8c53517b7f4d635b3738ca43131a76b..af3bc452ed64b5303f36cf9eb0d93e2d01f160f4 100644 (file)
@@ -276,16 +276,33 @@ describe('Fixed cluster pool test suite', () => {
   })
 
   it('Should work even without opts in input', async () => {
-    const pool = new FixedClusterPool(
-      numberOfWorkers,
-      './tests/worker-files/cluster/testWorker.js'
-    )
+    const workerFilePath = './tests/worker-files/cluster/testWorker.js'
+    const pool = new FixedClusterPool(numberOfWorkers, workerFilePath)
     const res = await pool.execute()
     expect(res).toStrictEqual({ ok: 1 })
     // We need to clean up the resources after our test
     await pool.destroy()
   })
 
+  it('Verify destroyWorkerNode()', async () => {
+    const workerFilePath = './tests/worker-files/cluster/testWorker.js'
+    const pool = new FixedClusterPool(numberOfWorkers, workerFilePath)
+    const workerNodeKey = 0
+    let disconnectEvent = 0
+    pool.workerNodes[workerNodeKey].worker.on('disconnect', () => {
+      ++disconnectEvent
+    })
+    let exitEvent = 0
+    pool.workerNodes[workerNodeKey].worker.on('exit', () => {
+      ++exitEvent
+    })
+    await expect(pool.destroyWorkerNode(workerNodeKey)).resolves.toBeUndefined()
+    expect(disconnectEvent).toBe(1)
+    expect(exitEvent).toBe(1)
+    expect(pool.workerNodes.length).toBe(numberOfWorkers - 1)
+    await pool.destroy()
+  })
+
   it('Verify that a pool with zero worker fails', async () => {
     expect(
       () =>