From: aardizio Date: Mon, 15 Feb 2021 16:29:36 +0000 (+0100) Subject: Cluster pool is now working X-Git-Tag: v2.0.0-beta.2~17^2~24 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=e5177d860cd10dd89b107cc6692e9989286b3a7c;p=poolifier.git Cluster pool is now working --- diff --git a/src/pools/cluster/dynamic.ts b/src/pools/cluster/dynamic.ts index 44847b61..f6c70126 100644 --- a/src/pools/cluster/dynamic.ts +++ b/src/pools/cluster/dynamic.ts @@ -62,7 +62,7 @@ export class DynamicClusterPool< const worker = this.createAndSetupWorker() this.registerWorkerMessageListener(worker, message => { const tasksInProgress = this.tasks.get(worker) - if (message.kill) { + if (message.kill && !tasksInProgress) { this.sendToWorker(worker, { kill: 1 }) void this.destroyWorker(worker) } diff --git a/tests/pools/cluster/dynamic.test.js b/tests/pools/cluster/dynamic.test.js index 024e2670..e0a0fde3 100644 --- a/tests/pools/cluster/dynamic.test.js +++ b/tests/pools/cluster/dynamic.test.js @@ -7,8 +7,7 @@ const pool = new DynamicClusterPool( max, './tests/worker/cluster/testWorker.js', { - errorHandler: e => console.error(e), - onlineHandler: () => console.log('worker is online') + errorHandler: e => console.error(e) } ) @@ -51,7 +50,7 @@ describe('Dynamic cluster pool test suite ', () => { pool.execute({ test: 'test' }) } expect(pool.workers.length).toBeGreaterThan(min) - await new Promise(resolve => setTimeout(resolve, 2000)) + await new Promise(resolve => setTimeout(resolve, 3000)) expect(pool.workers.length).toBe(min) }) it('Shutdown test', async () => { @@ -62,7 +61,7 @@ describe('Dynamic cluster pool test suite ', () => { }) }) pool.destroy() - await new Promise(resolve => setTimeout(resolve, 1000)) + await new Promise(resolve => setTimeout(resolve, 2000)) expect(closedWorkers).toBe(min) }) @@ -91,14 +90,14 @@ describe('Dynamic cluster pool test suite ', () => { const longRunningPool = new DynamicClusterPool( min, max, - './tests/worker/thread/longRunningWorker.js' + './tests/worker/cluster/longRunningWorker.js' ) expect(longRunningPool.workers.length).toBe(min) for (let i = 0; i < max * 10; i++) { longRunningPool.execute({ test: 'test' }) } expect(longRunningPool.workers.length).toBe(max) - await new Promise(resolve => setTimeout(resolve, 1000)) + await new Promise(resolve => setTimeout(resolve, 3000)) // Here we expect the workers to be at the max size since that the task is still running expect(longRunningPool.workers.length).toBe(max) }) diff --git a/tests/pools/cluster/fixed.test.js b/tests/pools/cluster/fixed.test.js index d22f697a..51501df0 100644 --- a/tests/pools/cluster/fixed.test.js +++ b/tests/pools/cluster/fixed.test.js @@ -6,8 +6,7 @@ const pool = new FixedClusterPool( numberOfWorkers, './tests/worker/cluster/testWorker.js', { - errorHandler: e => console.error(e), - onlineHandler: () => console.log('worker is online') + errorHandler: e => console.error(e) } ) const emptyPool = new FixedClusterPool( @@ -19,8 +18,7 @@ const errorPool = new FixedClusterPool( 1, './tests/worker/cluster/errorWorker.js', { - errorHandler: e => console.error(e), - onlineHandler: () => console.log('worker is online') + errorHandler: e => console.error(e) } ) diff --git a/tests/pools/thread/dynamic.test.js b/tests/pools/thread/dynamic.test.js index d59b9858..2f89b2ff 100644 --- a/tests/pools/thread/dynamic.test.js +++ b/tests/pools/thread/dynamic.test.js @@ -7,8 +7,7 @@ const pool = new DynamicThreadPool( max, './tests/worker/thread/testWorker.js', { - errorHandler: e => console.error(e), - onlineHandler: () => console.log('worker is online') + errorHandler: e => console.error(e) } ) diff --git a/tests/pools/thread/fixed.test.js b/tests/pools/thread/fixed.test.js index a5ec3f0a..e160f17c 100644 --- a/tests/pools/thread/fixed.test.js +++ b/tests/pools/thread/fixed.test.js @@ -6,8 +6,7 @@ const pool = new FixedThreadPool( numberOfThreads, './tests/worker/thread/testWorker.js', { - errorHandler: e => console.error(e), - onlineHandler: () => console.log('worker is online') + errorHandler: e => console.error(e) } ) const emptyPool = new FixedThreadPool(1, './tests/worker/thread/emptyWorker.js')