docs: refine changelog entries
[poolifier.git] / tests / pools / cluster / dynamic.test.mjs
index 93f995fcb4cfefd215ea90e348ec1e4023643745..870a5f4df9aa0f3bc997b4463f67746d3e7d8c42 100644 (file)
@@ -1,7 +1,7 @@
 import { expect } from 'expect'
-import { DynamicClusterPool, PoolEvents } from '../../../lib/index.js'
-import { TaskFunctions } from '../../test-types.js'
-import { sleep, waitWorkerEvents } from '../../test-utils.js'
+import { DynamicClusterPool, PoolEvents } from '../../../lib/index.cjs'
+import { TaskFunctions } from '../../test-types.cjs'
+import { sleep, waitWorkerEvents } from '../../test-utils.cjs'
 
 describe('Dynamic cluster pool test suite', () => {
   const min = 1
@@ -9,7 +9,7 @@ describe('Dynamic cluster pool test suite', () => {
   const pool = new DynamicClusterPool(
     min,
     max,
-    './tests/worker-files/cluster/testWorker.js',
+    './tests/worker-files/cluster/testWorker.cjs',
     {
       errorHandler: e => console.error(e)
     }
@@ -37,10 +37,10 @@ describe('Dynamic cluster pool test suite', () => {
     expect(poolBusy).toBe(1)
     const numberOfExitEvents = await waitWorkerEvents(pool, 'exit', max - min)
     expect(numberOfExitEvents).toBe(max - min)
+    expect(pool.workerNodes.length).toBe(min)
   })
 
   it('Verify scale worker up and down is working', async () => {
-    expect(pool.workerNodes.length).toBe(min)
     for (let i = 0; i < max * 2; i++) {
       pool.execute()
     }
@@ -76,7 +76,7 @@ describe('Dynamic cluster pool test suite', () => {
 
   it('Validation of inputs test', () => {
     expect(() => new DynamicClusterPool(min)).toThrow(
-      "Cannot find the worker file 'undefined'"
+      'The worker file path must be specified'
     )
   })
 
@@ -84,7 +84,7 @@ describe('Dynamic cluster pool test suite', () => {
     const pool = new DynamicClusterPool(
       min,
       max,
-      './tests/worker-files/cluster/testWorker.js'
+      './tests/worker-files/cluster/testWorker.cjs'
     )
     const result = await pool.execute()
     expect(result).toStrictEqual({ ok: 1 })
@@ -96,7 +96,7 @@ describe('Dynamic cluster pool test suite', () => {
     const longRunningPool = new DynamicClusterPool(
       min,
       max,
-      './tests/worker-files/cluster/longRunningWorkerHardBehavior.js',
+      './tests/worker-files/cluster/longRunningWorkerHardBehavior.cjs',
       {
         errorHandler: e => console.error(e),
         onlineHandler: () => console.info('long executing worker is online'),
@@ -123,7 +123,7 @@ describe('Dynamic cluster pool test suite', () => {
     const longRunningPool = new DynamicClusterPool(
       min,
       max,
-      './tests/worker-files/cluster/longRunningWorkerSoftBehavior.js',
+      './tests/worker-files/cluster/longRunningWorkerSoftBehavior.cjs',
       {
         errorHandler: e => console.error(e),
         onlineHandler: () => console.info('long executing worker is online'),
@@ -146,10 +146,29 @@ describe('Dynamic cluster pool test suite', () => {
     const pool = new DynamicClusterPool(
       0,
       max,
-      './tests/worker-files/cluster/testWorker.js'
+      './tests/worker-files/cluster/testWorker.cjs'
     )
     expect(pool).toBeInstanceOf(DynamicClusterPool)
     // We need to clean up the resources after our test
     await pool.destroy()
   })
+
+  it.skip('Verify that a pool with zero worker works', async () => {
+    const pool = new DynamicClusterPool(
+      0,
+      max,
+      './tests/worker-files/thread/testWorker.mjs'
+    )
+    expect(pool.starting).toBe(false)
+    expect(pool.workerNodes.length).toBe(pool.info.minSize)
+    const maxMultiplier = 10000
+    const promises = new Set()
+    for (let i = 0; i < max * maxMultiplier; i++) {
+      promises.add(pool.execute())
+    }
+    await Promise.all(promises)
+    expect(pool.workerNodes.length).toBe(max)
+    // We need to clean up the resources after our test
+    await pool.destroy()
+  })
 })