Merge pull request #153 from pioardi/add-worker-test
[poolifier.git] / tests / pools / cluster / dynamic.test.js
index e0a0fde3cc6246bf662cc656851bbf78f32abcde..01b720720ac4761a768645b329d3cdb00a93283e 100644 (file)
@@ -5,7 +5,7 @@ const max = 3
 const pool = new DynamicClusterPool(
   min,
   max,
-  './tests/worker/cluster/testWorker.js',
+  './tests/worker-files/cluster/testWorker.js',
   {
     errorHandler: e => console.error(e)
   }
@@ -81,16 +81,33 @@ describe('Dynamic cluster pool test suite ', () => {
     const pool1 = new DynamicClusterPool(
       1,
       1,
-      './tests/worker/cluster/testWorker.js'
+      './tests/worker-files/cluster/testWorker.js'
     )
     const res = await pool1.execute({ test: 'test' })
     expect(res).toBeFalsy()
   })
-  it('Verify scale processes up and down is working when long running task is used', async () => {
+
+  it('Verify scale processes up and down is working when long running task is used:hard', async () => {
+    const longRunningPool = new DynamicClusterPool(
+      min,
+      max,
+      './tests/worker/cluster/longRunningWorkerHardBehavior.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, 3000))
+    // Here we expect the workers to be at the max size since that the task is still running
+    expect(longRunningPool.workers.length).toBe(min)
+  })
+
+  it('Verify scale processes up and down is working when long running task is used:soft', async () => {
     const longRunningPool = new DynamicClusterPool(
       min,
       max,
-      './tests/worker/cluster/longRunningWorker.js'
+      './tests/worker/cluster/longRunningWorkerSoftBehavior.js'
     )
     expect(longRunningPool.workers.length).toBe(min)
     for (let i = 0; i < max * 10; i++) {