test: add kill behavior testing
authorJérôme Benoit <jerome.benoit@sap.com>
Sat, 3 Jun 2023 07:16:11 +0000 (09:16 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sat, 3 Jun 2023 07:16:11 +0000 (09:16 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/pools/abstract-pool.ts
tests/utils.test.js

index 55c380b80c5b92de72bb1c4c87e57f4614c56f37..631434f37618e4727b2a8dcdbee119c309965da1 100644 (file)
@@ -410,6 +410,7 @@ export abstract class AbstractPool<
     await Promise.all(
       this.workerNodes.map(async (workerNode, workerNodeKey) => {
         this.flushTasksQueue(workerNodeKey)
+        // FIXME: wait for tasks to be finished
         await this.destroyWorker(workerNode.worker)
       })
     )
@@ -535,6 +536,7 @@ export abstract class AbstractPool<
         ) {
           // Kill message received from the worker: no new tasks are submitted to that worker for a while ( > maxInactiveTime)
           this.flushTasksQueue(currentWorkerNodeKey)
+          // FIXME: wait for tasks to be finished
           void (this.destroyWorker(workerCreated) as Promise<void>)
         }
       })
index f3278e4780b064ee25b6fcf7d900559b96fb23c7..d4c2179b12a6ddba893aa771846a896bdccf1d7e 100644 (file)
@@ -1,5 +1,9 @@
 const { expect } = require('expect')
 const { isPlainObject, median } = require('../lib/utils')
+const {
+  isKillBehavior,
+  KillBehaviors
+} = require('../lib/worker/worker-options')
 
 describe('Utils test suite', () => {
   it('Verify median computation', () => {
@@ -45,4 +49,15 @@ describe('Utils test suite', () => {
     expect(isPlainObject({})).toBe(true)
     expect(isPlainObject({ a: 1 })).toBe(true)
   })
+
+  it('Verify isKillBehavior() behavior', () => {
+    expect(isKillBehavior(KillBehaviors.SOFT, KillBehaviors.SOFT)).toBe(true)
+    expect(isKillBehavior(KillBehaviors.SOFT, KillBehaviors.HARD)).toBe(false)
+    expect(isKillBehavior(KillBehaviors.HARD, KillBehaviors.HARD)).toBe(true)
+    expect(isKillBehavior(KillBehaviors.HARD, KillBehaviors.SOFT)).toBe(false)
+    expect(isKillBehavior(KillBehaviors.SOFT)).toBe(false)
+    expect(isKillBehavior(KillBehaviors.HARD)).toBe(false)
+    expect(isKillBehavior(KillBehaviors.HARD, null)).toBe(false)
+    expect(isKillBehavior(KillBehaviors.SOFT, 'unknown')).toBe(false)
+  })
 })