X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Fcluster%2Fdynamic.test.js;h=b45b7ccac91308fcb1fe5193f0ffa3ea8d882b60;hb=eb3b4c1592abc3f91acfe98c236a02ca994febff;hp=024e26707e66900f3844256334142272888059d3;hpb=c01733f14c19a0aabef6f310f29691912942d55c;p=poolifier.git diff --git a/tests/pools/cluster/dynamic.test.js b/tests/pools/cluster/dynamic.test.js index 024e2670..b45b7cca 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) }) @@ -87,18 +86,35 @@ describe('Dynamic cluster pool test suite ', () => { 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/thread/longRunningWorker.js' + './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, 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(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/longRunningWorkerSoftBehavior.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(max) })