How to use terminateAllWorkers method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

cli.js

Source:cli.js Github

copy

Full Screen

...17 client,18 workers = {},19 workerKeys = {},20 tunnelingAgent;21function terminateAllWorkers(callback) {22 logger.trace('terminateAllWorkers');23 var cleanWorker = function(id, key) {24 logger.trace('cleanWorker(%s, %s)', id, key);25 client.terminateWorker(id, function() {26 var worker = workers[key];27 if(worker) {28 logger.debug('[%s] Terminated', worker.string);29 clearTimeout(worker.ackTimeout);30 clearTimeout(worker.activityTimeout);31 clearTimeout(worker.testActivityTimeout);32 delete workers[key];33 delete workerKeys[worker.id];34 }35 if (utils.objectSize(workers) === 0) {36 logger.trace('terminateAllWorkers: done');37 callback();38 }39 });40 };41 if (utils.objectSize(workers) === 0) {42 logger.trace('terminateAllWorkers: done');43 callback();44 } else {45 for (var key in workers){46 var worker = workers[key];47 if (worker.id) {48 cleanWorker(worker.id, key);49 } else {50 delete workers[key];51 if (utils.objectSize(workers) === 0) {52 logger.trace('terminateAllWorkers: done');53 callback();54 }55 }56 }57 }58}59function cleanUpAndExit(signal, error, report, callback) {60 ConfigParser.finalBrowsers = [];61 callback = callback || function() {};62 report = report || [];63 logger.trace('cleanUpAndExit: signal: %s', signal);64 try {65 server.close();66 } catch (e) {67 logger.debug('Server already closed');68 }69 if (statusPoller) {70 statusPoller.stop();71 }72 try {73 process.kill(tunnel.process.pid, 'SIGTERM');74 } catch (e) {75 logger.debug('Non existent tunnel');76 }77 if (signal === 'SIGTERM') {78 logger.debug('Exiting');79 callback(error, report);80 } else {81 terminateAllWorkers(function() {82 logger.debug('Exiting');83 callback(error, report);84 });85 }86}87function getTestBrowserInfo(browserString, path) {88 var info = browserString;89 if (config.multipleTest) {90 info += ', ' + path;91 }92 logger.trace('getTestBrowserInfo(%s, %s): %s', browserString, path, info);93 return info;94}95function buildTestUrl(test_path, worker_key, browser) {...

Full Screen

Full Screen

createWorkers.js

Source:createWorkers.js Github

copy

Full Screen

...90 })91 worker.nodeWorker.once("exit", () => {92 // happens when:93 // - terminate is called due to error when calling worker.postMessage()94 // - terminate is called by terminateAllWorkers()95 // - terminate is called because job is cancelled while worker is executing96 // - terminate is called because worker timeout during execution97 // - There is a runtime error during job excecution98 // -> These cases should be catched by workerMap.has(worker.id)99 // - There is a runtime error during worker execution100 if (workerMap.has(worker.id)) {101 logger.debug(`worker #${worker.id} exited, it's not supposed to happen`)102 forget(worker)103 }104 // the worker emitted an "error" event outside the execution of a job105 // this is not supposed to happen and is used to recognize worker106 // throwing a top level error. In that case we don't want to create107 // an other worker that would also throw108 if (worker.errored) {109 logger.debug(`this worker won't be replace (errored flag is true)`)110 return111 }112 const workerCount = workerMap.size113 if (workerCount >= minWorkers) {114 logger.debug(115 `this worker won't be replaced (there is enough worker already: ${workerCount})`,116 )117 return118 }119 logger.debug("adding a new worker to replace the one who exited")120 addWorker()121 })122 return worker123 }124 const addWorker = () => {125 const newWorker = createWorker()126 tryToGoIdle(newWorker)127 }128 const tryToGoIdle = (worker) => {129 const nextJob = jobsWaitingAnAvailableWorker.shift()130 if (nextJob) {131 assignJobToWorker(nextJob, worker)132 return133 }134 markAsIdle(worker)135 }136 const markAsIdle = (worker) => {137 removeFromArray(busyArray, worker.id)138 idleArray.push(worker.id)139 logger.debug(`worker#${worker.id} marked as "idle"`)140 const workerCount = workerMap.size141 if (142 // keep the min amount of workers alive143 workerCount <= minWorkers ||144 // or if they are allowd to live forever145 maxIdleDuration === Infinity146 ) {147 return148 }149 // this worker was dynamically added, remove it according to maxIdleDuration150 worker.idleKillTimeout = setTimeout(() => {151 logger.debug(152 `killing worker #${worker.id} because idle during more than "maxIdleDuration" (${maxIdleDuration}ms)`,153 )154 kill(worker)155 }, maxIdleDuration)156 worker.idleKillTimeout.unref()157 }158 const addJob = (159 jobData,160 { transferList = [], abortSignal, allocatedMs } = {},161 ) => {162 return new Promise((resolve, reject) => {163 const job = {164 id: jobIdGenerator(),165 data: jobData,166 transferList,167 allocatedMs,168 abortSignal,169 reject,170 resolve,171 }172 logger.debug(`add job#${job.id}`)173 if (abortSignal && abortSignal.aborted) {174 reject(new Error(`job#${job.id} already aborted`))175 return176 }177 if (idleArray.length > 0) {178 logger.debug(`a worker is available for that job`)179 assignJobToWorker(job, workerMap.get(idleArray[0]))180 return181 }182 const workerCount = workerMap.size183 if (workerCount < maxWorkers) {184 logger.debug(`adding a worker for that job`)185 const worker = createWorker()186 assignJobToWorker(job, worker)187 return188 }189 const jobWaitingCount = jobsWaitingAnAvailableWorker.length190 if (jobWaitingCount > maxWaitingJobs) {191 throw new Error(192 `maxWaitingJobs reached (${maxWaitingJobs}), cannot add more job`,193 )194 }195 logger.debug(196 `no worker available for that job -> waiting for an available worker`,197 )198 jobsWaitingAnAvailableWorker.push(job)199 if (abortSignal) {200 const unregisterAbort = registerEventCallback(201 abortSignal,202 "abort",203 () => {204 unregisterAbort()205 removeFromArray(jobsWaitingAnAvailableWorker, job)206 reject(new Error(`job#${job.id} aborted while waiting a worker`))207 },208 )209 job.unregisterAbort = unregisterAbort210 }211 })212 }213 const assignJobToWorker = async (job, worker) => {214 // make worker busy215 clearTimeout(worker.idleKillTimeout)216 removeFromArray(idleArray, worker.id)217 busyArray.push(worker.id)218 job.worker = worker219 worker.job = job220 logger.debug(`job #${job.id} assigned to worker #${worker.id}`)221 // creating an async ressource is important so that Node.js222 // knows we are doing async stuff223 // without this the process sometimes hangs forever224 // https://nodejs.org/dist/latest-v16.x/docs/api/async_context.html#async_context_using_asyncresource_for_a_worker_thread_pool225 const asyncRessource = new AsyncResource(`job#${job.id}`, {226 triggerAsyncId: executionAsyncId(),227 requireManualDestroy: true,228 })229 const resolve = (value) => {230 asyncRessource.runInAsyncScope(() => {}, null, null, value)231 asyncRessource.emitDestroy()232 job.resolve(value)233 }234 const reject = (e) => {235 asyncRessource.runInAsyncScope(() => {}, null, e)236 asyncRessource.emitDestroy()237 job.reject(e)238 }239 let onPostMessageError240 const raceWinnerPromise = raceCallbacks({241 timeout: (cb) => {242 if (!job.allocatedMs) {243 return null244 }245 const timeout = setTimeout(cb, job.allocatedMs)246 return () => {247 clearTimeout(timeout)248 }249 },250 abort: (cb) => {251 if (!job.abortSignal) {252 return null253 }254 // abort now have a new effect: it's not anymore just255 // removing job from "jobsWaitingAnAvailableWorker"256 job.unregisterAbort()257 return registerEventCallback(job.abortSignal, "abort", cb)258 },259 error: (cb) => registerEventCallback(worker.nodeWorker, "error", cb),260 messageerror: (cb) =>261 registerEventCallback(worker.nodeWorker, "messageerror", cb),262 exit: (cb) => registerEventCallback(worker.nodeWorker, "exit", cb),263 message: (cb) => registerEventCallback(worker.nodeWorker, "message", cb),264 postMessageError: (cb) => {265 onPostMessageError = cb266 },267 })268 try {269 worker.nodeWorker.postMessage(job.data, job.transferList)270 } catch (e) {271 onPostMessageError(e) // to ensure other callbacks are removed by raceCallbacks272 }273 const winner = await raceWinnerPromise274 worker.job = null275 const callbacks = {276 // likely postMessageError.name ==="DataCloneError"277 postMessageError: (postMessageError) => {278 worker.job = job279 reject(postMessageError)280 // we call worker.terminate otherwise the process never exits281 kill(worker)282 },283 // uncaught error throw in the worker:284 // - clear timeout285 // - calls job.onError, the job promise will be rejected286 // - worker will be removed by "exit" listener set in "createWorker"287 error: (error) => {288 worker.job = job289 reject(error)290 },291 // Error occured while deserializing a message sent by us to the worker292 // - clear timeout293 // - calls job.onMessageError, the job promise will be rejected294 // - indicate worker is about to be idle295 messageerror: (error) => {296 reject(error)297 tryToGoIdle(worker)298 },299 abort: () => {300 // The worker might be in the middle of something301 // it cannot be reused, we terminate it302 kill(worker)303 reject(new Error(`job#${job.id} aborted during execution by worker`))304 },305 timeout: () => {306 // Same here, worker is in the middle of something, kill it307 kill(worker)308 reject(309 new Error(310 `worker timeout: worker #${job.worker.id} is too slow to perform job #${job.id} (takes more than ${job.allocatedMs} ms)`,311 ),312 )313 },314 // Worker exits before emitting a "message" event, this is unexpected315 // - clear timeout316 // - calls job.onExit, the job promise will be rejected317 // - worker will be removed by "exit" listener set in "createWorker"318 exit: (exitCode) => {319 reject(320 new Error(321 `worker exited: worker #${job.worker.id} exited with code ${exitCode} while performing job #${job.id}.`,322 ),323 )324 },325 // Worker properly respond something326 // - clear timeout327 // - call job.onMessage, the job promise will resolve328 // - indicate worker is about to be idle329 message: (value) => {330 logger.debug(`job #${job.id} completed`)331 resolve(value)332 tryToGoIdle(worker)333 },334 }335 callbacks[winner.name](winner.data)336 }337 const terminateAllWorkers = async () => {338 logger.debug(`terminal all workers`)339 await Promise.allSettled(340 Array.from(workerMap.values()).map(async (worker) => {341 await worker.terminate()342 }),343 )344 }345 let unregisterSIGINT = () => {}346 const destroy = async () => {347 unregisterSIGINT()348 minWorkers = 0 // prevent onWorkerExit() to spawn worker349 maxWorkers = 0 // so that if any code calls addJob, new worker are not spawned350 jobsWaitingAnAvailableWorker.length = 0351 await terminateAllWorkers()352 workerMap.clear() // this is to help garbage collect faster but not required353 }354 if (handleSIGINT) {355 const SIGINTCallback = () => {356 logger.debug(`SIGINT`)357 destroy()358 }359 process.once("SIGINT", SIGINTCallback)360 unregisterSIGINT = () => {361 process.removeListener("SIGINT", SIGINTCallback)362 }363 }364 if (minWorkers > 0) {365 let numberOfWorkerToCreate = Math.ceil(minWorkers)...

Full Screen

Full Screen

mandelbrot-xdk-ww.js

Source:mandelbrot-xdk-ww.js Github

copy

Full Screen

...155 var mw = mWorkers [mWorkerCount-1];156 mw.wworker.postMessage({terminate:true}); 157 mWorkerCount--;158 }159 function terminateAllWorkers() {160 while (mWorkerCount > 0) {161 terminateLastWorker ();162 }163 }164 function numberOfWorkers() {165 return mWorkerCount;166 }167 function bufferOf(worker_index) {168 return mWorkers[worker_index].buffer;169 }170 function workerIsActive(worker_index) {171 return worker_index < mWorkerCount;172 }173 return {...

Full Screen

Full Screen

mandelbrot-ww.js

Source:mandelbrot-ww.js Github

copy

Full Screen

...130 var mw = mWorkers [mWorkerCount-1];131 mw.wworker.postMessage({terminate:true});132 mWorkerCount--;133 }134 function terminateAllWorkers() {135 while (mWorkerCount > 0) {136 terminateLastWorker ();137 }138 }139 function numberOfWorkers() {140 return mWorkerCount;141 }142 function bufferOf(worker_index) {143 return mWorkers[worker_index].buffer;144 }145 function workerIsActive(worker_index) {146 return worker_index < mWorkerCount;147 }148 return {...

Full Screen

Full Screen

mandelbrot-ww-asm.js

Source:mandelbrot-ww-asm.js Github

copy

Full Screen

...125 var mw = mWorkers [mWorkerCount-1];126 mw.wworker.postMessage({terminate:true});127 mWorkerCount--;128 }129 function terminateAllWorkers() {130 while (mWorkerCount > 0) {131 terminateLastWorker ();132 }133 }134 function numberOfWorkers() {135 return mWorkerCount;136 }137 function bufferOf(worker_index) {138 return mWorkers[worker_index].buffer;139 }140 function workerIsActive(worker_index) {141 return worker_index < mWorkerCount;142 }143 return {...

Full Screen

Full Screen

provider_test.js

Source:provider_test.js Github

copy

Full Screen

...119 demand: 10,120 });121 await subject.rejectBids({bids});122 });123 test('.terminateAllWorkers() should work as specified', async () => {124 await subject.terminateAllWorkers();125 });126 test('.terminateWorkerType() should work as specified', async () => {127 await subject.terminateWorkerType({workerType});128 });129 test('.terminateWorker() should work as specified', async () => {130 let [worker] = await subject.listWorkers({131 states: [Provider.running],132 workerTypes: [workerType],133 });134 await subject.terminateWorker({workers: [worker]});135 await subject.terminateWorker({workers: [worker.id]});136 });137 });138}...

Full Screen

Full Screen

manager.js

Source:manager.js Github

copy

Full Screen

...52 this.calculatePI();53 this.callAllUpdateListeners();54 if (this.targetTotalPointCount === this.calculatedPointCount) {55 this.callAllCompleteListeners();56 this.terminateAllWorkers();57 }58 }59 terminateAllWorkers() {60 this.workers.forEach(worker => worker.terminate());61 this.workers = [];62 }63 addNewWorker() {64 const worker = new Worker("./worker.js");65 this.workers.push(worker);66 worker.onmessage = this.workerMessageHandler;67 }68 runWorker(worker, pointWorkLoad) {69 worker.postMessage({ pointWorkLoad });70 }71 runAllWorkers() {72 const pointWorkLoads = this.getPointWorkLoads();73 this.workers.forEach((worker, i) => this.runWorker(worker, pointWorkLoads[i]));...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1"use strict";2Object.defineProperty(exports, "__esModule", { value: true });3exports.terminateAllWorkers = exports.createInitialWorkers = exports.DeferredSourceMapCache = exports.rewriteHtmlJsAsync = exports.rewriteJsAsync = exports.HtmlJsRewriter = void 0;4var html_1 = require("./html");5Object.defineProperty(exports, "HtmlJsRewriter", { enumerable: true, get: function () { return html_1.HtmlJsRewriter; } });6var async_rewriters_1 = require("./async-rewriters");7Object.defineProperty(exports, "rewriteJsAsync", { enumerable: true, get: function () { return async_rewriters_1.rewriteJsAsync; } });8Object.defineProperty(exports, "rewriteHtmlJsAsync", { enumerable: true, get: function () { return async_rewriters_1.rewriteHtmlJsAsync; } });9var deferred_source_map_cache_1 = require("./deferred-source-map-cache");10Object.defineProperty(exports, "DeferredSourceMapCache", { enumerable: true, get: function () { return deferred_source_map_cache_1.DeferredSourceMapCache; } });11var threads_1 = require("./threads");12Object.defineProperty(exports, "createInitialWorkers", { enumerable: true, get: function () { return threads_1.createInitialWorkers; } });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { terminateAllWorkers } = require('fast-check');2terminateAllWorkers();3const { terminateAllWorkers } = require('fast-check');4terminateAllWorkers();5const { terminateAllWorkers } = require('fast-check');6terminateAllWorkers();7const { terminateAllWorkers } = require('fast-check');8terminateAllWorkers();9const { terminateAllWorkers } = require('fast-check');10terminateAllWorkers();11const { terminateAllWorkers } = require('fast-check');12terminateAllWorkers();13const { terminateAllWorkers } = require('fast-check');14terminateAllWorkers();15const { terminateAllWorkers } = require('fast-check');16terminateAllWorkers();17const { terminateAllWorkers } = require('fast-check');18terminateAllWorkers();19const { terminateAllWorkers } = require('fast-check');20terminateAllWorkers();21const { terminateAllWorkers } = require('fast-check');22terminateAllWorkers();23const { terminateAllWorkers } = require('fast-check');24terminateAllWorkers();25const { terminateAllWorkers } = require('fast-check');26terminateAllWorkers();27const { terminateAll

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const { terminateAllWorkers } = require('fast-check-monorepo');3fc.assert(4 fc.property(fc.integer(), fc.integer(), (a, b) => {5 return a + b === b + a;6 })7);8terminateAllWorkers();9{10 "scripts": {11 },12 "dependencies": {13 }14}15 at terminateAllWorkers (C:\Users\user\Documents\test\node_modules\fast-check-monorepo\lib\index.js:6:19)16 at Object.<anonymous> (C:\Users\user\Documents\test\test.js:11:1)17 at Module._compile (internal/modules/cjs/loader.js:1158:30)18 at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)19 at Module.load (internal/modules/cjs/loader.js:1002:32)20 at Function.Module._load (internal/modules/cjs/loader.js:901:14)21 at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require("fast-check");2const { terminateAllWorkers } = require("fast-check/lib/runner/worker");3fc.assert(4 fc.property(fc.integer(), fc.integer(), (a, b) => {5 return a + b === b + a;6 })7);8terminateAllWorkers();9{10 "scripts": {11 },12 "dependencies": {13 }14}

Full Screen

Using AI Code Generation

copy

Full Screen

1const { terminateAllWorkers } = require('fast-check');2terminateAllWorkers();3console.log('Worker terminated');4{5 "scripts": {6 },7 "dependencies": {8 }9}10Recommended Posts: Node.js | child_process.exec() method11Node.js | child_process.fork() method12Node.js | child_process.spawn() method13Node.js | child_process.execFile() method14Node.js | child_process.execSync() method15Node.js | child_process.execFileSync() method16Node.js | child_process.spawnSync() method17Node.js | child_process.spawn() method18Node.js | child_process.exec() method19Node.js | child_process.spawn() method20Node.js | child_process.execFile() method21Node.js | child_process.execSync() method22Node.js | child_process.execFileSync() method23Node.js | child_process.spawnSync() method24Node.js | child_process.spawn() method25Node.js | child_process.exec() method26Node.js | child_process.spawn() method27Node.js | child_process.execFile() method28Node.js | child_process.execSync() method29Node.js | child_process.execFileSync() method30Node.js | child_process.spawnSync() method31Node.js | child_process.spawn() method32Node.js | child_process.exec() method33Node.js | child_process.spawn() method34Node.js | child_process.execFile() method35Node.js | child_process.execSync() method36Node.js | child_process.execFileSync() method37Node.js | child_process.spawnSync() method38Node.js | child_process.spawn() method39Node.js | child_process.exec() method40Node.js | child_process.spawn() method41Node.js | child_process.execFile() method42Node.js | child_process.execSync() method43Node.js | child_process.execFileSync() method44Node.js | child_process.spawnSync() method45Node.js | child_process.spawn() method46Node.js | child_process.exec() method

Full Screen

Using AI Code Generation

copy

Full Screen

1const terminateAllWorkers = require('fast-check-monorepo').terminateAllWorkers;2terminateAllWorkers();3const terminateAllWorkers = require('fast-check-monorepo').terminateAllWorkers;4terminateAllWorkers();5const terminateAllWorkers = require('fast-check-monorepo').terminateAllWorkers;6terminateAllWorkers();7const terminateAllWorkers = require('fast-check-monorepo').terminateAllWorkers;8terminateAllWorkers();9const terminateAllWorkers = require('fast-check-monorepo').terminateAllWorkers;10terminateAllWorkers();11const terminateAllWorkers = require('fast-check-monorepo').terminateAllWorkers;12terminateAllWorkers();13const terminateAllWorkers = require('fast-check-monorepo').terminateAllWorkers;14terminateAllWorkers();15const terminateAllWorkers = require('fast-check-monorepo').terminateAllWorkers;16terminateAllWorkers();17const terminateAllWorkers = require('fast-check-monorepo').terminateAllWorkers;18terminateAllWorkers();

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const { terminateAllWorkers } = require('fast-check/lib/src/fast-check-default');3fc.assert(4 fc.property(fc.integer(), (n) => {5 if (n > 0) {6 return true;7 }8 return false;9 })10);11terminateAllWorkers();12const fc = require('fast-check');13const { terminateAllWorkers } = require('fast-check/lib/src/fast-check-default');14const testFunction = (param1, param2, param3) => {15 return new Promise((resolve, reject) => {16 if (param1 === 'test') {17 resolve('test');18 } else {19 reject('error');20 }21 });22}23fc.assert(24 fc.property(fc.string(), fc.string(), fc.string(), (param1, param2, param3) => {25 return testFunction(param1, param2, param3).then((result) => {26 return true;27 }, (err) => {28 return false;29 });30 })31);32terminateAllWorkers();33const fc = require('fast-check');34const { terminateAllWorkers } = require('fast-check/lib/src/fast-check-default');35const testFunction = (param1, param2, param3) => {36 return new Promise((resolve, reject) => {37 if (param1 === 'test') {38 resolve('test');39 } else {

Full Screen

Using AI Code Generation

copy

Full Screen

1import { terminateAllWorkers } from 'fast-check-monorepo';2terminateAllWorkers();3"scripts": {4 },5"scripts": {6 },7"scripts": {8 },9"scripts": {10 },11"scripts": {12 },13"scripts": {14 },15"scripts": {16 },17"scripts": {18 },19"scripts": {20 },21"scripts": {22 },23"scripts": {24 },

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fast-check-monorepo automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful