From 47aacbaa07c16cb4a11fd5d46323db47cb948b41 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 3 Jun 2023 09:16:11 +0200 Subject: [PATCH] test: add kill behavior testing MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/pools/abstract-pool.ts | 2 ++ tests/utils.test.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+) 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) + }) }) -- 2.34.1