test: refine UTs
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Mon, 28 Aug 2023 14:43:03 +0000 (16:43 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Mon, 28 Aug 2023 14:43:03 +0000 (16:43 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
tests/pools/abstract/abstract-pool.test.js
tests/pools/cluster/fixed.test.js
tests/pools/thread/fixed.test.js

index a44cdea527fcef97363d15063f4d432fcb366ec6..ba9fc4f71825a084881cd86e5a401bd6de80cbda 100644 (file)
@@ -1252,4 +1252,20 @@ describe('Abstract pool test suite', () => {
     }
     await pool.destroy()
   })
+
+  it('Verify sendKillMessageToWorker()', async () => {
+    const pool = new DynamicClusterPool(
+      Math.floor(numberOfWorkers / 2),
+      numberOfWorkers,
+      './tests/worker-files/cluster/testWorker.js'
+    )
+    const workerNodeKey = 0
+    await expect(
+      pool.sendKillMessageToWorker(
+        workerNodeKey,
+        pool.workerNodes[workerNodeKey].info.id
+      )
+    ).resolves.toBeUndefined()
+    await pool.destroy()
+  })
 })
index 675bf70759ebb9911198f1a15012420c384bb04a..af3bc452ed64b5303f36cf9eb0d93e2d01f160f4 100644 (file)
@@ -287,21 +287,16 @@ describe('Fixed cluster pool test suite', () => {
   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[0].worker.on('disconnect', () => {
+    pool.workerNodes[workerNodeKey].worker.on('disconnect', () => {
       ++disconnectEvent
     })
     let exitEvent = 0
-    pool.workerNodes[0].worker.on('exit', () => {
+    pool.workerNodes[workerNodeKey].worker.on('exit', () => {
       ++exitEvent
     })
-    let error
-    try {
-      await pool.destroyWorkerNode(0)
-    } catch (e) {
-      error = e
-    }
-    expect(error).toBeUndefined()
+    await expect(pool.destroyWorkerNode(workerNodeKey)).resolves.toBeUndefined()
     expect(disconnectEvent).toBe(1)
     expect(exitEvent).toBe(1)
     expect(pool.workerNodes.length).toBe(numberOfWorkers - 1)
index ec756aa53b99097e23568d0c02e0a586031c0e6c..901c6665c7d0086bdf453466a7c74027a2c0e6d6 100644 (file)
@@ -312,17 +312,12 @@ describe('Fixed thread pool test suite', () => {
   it('Verify destroyWorkerNode()', async () => {
     const workerFilePath = './tests/worker-files/thread/testWorker.js'
     const pool = new FixedThreadPool(numberOfThreads, workerFilePath)
+    const workerNodeKey = 0
     let exitEvent = 0
-    pool.workerNodes[0].worker.on('exit', () => {
+    pool.workerNodes[workerNodeKey].worker.on('exit', () => {
       ++exitEvent
     })
-    let error
-    try {
-      await pool.destroyWorkerNode(0)
-    } catch (e) {
-      error = e
-    }
-    expect(error).toBeUndefined()
+    await expect(pool.destroyWorkerNode(workerNodeKey)).resolves.toBeUndefined()
     expect(exitEvent).toBe(1)
     expect(pool.workerNodes.length).toBe(numberOfThreads - 1)
     await pool.destroy()