X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fdynamic.test.js;h=e8be74ace413c874a008dbd846c2ec98811d46cb;hb=93954d0a3cb73d3626b521457f34fb2f1c12d4b2;hp=7c5eec12e8b0496e3f3a3c9fbc0ba11cc08d0abc;hpb=b755d5beab080feedc652bac13e376b902321040;p=poolifier.git diff --git a/tests/dynamic.test.js b/tests/dynamic.test.js index 7c5eec12..e8be74ac 100644 --- a/tests/dynamic.test.js +++ b/tests/dynamic.test.js @@ -1,9 +1,9 @@ const expect = require('expect') const DynamicThreadPool = require('../lib/dynamic') const min = 1 -const max = 10 +const max = 3 const pool = new DynamicThreadPool(min, max, - './tests/testWorker.js', + './tests/workers/testWorker.js', { errorHandler: (e) => console.error(e), onlineHandler: () => console.log('worker is online') }) describe('Dynamic thread pool test suite ', () => { @@ -18,7 +18,7 @@ describe('Dynamic thread pool test suite ', () => { let closedThreads = 0 let fullPool = 0 pool.emitter.on('FullPool', () => fullPool++) - for (let i = 0; i < (max * 3); i++) { + for (let i = 0; i < (max * 2); i++) { promises.push(pool.execute({ test: 'test' })) } expect(pool.workers.length).toBe(max) @@ -28,7 +28,7 @@ describe('Dynamic thread pool test suite ', () => { }) }) expect(fullPool > 1).toBeTruthy() - await new Promise(resolve => setTimeout(resolve, 1000 * 2)) + await new Promise(resolve => setTimeout(resolve, 2000)) expect(closedThreads).toBe(max - min) }) @@ -39,8 +39,7 @@ describe('Dynamic thread pool test suite ', () => { closedThreads++ }) }) - pool.destroy() - await new Promise(resolve => setTimeout(resolve, 1000)) + await pool.destroy() expect(closedThreads).toBe(min) }) @@ -57,7 +56,7 @@ describe('Dynamic thread pool test suite ', () => { }) it('Should work even without opts in input', async () => { - const pool1 = new DynamicThreadPool(1, 1, './tests/testWorker.js') + const pool1 = new DynamicThreadPool(1, 1, './tests/workers/testWorker.js') const res = await pool1.execute({ test: 'test' }) expect(res).toBeFalsy() })