How to use initWorker1Task method in stryker-parent

Best JavaScript code snippet using stryker-parent

pool.spec.ts

Source:pool.spec.ts Github

copy

Full Screen

1import { expect } from 'chai';2import { toArray } from 'rxjs/operators';3import sinon from 'sinon';4import { factory, tick } from '@stryker-mutator/test-helpers';5import { Task, ExpirableTask } from '@stryker-mutator/util';6import { lastValueFrom, range, ReplaySubject } from 'rxjs';7import { Pool, Resource } from '../../../src/concurrent';8describe(Pool.name, () => {9 let worker1: sinon.SinonStubbedInstance<Required<Resource>>;10 let worker2: sinon.SinonStubbedInstance<Required<Resource>>;11 let genericWorkerForAllSubsequentCreates: sinon.SinonStubbedInstance<Required<Resource>>;12 let createWorkerStub: sinon.SinonStub;13 let concurrencyToken$: ReplaySubject<number>;14 let sut: Pool<Required<Resource>>;15 beforeEach(() => {16 concurrencyToken$ = new ReplaySubject();17 worker1 = factory.testRunner();18 worker2 = factory.testRunner();19 genericWorkerForAllSubsequentCreates = factory.testRunner();20 createWorkerStub = sinon.stub();21 });22 afterEach(() => {23 concurrencyToken$.complete();24 sut.dispose();25 });26 function arrangeWorkers() {27 createWorkerStub.returns(genericWorkerForAllSubsequentCreates).onCall(0).returns(worker1).onCall(1).returns(worker2);28 }29 function createSut() {30 return new Pool<Required<Resource>>(createWorkerStub, concurrencyToken$);31 }32 function setConcurrency(n: number) {33 Array.from({ length: n }).forEach((_, i) => concurrencyToken$.next(i));34 }35 describe('schedule', () => {36 it("should create 2 workers at a time (for performance reasons, we don't to overwhelm the device)", async () => {37 // Arrange38 arrangeWorkers();39 setConcurrency(3);40 const initWorker1Task = new Task<void>();41 const initWorker2Task = new Task<void>();42 const initWorker3Task = new Task<void>();43 worker1.init.returns(initWorker1Task.promise);44 worker2.init.returns(initWorker2Task.promise);45 genericWorkerForAllSubsequentCreates.init.returns(initWorker3Task.promise);46 sut = createSut();47 const actualWorkers: Array<Required<Resource>> = [];48 // Act49 const onGoingTask = lastValueFrom(sut.schedule(range(0, 3), async (worker) => actualWorkers.push(worker)));50 // Assert51 expect(actualWorkers).lengthOf(0);52 expect(createWorkerStub).callCount(2);53 initWorker1Task.resolve();54 initWorker2Task.resolve();55 initWorker3Task.resolve();56 await tick(2);57 await sut.dispose();58 expect(actualWorkers).lengthOf(3);59 await onGoingTask;60 });61 it('should eventually create all workers', async () => {62 arrangeWorkers();63 setConcurrency(8);64 sut = createSut();65 const result = await captureWorkers(sut, 8);66 expect(result).lengthOf(8);67 expect(result).deep.eq([68 worker1,69 worker2,70 genericWorkerForAllSubsequentCreates,71 genericWorkerForAllSubsequentCreates,72 genericWorkerForAllSubsequentCreates,73 genericWorkerForAllSubsequentCreates,74 genericWorkerForAllSubsequentCreates,75 genericWorkerForAllSubsequentCreates,76 ]);77 });78 it("should reject when a worker couldn't be created", async () => {79 setConcurrency(1);80 const expectedError = new Error('foo error');81 createWorkerStub.throws(expectedError);82 sut = createSut();83 await expect(captureWorkers(sut, 1)).rejectedWith(expectedError);84 });85 it('should share workers across subscribers (for sharing between dry runner and mutation test runner)', async () => {86 // Arrange87 setConcurrency(2);88 arrangeWorkers();89 sut = createSut();90 // Act91 const firstResult = await lastValueFrom(sut.schedule(range(0, 2), (worker) => worker).pipe(toArray()));92 const secondResult = await lastValueFrom(sut.schedule(range(0, 2), (worker) => worker).pipe(toArray()));93 // Assert94 await sut.dispose();95 expect(firstResult).lengthOf(2);96 expect(secondResult).lengthOf(2);97 expect(firstResult[0]).eq(secondResult[0]);98 expect(firstResult[1]).eq(secondResult[1]);99 });100 it('should re-emit the presented worker in the stream', async () => {101 // Arrange102 arrangeWorkers();103 setConcurrency(2);104 const actualScheduledWork: Array<[number, Required<Resource>]> = [];105 sut = createSut();106 const onGoingWork = lastValueFrom(107 sut108 .schedule(range(0, 3), async (worker, input) => {109 await tick();110 actualScheduledWork.push([input, worker]);111 })112 .pipe(toArray())113 );114 await tick(3);115 // Act116 await sut.dispose();117 // Assert118 expect(actualScheduledWork).lengthOf(3);119 expect(actualScheduledWork).deep.eq([120 [0, worker1],121 [1, worker2],122 [2, worker1],123 ]);124 await onGoingWork;125 });126 });127 describe('init', () => {128 it('should await the init() of all workers', async () => {129 // Arrange130 arrangeWorkers();131 setConcurrency(2);132 const initWorker2Task = new Task<void>();133 worker2.init.returns(initWorker2Task.promise);134 worker1.init.resolves();135 sut = createSut();136 // Act137 const timeoutResult = await ExpirableTask.timeout(sut.init(), 20);138 initWorker2Task.resolve();139 concurrencyToken$.complete();140 await sut.init();141 // Assert142 expect(timeoutResult).eq(ExpirableTask.TimeoutExpired);143 expect(worker1.init).called;144 expect(worker2.init).called;145 });146 it('should cache the workers for later use', async () => {147 // Arrange148 arrangeWorkers();149 setConcurrency(1);150 sut = createSut();151 concurrencyToken$.complete();152 // Act153 await sut.init();154 await sut.init();155 const allWorkers = await captureWorkers(sut, 1);156 // Assert157 expect(createWorkerStub).calledOnce;158 expect(allWorkers[0]).eq(worker1);159 });160 it('should await for all concurrency tokens to be delivered', async () => {161 // Arrange162 arrangeWorkers();163 setConcurrency(2);164 const actualWorkers: Array<Required<Resource>> = [];165 sut = createSut();166 const onGoingScheduledWork = lastValueFrom(sut.schedule(range(0, 2), (worker) => actualWorkers.push(worker)));167 // Act168 const timeoutResult = await ExpirableTask.timeout(sut.init(), 20);169 concurrencyToken$.complete();170 // Assert171 expect(timeoutResult).eq(ExpirableTask.TimeoutExpired);172 expect(actualWorkers).lengthOf(2);173 await sut.init();174 await onGoingScheduledWork;175 });176 it('should reject when a worker rejects', async () => {177 // Arrange178 arrangeWorkers();179 setConcurrency(2);180 const expectedError = new Error('expected error');181 worker2.init.rejects(expectedError);182 sut = createSut();183 // Act & Assert184 await expect(sut.init()).rejectedWith(expectedError);185 concurrencyToken$.complete();186 });187 });188 describe('dispose', () => {189 it('should have disposed all testRunners', async () => {190 setConcurrency(8);191 arrangeWorkers();192 sut = createSut();193 await captureWorkers(sut, 9);194 await sut.dispose();195 expect(worker1.dispose).called;196 expect(worker2.dispose).called;197 expect(genericWorkerForAllSubsequentCreates.dispose).called;198 });199 it('should not do anything if no workers were created', async () => {200 sut = createSut();201 await sut.dispose();202 expect(worker1.dispose).not.called;203 expect(worker2.dispose).not.called;204 });205 it('should not resolve when there are still workers being initialized (issue #713)', async () => {206 // Arrange207 arrangeWorkers();208 setConcurrency(2);209 const task = new Task<void>();210 const task2 = new Task<void>();211 worker1.init.returns(task.promise);212 worker2.init.returns(task2.promise);213 sut = createSut();214 // Act215 const resultPromise = lastValueFrom(sut.schedule(range(0, 2), (worker) => worker).pipe(toArray()));216 task.resolve();217 await sut.dispose();218 task2.resolve();219 concurrencyToken$.complete();220 await resultPromise;221 expect(worker1.dispose).called;222 expect(worker2.dispose).called;223 });224 it('should halt creating of new sandboxes', async () => {225 // Arrange226 arrangeWorkers();227 setConcurrency(3);228 const task = new Task<void>();229 const task2 = new Task<void>();230 worker1.init.returns(task.promise);231 worker2.init.returns(task2.promise);232 sut = createSut();233 // Act234 const actualTestRunnersPromise = lastValueFrom(sut.schedule(range(0, 3), (worker) => worker).pipe(toArray()));235 const disposePromise = sut.dispose();236 task.resolve();237 task2.resolve();238 await disposePromise;239 concurrencyToken$.complete();240 await actualTestRunnersPromise;241 // Assert242 expect(createWorkerStub).calledTwice;243 });244 });245 async function captureWorkers(suite: Pool<Required<Resource>>, inputCount: number) {246 // Eagerly get all test runners247 const createAllPromise = lastValueFrom(248 suite249 .schedule(range(0, inputCount), async (worker) => {250 await tick();251 return worker;252 })253 .pipe(toArray())254 );255 // But don't await yet, until after dispose.256 // Allow processes to be created257 await tick(inputCount);258 // Dispose completes the internal recycle bin subject, which in turn will complete.259 await suite.dispose();260 concurrencyToken$.complete();261 return createAllPromise;262 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { initWorker1Task } = require('stryker-parent');2initWorker1Task();3const { initWorker2Task } = require('stryker-parent');4initWorker2Task();5const { initWorker3Task } = require('stryker-parent');6initWorker3Task();7const { initWorker4Task } = require('stryker-parent');8initWorker4Task();9const { initWorker1Task } = require('stryker-parent');10initWorker1Task();11const { initWorker2Task } = require('stryker-parent');12initWorker2Task();13const { initWorker3Task } = require('stryker-parent');14initWorker3Task();15const { initWorker4Task } = require('stryker-parent');16initWorker4Task();17const { initWorker1Task } = require('stryker-parent');18initWorker1Task();19const { initWorker2Task } = require('stryker-parent');20initWorker2Task();21const { initWorker3Task } = require('stryker-parent');22initWorker3Task();23const { initWorker4Task } = require('stryker-parent');24initWorker4Task();25const { initWorker1Task } = require('stryker-parent');26initWorker1Task();27const { initWorker2Task } = require('stryker-parent');28initWorker2Task();29const {

Full Screen

Using AI Code Generation

copy

Full Screen

1const stryker = require('stryker-parent');2const worker = stryker.initWorker1Task();3const stryker = require('stryker-parent');4const worker = stryker.initWorker2Task();5const stryker = require('stryker-parent');6const worker = stryker.initWorker3Task();7const stryker = require('stryker-parent');8const worker = stryker.initWorker4Task();9const stryker = require('stryker-parent');10const worker = stryker.initWorker5Task();11const stryker = require('stryker-parent');12const worker = stryker.initWorker6Task();13const stryker = require('stryker-parent');14const worker = stryker.initWorker7Task();15const stryker = require('stryker-parent');16const worker = stryker.initWorker8Task();17const stryker = require('stryker-parent');18const worker = stryker.initWorker9Task();19const stryker = require('stryker-parent');20const worker = stryker.initWorker10Task();21const stryker = require('stryker-parent');22const worker = stryker.initWorker11Task();23const stryker = require('stryker-parent');24const worker = stryker.initWorker12Task();25const stryker = require('stryker-parent');26const worker = stryker.initWorker13Task();27const stryker = require('stryker-parent');

Full Screen

Using AI Code Generation

copy

Full Screen

1var stryker = require('stryker-parent');2stryker.initWorker1Task('test1.js');3var stryker = require('stryker-parent');4stryker.initWorker2Task('test2.js');5var stryker = require('stryker-parent');6stryker.initWorker1Task('test1.js');7var stryker = require('stryker-parent');8stryker.initWorker2Task('test2.js');9var stryker = require('stryker-parent');10stryker.initWorker1Task('test1.js');11var stryker = require('stryker-parent');12stryker.initWorker2Task('test2.js');13var stryker = require('stryker-parent');14stryker.initWorker1Task('test1.js');15var stryker = require('stryker-parent');16stryker.initWorker2Task('test2.js');17var stryker = require('stryker-parent');18stryker.initWorker1Task('test1.js');19var stryker = require('stryker-parent');20stryker.initWorker2Task('test2.js');21var stryker = require('stryker-parent');22stryker.initWorker1Task('test1.js');23var stryker = require('stryker-parent');24stryker.initWorker2Task('test2.js');25var stryker = require('stryker-parent');

Full Screen

Using AI Code Generation

copy

Full Screen

1const strykerParent = require('stryker-parent');2const myWorker = strykerParent.initWorker1Task();3const strykerParent = require('stryker-parent');4const myWorker = strykerParent.initWorker2Task();5const strykerParent = require('stryker-parent');6const myWorker = strykerParent.initWorker3Task();7const strykerParent = require('stryker-parent');8const myWorker = strykerParent.initWorker4Task();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { initWorker1Task } = require('stryker-parent');2initWorker1Task({ port: 8080 });3const { initWorker1Task } = require('stryker-parent');4initWorker1Task({ port: 8080 });5const { initWorker1Task } = require('stryker-parent');6initWorker1Task({ port: 8080 });7const { initWorker1Task } = require('stryker-parent');8initWorker1Task({ port: 8080 });9const { initWorker1Task } = require('stryker-parent');10initWorker1Task({ port: 8080 });11const { initWorker1Task } = require('stryker-parent');12initWorker1Task({ port: 8080 });13const { initWorker1Task } = require('stryker-parent');14initWorker1Task({ port: 8080 });15const { initWorker1Task } = require('stryker-parent');16initWorker1Task({ port: 8080 });17const { initWorker1Task } = require('stryker-parent');18initWorker1Task({ port: 8080 });19const { initWorker1Task } = require('stryker-parent');20initWorker1Task({ port: 8080 });21const { initWorker1Task } = require('stryker-parent');22initWorker1Task({ port: 8080 });

Full Screen

Using AI Code Generation

copy

Full Screen

1var parent = require('stryker-parent');2var childProcess = parent.initWorker1Task('test.js');3childProcess.send({ hello: 'world' });4childProcess.on('message', function (msg) {5 console.log('Message from child', msg);6});7var parent = require('stryker-parent');8var childProcess = parent.initWorker2Task('test.js');9childProcess.send({ hello: 'world' });10childProcess.on('message', function (msg) {11 console.log('Message from child', msg);12});13var parent = require('stryker-parent');14var childProcess = parent.initMasterTask('test.js');15childProcess.send({ hello: 'world' });16childProcess.on('message', function (msg) {17 console.log('Message from child', msg);18});19var parent = require('stryker-parent');20var childProcess = parent.initWorker1Task('test.js');21childProcess.send({ hello: 'world' });22childProcess.on('message', function (msg) {23 console.log('Message from child', msg);24});25var parent = require('stryker-parent');26var childProcess = parent.initWorker2Task('test.js');27childProcess.send({ hello: 'world' });28childProcess.on('message', function (msg) {29 console.log('Message from child', msg);30});31var parent = require('stryker-parent');32var childProcess = parent.initMasterTask('test.js');33childProcess.send({ hello: 'world' });34childProcess.on('message', function (msg) {35 console.log('Message from child', msg);36});37var parent = require('stryker-parent');38var childProcess = parent.initWorker1Task('test.js');39childProcess.send({ hello: 'world' });40childProcess.on('message', function (msg) {41 console.log('Message from child', msg);

Full Screen

Using AI Code Generation

copy

Full Screen

1var stryker = require('stryker-parent');2var worker1Task = stryker.initWorker1Task();3worker1Task.start();4var worker2Task = stryker.initWorker2Task();5worker2Task.start();6var stryker = require('stryker-child');7var worker1Task = stryker.initWorker1Task();8worker1Task.start();9var worker2Task = stryker.initWorker2Task();10worker2Task.start();11var stryker = require('stryker');12var worker1Task = stryker.initWorker1Task();13worker1Task.start();14var worker2Task = stryker.initWorker2Task();15worker2Task.start();16var stryker = require('stryker-parent');17var worker1Task = stryker.initWorker1Task();18worker1Task.start();19var worker2Task = stryker.initWorker2Task();20worker2Task.start();21var stryker = require('stryker-child');22var worker1Task = stryker.initWorker1Task();23worker1Task.start();24var worker2Task = stryker.initWorker2Task();25worker2Task.start();26var stryker = require('stryker');27var worker1Task = stryker.initWorker1Task();28worker1Task.start();29var worker2Task = stryker.initWorker2Task();30worker2Task.start();31var stryker = require('stryker-parent');32var worker1Task = stryker.initWorker1Task();33worker1Task.start();34var worker2Task = stryker.initWorker2Task();35worker2Task.start();36var stryker = require('stryker-child');37var worker1Task = stryker.initWorker1Task();38worker1Task.start();39var worker2Task = stryker.initWorker2Task();40worker2Task.start();41var stryker = require('stry

Full Screen

Using AI Code Generation

copy

Full Screen

1var stryker = require('stryker-parent');2var childProcess = require('child_process');3var child = childProcess.fork('./initWorker1.js');4var initWorker1Task = stryker.initWorker1Task(child);5initWorker1Task.run();6var stryker = require('stryker-parent');7var childProcess = require('child_process');8var child = childProcess.fork('./worker1.js');9var initWorker1Task = stryker.initWorker1Task(child);10initWorker1Task.run();11var stryker = require('stryker-parent');12var childProcess = require('child_process');13var child = childProcess.fork('./initWorker2.js');14var initWorker1Task = stryker.initWorker1Task(child);15initWorker1Task.run();16var stryker = require('stryker-parent');17var childProcess = require('child_process');18var child = childProcess.fork('./worker2.js');19var initWorker1Task = stryker.initWorker1Task(child);20initWorker1Task.run();21var stryker = require('stryker-parent');22var childProcess = require('child_process');23var child = childProcess.fork('./initWorker3.js');24var initWorker1Task = stryker.initWorker1Task(child);25initWorker1Task.run();26var stryker = require('stryker-parent');27var childProcess = require('child_process');28var child = childProcess.fork('./worker3.js');29var initWorker1Task = stryker.initWorker1Task(child);30initWorker1Task.run();31var stryker = require('stryker-parent');32var childProcess = require('child_process');33var child = childProcess.fork('./initWorker4.js');

Full Screen

Using AI Code Generation

copy

Full Screen

1var worker1 = require('stryker-parent').initWorker1Task();2worker1.on('message', function (message) {3 console.log('message from worker1: ', message);4});5worker1.send({ hello: 'world' });6var worker1 = require('stryker-worker1').initWorker1Task();7worker1.on('message', function (message) {8 console.log('message from worker1: ', message);9});10worker1.send({ hello: 'world' });

Full Screen

Using AI Code Generation

copy

Full Screen

1var worker = require('stryker-parent').initWorker1Task();2worker.on('task', function (task) {3 worker.sendResult('done');4});5var childProcess = require('child_process');6var path = require('path');7var initWorker1Task = function () {8 var child = childProcess.fork(path.join(__dirname, 'test.js'));9 var worker = {10 on: function (event, callback) {11 child.on('message', function (msg) {12 if (msg.event === event) {13 callback(msg.data);14 }15 });16 },17 sendResult: function (result) {18 child.send({19 });20 }21 };22 return worker;23};24module.exports.initWorker1Task = initWorker1Task;25var childProcess = require('child_process');26var path = require('path');27var initWorker2Task = function () {28 var child = childProcess.fork(path.join(__dirname, 'test.js'));29 var worker = {30 on: function (event, callback) {31 child.on('message', function (msg) {32 if (msg.event === event) {33 callback(msg.data);34 }35 });36 },37 sendResult: function (result) {38 child.send({39 });40 }41 };42 return worker;43};44module.exports.initWorker2Task = initWorker2Task;45var childProcess = require('child_process');46var path = require('path');47var initWorker3Task = function () {48 var child = childProcess.fork(path.join(__dirname, 'test.js'));49 var worker = {50 on: function (event, callback) {51 child.on('message', function (msg) {52 if (msg.event === event) {53 callback(msg.data);54 }55 });56 },57 sendResult: function (result) {58 child.send({59 });60 }61 };62 return worker;63};64module.exports.initWorker3Task = initWorker3Task;65var childProcess = require('child_process');

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 stryker-parent 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