}
JSON.stringify(o)
}
+ return { ok: 1 }
}
/**
fs.readFileSync(filePath, 'utf8')
}
fs.rmSync(baseDirectory, { recursive: true })
+ return { ok: 1 }
}
export const executeWorkerFunction = data => {
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)
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)
)
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')
'./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()
})
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 () => {
'./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()
})
'./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()
})
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 () => {
'./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()
})
}
JSON.stringify(o)
}
+ return { ok: 1 }
}
/**
'use strict'
-const { isMaster } = require('cluster')
const { ClusterWorker, KillBehaviors } = require('../../../lib')
const {
jsonIntegerSerialization,
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)
},
'use strict'
-const { isMaster } = require('cluster')
const { ClusterWorker, KillBehaviors } = require('../../../lib')
const { executeWorkerFunction } = require('../../test-utils')
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, {
'use strict'
-const { isMainThread } = require('worker_threads')
const { ThreadWorker, KillBehaviors } = require('../../../lib')
const {
jsonIntegerSerialization,
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)
},
'use strict'
-const { isMainThread } = require('worker_threads')
const { ThreadWorker, KillBehaviors } = require('../../../lib')
const { executeWorkerFunction } = require('../../test-utils')
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, {