import { EventEmitterAsyncResource } from 'node:events'
+import { dirname, join } from 'node:path'
import { readFileSync } from 'node:fs'
+import { fileURLToPath } from 'node:url'
import { expect } from 'expect'
import { restore, stub } from 'sinon'
import {
import { WorkerNode } from '../../lib/pools/worker-node.js'
describe('Abstract pool test suite', () => {
- const version = JSON.parse(readFileSync('./package.json', 'utf8')).version
+ const version = JSON.parse(
+ readFileSync(
+ join(dirname(fileURLToPath(import.meta.url)), '../../package.json'),
+ 'utf8'
+ )
+ ).version
const numberOfWorkers = 2
class StubPoolWithIsMain extends FixedThreadPool {
isMain () {
-const { TaskFunctions } = require('./test-types')
+const { TaskFunctions } = require('./test-types.js')
const waitWorkerEvents = async (pool, workerEvent, numberOfEventsToWait) => {
return await new Promise(resolve => {
'use strict'
const { ClusterWorker, KillBehaviors } = require('../../../lib')
-const { sleepTaskFunction } = require('../../test-utils')
+const { sleepTaskFunction } = require('../../test-utils.js')
async function error (data) {
return sleepTaskFunction(
'use strict'
const { ClusterWorker, KillBehaviors } = require('../../../lib')
-const { sleepTaskFunction } = require('../../test-utils')
+const { sleepTaskFunction } = require('../../test-utils.js')
async function sleep (data) {
return sleepTaskFunction(data, 2000)
'use strict'
const { ClusterWorker, KillBehaviors } = require('../../../lib')
-const { sleepTaskFunction } = require('../../test-utils')
+const { sleepTaskFunction } = require('../../test-utils.js')
async function sleep (data) {
return sleepTaskFunction(data, 50000)
'use strict'
const { ClusterWorker } = require('../../../lib')
-const { sleepTaskFunction } = require('../../test-utils')
+const { sleepTaskFunction } = require('../../test-utils.js')
async function sleep (data) {
return sleepTaskFunction(data, 50000)
jsonIntegerSerialization,
factorial,
fibonacci
-} = require('../../test-utils')
+} = require('../../test-utils.js')
module.exports = new ClusterWorker(
{
'use strict'
const { ClusterWorker, KillBehaviors } = require('../../../lib')
-const { executeTaskFunction } = require('../../test-utils')
-const { TaskFunctions } = require('../../test-types')
+const { executeTaskFunction } = require('../../test-utils.js')
+const { TaskFunctions } = require('../../test-types.js')
function test (data) {
data = data || {}
/**
*
* @param data
+ * @returns
*/
async function error (data) {
return sleepTaskFunction(
/**
*
* @param data
+ * @returns
*/
async function sleep (data) {
return sleepTaskFunction(data, 2000)
/**
*
* @param data
+ * @returns
*/
function echo (data) {
return data
/**
*
* @param data
+ * @returns
*/
async function sleep (data) {
return sleepTaskFunction(data, 50000)
/**
*
* @param data
+ * @returns
*/
async function sleep (data) {
return sleepTaskFunction(data, 50000)
/**
*
* @param data
+ * @returns
*/
function test (data) {
data = data || {}