repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge dependabot/npm_and_yarn/examples/typescript/websocket-server-pool/ws-hybrid...
[poolifier.git]
/
tests
/
test-utils.js
diff --git
a/tests/test-utils.js
b/tests/test-utils.js
index 67d10e4a93e690c3cd70f6fc3d2e63641f91ff83..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,7
+18,7
@@
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)
@@
-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,7
+65,7
@@
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
for (let i = 0; i < n; i++) {
const o = {
a: i
@@
-80,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)
}
@@
-90,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')
@@
-111,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,
+ sleep
Task
Function,
waitPoolEvents,
waitWorkerEvents
}
waitPoolEvents,
waitWorkerEvents
}