repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
build(deps-dev): bump @types/node
[poolifier.git]
/
tests
/
test-utils.js
diff --git
a/tests/test-utils.js
b/tests/test-utils.js
index 0014a7911cf587e876aa817f43155c4de00ffb51..3234a6a22cb3af039b81494520178a996a95d9f3 100644
(file)
--- a/
tests/test-utils.js
+++ b/
tests/test-utils.js
@@
-1,7
+1,7
@@
-const {
Worker
Functions } = require('./test-types')
+const {
Task
Functions } = require('./test-types')
const waitWorkerEvents = async (pool, workerEvent, numberOfEventsToWait) => {
const waitWorkerEvents = async (pool, workerEvent, numberOfEventsToWait) => {
- return new Promise(
resolve
=> {
+ return new Promise(
(resolve)
=> {
let events = 0
if (numberOfEventsToWait === 0) {
resolve(events)
let events = 0
if (numberOfEventsToWait === 0) {
resolve(events)
@@
-18,12
+18,12
@@
const waitWorkerEvents = async (pool, workerEvent, numberOfEventsToWait) => {
}
const waitPoolEvents = async (pool, poolEvent, numberOfEventsToWait) => {
}
const waitPoolEvents = async (pool, poolEvent, numberOfEventsToWait) => {
- return new Promise(
resolve
=> {
+ return new Promise(
(resolve)
=> {
let events = 0
if (numberOfEventsToWait === 0) {
resolve(events)
}
let events = 0
if (numberOfEventsToWait === 0) {
resolve(events)
}
- pool.emitter.on(poolEvent, () => {
+ pool.emitter
?
.on(poolEvent, () => {
++events
if (events === numberOfEventsToWait) {
resolve(events)
++events
if (events === numberOfEventsToWait) {
resolve(events)
@@
-32,11
+32,11
@@
const waitPoolEvents = async (pool, poolEvent, numberOfEventsToWait) => {
})
}
})
}
-const sleep = async
ms
=> {
- return new Promise(
resolve
=> setTimeout(resolve, ms))
+const sleep = async
(ms)
=> {
+ return new Promise(
(resolve)
=> setTimeout(resolve, ms))
}
}
-const sleep
Worker
Function = async (
+const sleep
Task
Function = async (
data,
ms,
rejection = false,
data,
ms,
rejection = false,
@@
-65,13
+65,14
@@
const generateRandomInteger = (max = Number.MAX_SAFE_INTEGER, min = 0) => {
return Math.floor(Math.random() * (max + 1))
}
return Math.floor(Math.random() * (max + 1))
}
-const jsonIntegerSerialization =
n
=> {
+const jsonIntegerSerialization =
(n)
=> {
for (let i = 0; i < n; i++) {
const o = {
a: i
}
JSON.stringify(o)
}
for (let i = 0; i < n; i++) {
const o = {
a: i
}
JSON.stringify(o)
}
+ return { ok: 1 }
}
/**
}
/**
@@
-79,7
+80,7
@@
const jsonIntegerSerialization = n => {
* @param {number} n - The number of fibonacci numbers to generate.
* @returns {number} - The nth fibonacci number.
*/
* @param {number} n - The number of fibonacci numbers to generate.
* @returns {number} - The nth fibonacci number.
*/
-const fibonacci =
n
=> {
+const fibonacci =
(n)
=> {
if (n <= 1) return n
return fibonacci(n - 1) + fibonacci(n - 2)
}
if (n <= 1) return n
return fibonacci(n - 1) + fibonacci(n - 2)
}
@@
-89,20
+90,20
@@
const fibonacci = n => {
* @param {number} n - The number to calculate the factorial of.
* @returns {number} - The factorial of n.
*/
* @param {number} n - The number to calculate the factorial of.
* @returns {number} - The factorial of n.
*/
-const factorial =
n
=> {
+const factorial =
(n)
=> {
if (n === 0) {
return 1
}
return factorial(n - 1) * n
}
if (n === 0) {
return 1
}
return factorial(n - 1) * n
}
-const execute
WorkerFunction = data
=> {
+const execute
TaskFunction = (data)
=> {
switch (data.function) {
switch (data.function) {
- case
Worker
Functions.jsonIntegerSerialization:
+ case
Task
Functions.jsonIntegerSerialization:
return jsonIntegerSerialization(data.n || 100)
return jsonIntegerSerialization(data.n || 100)
- case
Worker
Functions.fibonacci:
+ case
Task
Functions.fibonacci:
return fibonacci(data.n || 25)
return fibonacci(data.n || 25)
- case
Worker
Functions.factorial:
+ case
Task
Functions.factorial:
return factorial(data.n || 100)
default:
throw new Error('Unknown worker function')
return factorial(data.n || 100)
default:
throw new Error('Unknown worker function')
@@
-110,13
+111,13
@@
const executeWorkerFunction = data => {
}
module.exports = {
}
module.exports = {
- execute
Worker
Function,
+ execute
Task
Function,
factorial,
fibonacci,
generateRandomInteger,
jsonIntegerSerialization,
sleep,
factorial,
fibonacci,
generateRandomInteger,
jsonIntegerSerialization,
sleep,
- sleep
Worker
Function,
- wait
Worker
Events,
- wait
Pool
Events
+ sleep
Task
Function,
+ wait
Pool
Events,
+ wait
Worker
Events
}
}