From: Jérôme Benoit Date: Fri, 7 Jul 2023 22:37:57 +0000 (+0200) Subject: test: cleanup worker functions return X-Git-Tag: v2.6.10~11 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=30b963d47336380d1878a1feb1bc87f616e0fec6;p=poolifier.git test: cleanup worker functions return Signed-off-by: Jérôme Benoit --- diff --git a/benchmarks/benchmarks-utils.mjs b/benchmarks/benchmarks-utils.mjs index 48d5e41b..c88ada12 100644 --- a/benchmarks/benchmarks-utils.mjs +++ b/benchmarks/benchmarks-utils.mjs @@ -51,6 +51,7 @@ const jsonIntegerSerialization = n => { } JSON.stringify(o) } + return { ok: 1 } } /** @@ -94,6 +95,7 @@ const readWriteFiles = ( fs.readFileSync(filePath, 'utf8') } fs.rmSync(baseDirectory, { recursive: true }) + return { ok: 1 } } export const executeWorkerFunction = data => { diff --git a/benchmarks/internal/cluster-worker.mjs b/benchmarks/internal/cluster-worker.mjs index e8d16d21..2ec78054 100644 --- a/benchmarks/internal/cluster-worker.mjs +++ b/benchmarks/internal/cluster-worker.mjs @@ -8,9 +8,9 @@ const debug = false function workerFunction (data) { data = data || {} data.function = data.function || WorkerFunctions.jsonIntegerSerialization - executeWorkerFunction(data) + const res = executeWorkerFunction(data) debug === true && console.debug('This is the main thread ' + isMaster) - return { ok: 1 } + return res } export default new ClusterWorker(workerFunction) diff --git a/benchmarks/internal/thread-worker.mjs b/benchmarks/internal/thread-worker.mjs index c1cd0141..88d57670 100644 --- a/benchmarks/internal/thread-worker.mjs +++ b/benchmarks/internal/thread-worker.mjs @@ -8,9 +8,9 @@ const debug = false function workerFunction (data) { data = data || {} data.function = data.function || WorkerFunctions.jsonIntegerSerialization - executeWorkerFunction(data) + const res = executeWorkerFunction(data) debug === true && console.debug('This is the main thread ' + isMainThread) - return { ok: 1 } + return res } export default new ThreadWorker(workerFunction) diff --git a/tests/pools/abstract/abstract-pool.test.js b/tests/pools/abstract/abstract-pool.test.js index da870774..0e31ad5c 100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@ -711,9 +711,9 @@ describe('Abstract pool test suite', () => { ) const data = { n: 10 } const result0 = await pool.execute(data) - expect(result0).toBe(false) + expect(result0).toStrictEqual({ ok: 1 }) const result1 = await pool.execute(data, 'jsonIntegerSerialization') - expect(result1).toBe(false) + expect(result1).toStrictEqual({ ok: 1 }) const result2 = await pool.execute(data, 'factorial') expect(result2).toBe(3628800) const result3 = await pool.execute(data, 'fibonacci') diff --git a/tests/pools/cluster/dynamic.test.js b/tests/pools/cluster/dynamic.test.js index 753f59af..bd405a77 100644 --- a/tests/pools/cluster/dynamic.test.js +++ b/tests/pools/cluster/dynamic.test.js @@ -77,7 +77,7 @@ describe('Dynamic cluster pool test suite', () => { './tests/worker-files/cluster/testWorker.js' ) const result = await pool1.execute() - expect(result).toBe(false) + expect(result).toStrictEqual({ ok: 1 }) // We need to clean up the resources after our test await pool1.destroy() }) diff --git a/tests/pools/cluster/fixed.test.js b/tests/pools/cluster/fixed.test.js index 48455f18..a0331317 100644 --- a/tests/pools/cluster/fixed.test.js +++ b/tests/pools/cluster/fixed.test.js @@ -74,7 +74,7 @@ describe('Fixed cluster pool test suite', () => { it('Verify that is possible to invoke the execute() method without input', async () => { const result = await pool.execute() - expect(result).toBe(false) + expect(result).toStrictEqual({ ok: 1 }) }) it("Verify that 'busy' event is emitted", async () => { @@ -230,7 +230,7 @@ describe('Fixed cluster pool test suite', () => { './tests/worker-files/cluster/testWorker.js' ) const res = await pool1.execute() - expect(res).toBe(false) + expect(res).toStrictEqual({ ok: 1 }) // We need to clean up the resources after our test await pool1.destroy() }) diff --git a/tests/pools/thread/dynamic.test.js b/tests/pools/thread/dynamic.test.js index 65d16239..56847302 100644 --- a/tests/pools/thread/dynamic.test.js +++ b/tests/pools/thread/dynamic.test.js @@ -77,7 +77,7 @@ describe('Dynamic thread pool test suite', () => { './tests/worker-files/thread/testWorker.js' ) const res = await pool1.execute() - expect(res).toBe(false) + expect(res).toStrictEqual({ ok: 1 }) // We need to clean up the resources after our test await pool1.destroy() }) diff --git a/tests/pools/thread/fixed.test.js b/tests/pools/thread/fixed.test.js index 45197cba..a94745e3 100644 --- a/tests/pools/thread/fixed.test.js +++ b/tests/pools/thread/fixed.test.js @@ -74,7 +74,7 @@ describe('Fixed thread pool test suite', () => { it('Verify that is possible to invoke the execute() method without input', async () => { const result = await pool.execute() - expect(result).toBe(false) + expect(result).toStrictEqual({ ok: 1 }) }) it("Verify that 'busy' event is emitted", async () => { @@ -229,7 +229,7 @@ describe('Fixed thread pool test suite', () => { './tests/worker-files/thread/testWorker.js' ) const res = await pool1.execute() - expect(res).toBe(false) + expect(res).toStrictEqual({ ok: 1 }) // We need to clean up the resources after our test await pool1.destroy() }) diff --git a/tests/test-utils.js b/tests/test-utils.js index ba5e652d..1fd59942 100644 --- a/tests/test-utils.js +++ b/tests/test-utils.js @@ -72,6 +72,7 @@ const jsonIntegerSerialization = n => { } JSON.stringify(o) } + return { ok: 1 } } /** diff --git a/tests/worker-files/cluster/testMultiTasksWorker.js b/tests/worker-files/cluster/testMultiTasksWorker.js index 692a2e76..62b640fb 100644 --- a/tests/worker-files/cluster/testMultiTasksWorker.js +++ b/tests/worker-files/cluster/testMultiTasksWorker.js @@ -1,5 +1,4 @@ 'use strict' -const { isMaster } = require('cluster') const { ClusterWorker, KillBehaviors } = require('../../../lib') const { jsonIntegerSerialization, @@ -9,10 +8,7 @@ const { module.exports = new ClusterWorker( { - jsonIntegerSerialization: data => { - jsonIntegerSerialization(data.n) - return isMaster - }, + jsonIntegerSerialization: data => jsonIntegerSerialization(data.n), factorial: data => factorial(data.n), fibonacci: data => fibonacci(data.n) }, diff --git a/tests/worker-files/cluster/testWorker.js b/tests/worker-files/cluster/testWorker.js index e79a2102..25774bb2 100644 --- a/tests/worker-files/cluster/testWorker.js +++ b/tests/worker-files/cluster/testWorker.js @@ -1,5 +1,4 @@ 'use strict' -const { isMaster } = require('cluster') const { ClusterWorker, KillBehaviors } = require('../../../lib') const { executeWorkerFunction } = require('../../test-utils') const { WorkerFunctions } = require('../../test-types') @@ -7,11 +6,7 @@ const { WorkerFunctions } = require('../../test-types') function test (data) { data = data || {} data.function = data.function || WorkerFunctions.jsonIntegerSerialization - const result = executeWorkerFunction(data) - if (result == null) { - return isMaster - } - return result + return executeWorkerFunction(data) } module.exports = new ClusterWorker(test, { diff --git a/tests/worker-files/thread/testMultiTasksWorker.js b/tests/worker-files/thread/testMultiTasksWorker.js index da357a2a..ace9fea0 100644 --- a/tests/worker-files/thread/testMultiTasksWorker.js +++ b/tests/worker-files/thread/testMultiTasksWorker.js @@ -1,5 +1,4 @@ 'use strict' -const { isMainThread } = require('worker_threads') const { ThreadWorker, KillBehaviors } = require('../../../lib') const { jsonIntegerSerialization, @@ -9,10 +8,7 @@ const { module.exports = new ThreadWorker( { - jsonIntegerSerialization: data => { - jsonIntegerSerialization(data.n) - return isMainThread - }, + jsonIntegerSerialization: data => jsonIntegerSerialization(data.n), factorial: data => factorial(data.n), fibonacci: data => fibonacci(data.n) }, diff --git a/tests/worker-files/thread/testWorker.js b/tests/worker-files/thread/testWorker.js index 349336e5..5779e231 100644 --- a/tests/worker-files/thread/testWorker.js +++ b/tests/worker-files/thread/testWorker.js @@ -1,5 +1,4 @@ 'use strict' -const { isMainThread } = require('worker_threads') const { ThreadWorker, KillBehaviors } = require('../../../lib') const { executeWorkerFunction } = require('../../test-utils') const { WorkerFunctions } = require('../../test-types') @@ -7,11 +6,7 @@ const { WorkerFunctions } = require('../../test-types') function test (data) { data = data || {} data.function = data.function || WorkerFunctions.jsonIntegerSerialization - const result = executeWorkerFunction(data) - if (result == null) { - return isMainThread - } - return result + return executeWorkerFunction(data) } module.exports = new ThreadWorker(test, {