From: Jérôme Benoit Date: Sat, 3 Jun 2023 07:16:11 +0000 (+0200) Subject: test: add kill behavior testing X-Git-Tag: v2.5.3~15 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=47aacbaa07c16cb4a11fd5d46323db47cb948b41;p=poolifier.git test: add kill behavior testing Signed-off-by: Jérôme Benoit --- diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 55c380b8..631434f3 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -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) } }) diff --git a/tests/utils.test.js b/tests/utils.test.js index f3278e47..d4c2179b 100644 --- a/tests/utils.test.js +++ b/tests/utils.test.js @@ -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) + }) })