How to use onGoingScheduledWork 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 onGoingScheduledWork = require('stryker-parent').onGoingScheduledWork;2onGoingScheduledWork();3const onGoingScheduledWork = require('stryker-parent').onGoingScheduledWork;4onGoingScheduledWork();5const onGoingScheduledWork = require('stryker-parent').onGoingScheduledWork;6onGoingScheduledWork();7const onGoingScheduledWork = require('stryker-parent').onGoingScheduledWork;8onGoingScheduledWork();9const onGoingScheduledWork = require('stryker-parent').onGoingScheduledWork;10onGoingScheduledWork();11const onGoingScheduledWork = require('stryker-parent').onGoingScheduledWork;12onGoingScheduledWork();13const onGoingScheduledWork = require('stryker-parent').onGoingScheduledWork;14onGoingScheduledWork();15const onGoingScheduledWork = require('stryker-parent').onGoingScheduledWork;16onGoingScheduledWork();17const onGoingScheduledWork = require('stryker-parent').onGoingScheduledWork;18onGoingScheduledWork();19const onGoingScheduledWork = require('stryker-parent').onGoingScheduledWork;20onGoingScheduledWork();21const onGoingScheduledWork = require('stryker-parent').onGoingScheduledWork;22onGoingScheduledWork();23const onGoingScheduledWork = require('stryker-parent').onGoingScheduledWork;24onGoingScheduledWork();25const onGoingScheduledWork = require('stryker-parent').onGoingScheduledWork;26onGoingScheduledWork();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Stryker } = require('stryker-parent');2const stryker = new Stryker();3stryker.on('progress', function (progress) {4 console.log(progress);5});6stryker.on('error', function (error) {7 console.error(error);8});9stryker.on('complete', function (result) {10 console.log(result);11});12stryker.on('allSourceFilesRead', function (result) {13 console.log(result);14});15stryker.on('sourceFileRead', function (result) {16 console.log(result);17});18stryker.on('browsersReady', function (result) {19 console.log(result);20});21stryker.on('browsersError', function (result) {22 console.log(result);23});24stryker.on('browsersClose', function (result) {25 console.log(result);26});27stryker.on('testRunComplete', function (result) {28 console.log(result);29});30stryker.on('testRunStart', function (result) {31 console.log(result);32});33stryker.on('testStart', function (result) {34 console.log(result);35});36stryker.on('testResult', function (result) {37 console.log(result);38});39stryker.on('allMutantsTested', function (result) {40 console.log(result);41});42stryker.on('mutantTested', function (result) {43 console.log(result);44});45stryker.on('testError', function (result) {46 console.log(result);47});48stryker.on('testFail', function (result) {49 console.log(result);50});51stryker.on('testPass', function (result) {52 console.log(result);53});54stryker.on('testSkip', function (result) {55 console.log(result);56});57stryker.on('testTimeout', function (result) {58 console.log(result);59});60stryker.on('testRetry', function (result) {61 console.log(result);62});63stryker.on('testCoverage', function (result) {64 console.log(result);65});66stryker.on('allMutantsMatchedWithTests', function (result) {67 console.log(result);68});69stryker.on('mutantMatchedWithTests', function (result) {70 console.log(result);71});72stryker.on('allMutantsTested', function (result) {73 console.log(result);74});75stryker.on('mutantTested', function (result) {76 console.log(result);77});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { onGoingScheduledWork } = require('stryker-parent');2const { scheduleWork } = require('jest-worker');3const { onGoingScheduledWork } = require('stryker-parent');4const { scheduleWork } = require('jest-worker');5const { onGoingScheduledWork } = require('stryker-parent');6const { scheduleWork } = require('jest-worker');7const { onGoingScheduledWork } = require('stryker-parent');8const { scheduleWork } = require('jest-worker');9const { onGoingScheduledWork } = require('stryker-parent');10const { scheduleWork } = require('jest-worker');11const { onGoingScheduledWork } = require('stryker-parent');12const { scheduleWork } = require('jest-worker');13const { onGoingScheduledWork } = require('stryker-parent');14const { scheduleWork } = require('jest-worker');15const { onGoingScheduledWork } = require('stryker-parent');16const { scheduleWork } = require('jest-worker');17const { onGoingScheduledWork } = require('stryker-parent');18const { scheduleWork } = require('jest-worker');19const { onGoingScheduledWork } = require('stryker-parent');20const { scheduleWork } = require('jest-worker');21const { onGoingScheduledWork } = require('stryker-parent');22const { scheduleWork } = require('jest-worker');23const { onGoingScheduledWork } = require('stryker-parent');24const { scheduleWork } = require('jest-worker');25const { onGoingScheduledWork } = require('stryker-parent');26const { scheduleWork }

Full Screen

Using AI Code Generation

copy

Full Screen

1const StrykerParent = require('stryker-parent');2StrykerParent.onGoingScheduledWork((work) => {3 console.log(work);4});5const StrykerParent = require('stryker-parent');6StrykerParent.onGoingScheduledWork((work) => {7 console.log(work);8});9const StrykerParent = require('stryker-parent');10StrykerParent.onGoingScheduledWork((work) => {11 console.log(work);12});13const StrykerParent = require('stryker-parent');14StrykerParent.onGoingScheduledWork((work) => {15 console.log(work);16});17const StrykerParent = require('stryker-parent');18StrykerParent.onGoingScheduledWork((work) => {19 console.log(work);20});21const StrykerParent = require('stryker-parent');22StrykerParent.onGoingScheduledWork((work) => {23 console.log(work);24});25const StrykerParent = require('stryker-parent');26StrykerParent.onGoingScheduledWork((work) => {27 console.log(work);28});29const StrykerParent = require('stryker-parent');30StrykerParent.onGoingScheduledWork((work) => {31 console.log(work);32});33const StrykerParent = require('stryker-parent');34StrykerParent.onGoingScheduledWork((work) => {35 console.log(work);36});37const StrykerParent = require('stryker-parent');38StrykerParent.onGoingScheduledWork((work) => {39 console.log(work);40});

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