Best JavaScript code snippet using wpt
MemoryExecutorMixin-test.js
Source:MemoryExecutorMixin-test.js
1const EventEmitter = require('events');2const { expect, assert } = require('chai');3const LeanES = require("../../../src/leanes/index.js").default;4const {5 initialize, partOf, nameBy, meta, constant, mixin, method6} = LeanES.NS;7describe('MemoryExecutorMixin', () => {8 describe('.new', () => {9 it('should create new memory resque executor', () => {10 const executorName = 'TEST_MEMORY_RESQUE_EXECUTOR';11 const viewComponent = {12 id: 'view-component'13 };14 @initialize15 class Test extends LeanES {16 @nameBy static __filename = 'Test';17 @meta static object = {};18 @constant ROOT = `${__dirname}/../command/config`;19 }20 @initialize21 @mixin(LeanES.NS.MemoryExecutorMixin)22 @partOf(Test)23 class MemoryResqueExecutor extends LeanES.NS.Mediator {24 @nameBy static __filename = 'MemoryResqueExecutor';25 @meta static object = {};26 }27 const executor = MemoryResqueExecutor.new();28 executor.setName(executorName);29 executor.setViewComponent(viewComponent);30 assert.instanceOf(executor, MemoryResqueExecutor);31 });32 });33 describe('.listNotificationInterests', () => {34 it('should check notification interests list', () => {35 const executorName = 'TEST_MEMORY_RESQUE_EXECUTOR';36 const viewComponent = {37 id: 'view-component'38 };39 @initialize40 class Test extends LeanES {41 @nameBy static __filename = 'Test';42 @meta static object = {};43 @constant ROOT = `${__dirname}/../command/config`;44 }45 @initialize46 @mixin(LeanES.NS.MemoryExecutorMixin)47 @partOf(Test)48 class MemoryResqueExecutor extends LeanES.NS.Mediator {49 @nameBy static __filename = 'MemoryResqueExecutor';50 @meta static object = {};51 }52 const executor = MemoryResqueExecutor.new();53 executor.setName(executorName);54 executor.setViewComponent(viewComponent);55 assert.deepEqual(executor.listNotificationInterests(), [LeanES.NS.JOB_RESULT, LeanES.NS.START_RESQUE]);56 });57 });58 describe('.stop', () => {59 it('should stop executor', () => {60 const executorName = 'TEST_MEMORY_RESQUE_EXECUTOR';61 const viewComponent = {62 id: 'view-component'63 };64 @initialize65 class Test extends LeanES {66 @nameBy static __filename = 'Test';67 @meta static object = {};68 @constant ROOT = `${__dirname}/../command/config`;69 }70 @initialize71 @mixin(LeanES.NS.MemoryExecutorMixin)72 @partOf(Test)73 class MemoryResqueExecutor extends LeanES.NS.Mediator {74 @nameBy static __filename = 'MemoryResqueExecutor';75 @meta static object = {};76 }77 const executor = MemoryResqueExecutor.new();78 executor.setName(executorName);79 executor.setViewComponent(viewComponent);80 executor.stop();81 assert.isTrue(executor._isStopped);82 });83 });84 describe('.onRemove', () => {85 it('should handle remove event', async () => {86 const executorName = 'TEST_MEMORY_RESQUE_EXECUTOR';87 const viewComponent = {88 id: 'view-component'89 };90 @initialize91 class Test extends LeanES {92 @nameBy static __filename = 'Test';93 @meta static object = {};94 @constant ROOT = `${__dirname}/../command/config`;95 }96 @initialize97 @mixin(LeanES.NS.MemoryExecutorMixin)98 @partOf(Test)99 class MemoryResqueExecutor extends LeanES.NS.Mediator {100 @nameBy static __filename = 'MemoryResqueExecutor';101 @meta static object = {};102 }103 const executor = MemoryResqueExecutor.new();104 executor.setName(executorName);105 executor.setViewComponent(viewComponent);106 await executor.onRemove();107 assert.isTrue(executor._isStopped);108 });109 });110 describe('.define', () => {111 it('should define processor (success)', async () => {112 const executorName = 'TEST_MEMORY_RESQUE_EXECUTOR';113 const viewComponent = {114 id: 'view-component'115 };116 @initialize117 class Test extends LeanES {118 @nameBy static __filename = 'Test';119 @meta static object = {};120 @constant ROOT = `${__dirname}/../command/config`;121 }122 @initialize123 @mixin(LeanES.NS.MemoryExecutorMixin)124 @partOf(Test)125 class MemoryResqueExecutor extends LeanES.NS.Mediator {126 @nameBy static __filename = 'MemoryResqueExecutor';127 @meta static object = {};128 }129 const executor = MemoryResqueExecutor.new();130 executor.setName(executorName);131 executor.setViewComponent(viewComponent);132 executor._definedProcessors = {};133 executor._concurrencyCount = {};134 const QUEUE_NAME = 'TEST_QUEUE';135 const concurrency = 4;136 const testTrigger = new EventEmitter();137 executor.define(QUEUE_NAME, { concurrency }, (job, done) => {138 assert(job);139 testTrigger.once('DONE', (options) => {140 done(options);141 });142 });143 const processorData = executor._definedProcessors[QUEUE_NAME];144 assert.equal(processorData.concurrency, concurrency);145 const {146 listener,147 concurrency: processorConcurrency148 } = processorData;149 assert.equal(processorConcurrency, concurrency);150 const job = {151 status: 'scheduled'152 };153 listener(job);154 assert.equal(executor._concurrencyCount[QUEUE_NAME], 1);155 assert.propertyVal(job, 'status', 'running');156 assert.isDefined(job.startedAt);157 const promise = new Promise((resolve) => {158 testTrigger.once('DONE', resolve);159 });160 testTrigger.emit('DONE');161 await promise;162 assert.equal(executor._concurrencyCount[QUEUE_NAME], 0);163 assert.propertyVal(job, 'status', 'completed');164 });165 it('should define processor (fail)', async () => {166 const executorName = 'TEST_MEMORY_RESQUE_EXECUTOR';167 const viewComponent = {168 id: 'view-component'169 };170 @initialize171 class Test extends LeanES {172 @nameBy static __filename = 'Test';173 @meta static object = {};174 @constant ROOT = `${__dirname}/../command/config`;175 }176 @initialize177 @mixin(LeanES.NS.MemoryExecutorMixin)178 @partOf(Test)179 class MemoryResqueExecutor extends LeanES.NS.Mediator {180 @nameBy static __filename = 'MemoryResqueExecutor';181 @meta static object = {};182 }183 const executor = MemoryResqueExecutor.new();184 executor.setName(executorName);185 executor.setViewComponent(viewComponent);186 executor._definedProcessors = {};187 executor._concurrencyCount = {};188 const QUEUE_NAME = 'TEST_QUEUE';189 const concurrency = 4;190 const testTrigger = new EventEmitter();191 executor.define(QUEUE_NAME, { concurrency }, (job, done) => {192 assert(job);193 testTrigger.once('DONE', (options) => {194 done(options);195 });196 });197 const processorData = executor._definedProcessors[QUEUE_NAME];198 assert.equal(processorData.concurrency, concurrency);199 const {200 listener,201 concurrency: processorConcurrency202 } = processorData;203 assert.equal(processorConcurrency, concurrency);204 const job = {205 status: 'scheduled'206 };207 listener(job);208 assert.equal(executor._concurrencyCount[QUEUE_NAME], 1);209 assert.propertyVal(job, 'status', 'running');210 assert.isDefined(job.startedAt);211 const promise = new Promise((resolve) => {212 testTrigger.once('DONE', resolve);213 });214 testTrigger.emit('DONE', {215 error: 'error'216 });217 await promise;218 assert.equal(executor._concurrencyCount[QUEUE_NAME], 0);219 assert.propertyVal(job, 'status', 'failed');220 assert.deepEqual(job.reason, {221 error: 'error'222 });223 });224 });225 describe('.defineProcessors', () => {226 let facade = null;227 afterEach(async () => {228 facade != null ? typeof facade.remove === "function" ? await facade.remove() : void 0 : void 0;229 });230 it('should define processors', async () => {231 const KEY = 'TEST_MEMORY_RESQUE_EXECUTOR_001';232 facade = LeanES.NS.Facade.getInstance(KEY);233 @initialize234 class Test extends LeanES {235 @nameBy static __filename = 'Test';236 @meta static object = {};237 @constant ROOT = `${__dirname}/../command/config`;238 }239 @initialize240 @mixin(LeanES.NS.MemoryResqueMixin)241 @partOf(Test)242 class TestResque extends LeanES.NS.Resque {243 @nameBy static __filename = 'TestResque';244 @meta static object = {};245 }246 @initialize247 @mixin(LeanES.NS.MemoryExecutorMixin)248 @partOf(Test)249 class MemoryResqueExecutor extends LeanES.NS.Mediator {250 @nameBy static __filename = 'MemoryResqueExecutor';251 @meta static object = {};252 }253 const resque = TestResque.new();254 resque.setName(LeanES.NS.RESQUE);255 facade.registerProxy(resque);256 resque.create('TEST_QUEUE_1', 4);257 resque.create('TEST_QUEUE_2', 4);258 const executorName = 'TEST_MEMORY_RESQUE_EXECUTOR';259 const viewComponent = {260 id: 'view-component'261 };262 const executor = MemoryResqueExecutor.new();263 executor.setName(executorName);264 executor.setViewComponent(viewComponent);265 executor.initializeNotifier(KEY);266 executor.setViewComponent(new EventEmitter());267 executor._definedProcessors = {};268 executor._concurrencyCount = {};269 executor._resque = resque;270 await executor.defineProcessors();271 assert.property(executor._definedProcessors, 'TEST_QUEUE_1');272 assert.property(executor._definedProcessors, 'TEST_QUEUE_2');273 });274 });275 describe('.reDefineProcessors', () => {276 let facade = null;277 afterEach(async () => {278 facade != null ? typeof facade.remove === "function" ? await facade.remove() : void 0 : void 0;279 });280 it('should redefine processors', async () => {281 const KEY = 'TEST_MEMORY_RESQUE_EXECUTOR_009';282 facade = LeanES.NS.Facade.getInstance(KEY);283 @initialize284 class Test extends LeanES {285 @nameBy static __filename = 'Test';286 @meta static object = {};287 @constant ROOT = `${__dirname}/../command/config`;288 }289 @initialize290 @mixin(LeanES.NS.MemoryResqueMixin)291 @partOf(Test)292 class TestResque extends LeanES.NS.Resque {293 @nameBy static __filename = 'TestResque';294 @meta static object = {};295 }296 @initialize297 @mixin(LeanES.NS.MemoryExecutorMixin)298 @partOf(Test)299 class MemoryResqueExecutor extends LeanES.NS.Mediator {300 @nameBy static __filename = 'MemoryResqueExecutor';301 @meta static object = {};302 }303 const resque = TestResque.new();304 resque.setName(LeanES.NS.RESQUE);305 facade.registerProxy(resque);306 resque.create('TEST_QUEUE_1', 4);307 resque.create('TEST_QUEUE_2', 4);308 const executorName = 'TEST_MEMORY_RESQUE_EXECUTOR';309 const viewComponent = {310 id: 'view-component'311 };312 const executor = MemoryResqueExecutor.new();313 executor.setName(executorName);314 executor.setViewComponent(viewComponent);315 executor.initializeNotifier(KEY);316 executor.setViewComponent(new EventEmitter());317 executor._definedProcessors = {};318 executor._concurrencyCount = {};319 executor._resque = resque;320 await executor.defineProcessors();321 assert.property(executor._definedProcessors, 'TEST_QUEUE_1');322 assert.property(executor._definedProcessors, 'TEST_QUEUE_2');323 delete executor._definedProcessors;324 await executor.reDefineProcessors();325 assert.property(executor._definedProcessors, 'TEST_QUEUE_1');326 assert.property(executor._definedProcessors, 'TEST_QUEUE_2');327 });328 });329 describe('.onRegister', () => {330 let facade = null;331 afterEach(async () => {332 facade != null ? typeof facade.remove === "function" ? await facade.remove() : void 0 : void 0;333 });334 it('should setup executor on register', async () => {335 const KEY = 'TEST_MEMORY_RESQUE_EXECUTOR_002';336 facade = LeanES.NS.Facade.getInstance(KEY);337 const trigger = new EventEmitter();338 @initialize339 class Test extends LeanES {340 @nameBy static __filename = 'Test';341 @meta static object = {};342 @constant ROOT = `${__dirname}/../command/config`;343 }344 @initialize345 @mixin(LeanES.NS.MemoryResqueMixin)346 @partOf(Test)347 class TestResque extends LeanES.NS.Resque {348 @nameBy static __filename = 'TestResque';349 @meta static object = {};350 }351 @initialize352 @mixin(LeanES.NS.MemoryExecutorMixin)353 @partOf(Test)354 class MemoryResqueExecutor extends LeanES.NS.Mediator {355 @nameBy static __filename = 'MemoryResqueExecutor';356 @meta static object = {};357 @method async defineProcessors(...args) {358 await super.defineProcessors(...args);359 trigger.emit('PROCESSORS_DEFINED');360 }361 }362 const resque = TestResque.new();363 resque.setName(LeanES.NS.RESQUE);364 facade.registerProxy(resque);365 resque.create('TEST_QUEUE_1', 4);366 resque.create('TEST_QUEUE_2', 4);367 const executorName = 'TEST_MEMORY_RESQUE_EXECUTOR';368 const viewComponent = {369 id: 'view-component'370 };371 const executor = MemoryResqueExecutor.new();372 executor.setName(executorName);373 executor.setViewComponent(viewComponent);374 const promise = new Promise((resolve) => {375 trigger.once('PROCESSORS_DEFINED', resolve);376 });377 facade.registerMediator(executor);378 await promise;379 assert.property(executor._definedProcessors, 'TEST_QUEUE_1');380 assert.property(executor._definedProcessors, 'TEST_QUEUE_2');381 });382 });383 describe('.recursion', () => {384 let facade = null;385 afterEach(async () => {386 facade != null ? typeof facade.remove === "function" ? await facade.remove() : void 0 : void 0;387 });388 it('should recursively call cycle part', async () => {389 const KEY = 'TEST_MEMORY_RESQUE_EXECUTOR_004';390 facade = LeanES.NS.Facade.getInstance(KEY);391 const trigger = new EventEmitter();392 let test = null;393 @initialize394 class Test extends LeanES {395 @nameBy static __filename = 'Test';396 @meta static object = {};397 @constant ROOT = `${__dirname}/../command/config`;398 }399 @initialize400 @mixin(LeanES.NS.MemoryResqueMixin)401 @partOf(Test)402 class TestResque extends LeanES.NS.Resque {403 @nameBy static __filename = 'TestResque';404 @meta static object = {};405 }406 @initialize407 @mixin(LeanES.NS.MemoryExecutorMixin)408 @partOf(Test)409 class MemoryResqueExecutor extends LeanES.NS.Mediator {410 @nameBy static __filename = 'MemoryResqueExecutor';411 @meta static object = {};412 @method async defineProcessors(...args) {413 await super.defineProcessors(...args);414 trigger.emit('PROCESSORS_DEFINED');415 }416 @method cyclePart(...args) {417 test = true;418 trigger.emit('CYCLE_PART');419 }420 }421 const resque = TestResque.new();422 resque.setName(LeanES.NS.RESQUE);423 facade.registerProxy(resque);424 resque.create(LeanES.NS.DELAYED_JOBS_QUEUE, 4);425 const executor = MemoryResqueExecutor.new(LeanES.NS.RESQUE_EXECUTOR);426 let promise = new Promise((resolve) => {427 trigger.once('PROCESSORS_DEFINED', resolve);428 });429 facade.registerMediator(executor);430 await promise;431 promise = new Promise((resolve) => {432 trigger.once('CYCLE_PART', resolve);433 });434 executor._isStopped = false;435 await executor.recursion();436 await promise;437 assert.isNotNull(test);438 });439 });440 describe('.start', () => {441 let facade = null;442 afterEach(async () => {443 facade != null ? typeof facade.remove === "function" ? await facade.remove() : void 0 : void 0;444 });445 it('should call recursion', async () => {446 const KEY = 'TEST_MEMORY_RESQUE_EXECUTOR_005';447 facade = LeanES.NS.Facade.getInstance(KEY);448 const trigger = new EventEmitter();449 let test = null;450 @initialize451 class Test extends LeanES {452 @nameBy static __filename = 'Test';453 @meta static object = {};454 @constant ROOT = `${__dirname}/../command/config`;455 }456 @initialize457 @mixin(LeanES.NS.MemoryResqueMixin)458 @partOf(Test)459 class TestResque extends LeanES.NS.Resque {460 @nameBy static __filename = 'TestResque';461 @meta static object = {};462 }463 @initialize464 @mixin(LeanES.NS.MemoryExecutorMixin)465 @partOf(Test)466 class MemoryResqueExecutor extends LeanES.NS.Mediator {467 @nameBy static __filename = 'MemoryResqueExecutor';468 @meta static object = {};469 @method async defineProcessors(...args) {470 await super.defineProcessors(...args);471 trigger.emit('PROCESSORS_DEFINED');472 }473 @method cyclePart(...args) {474 test = true;475 trigger.emit('CYCLE_PART');476 }477 }478 const resque = TestResque.new();479 resque.setName(LeanES.NS.RESQUE);480 facade.registerProxy(resque);481 resque.create(LeanES.NS.DELAYED_JOBS_QUEUE, 4);482 const executor = MemoryResqueExecutor.new(LeanES.NS.RESQUE_EXECUTOR);483 let promise = new Promise((resolve) => {484 trigger.once('PROCESSORS_DEFINED', resolve);485 });486 facade.registerMediator(executor);487 await promise;488 promise = new Promise((resolve) => {489 trigger.once('CYCLE_PART', resolve);490 });491 await executor.start();492 await promise;493 assert.isNotNull(test);494 });495 });496 describe('.handleNotification', () => {497 let facade = null;498 afterEach(async () => {499 facade != null ? typeof facade.remove === "function" ? await facade.remove() : void 0 : void 0;500 });501 it('should start resque', async () => {502 const KEY = 'TEST_MEMORY_RESQUE_EXECUTOR_006';503 facade = LeanES.NS.Facade.getInstance(KEY);504 const trigger = new EventEmitter();505 let test = null;506 @initialize507 class Test extends LeanES {508 @nameBy static __filename = 'Test';509 @meta static object = {};510 @constant ROOT = `${__dirname}/../command/config`;511 }512 @initialize513 @mixin(LeanES.NS.MemoryResqueMixin)514 @partOf(Test)515 class TestResque extends LeanES.NS.Resque {516 @nameBy static __filename = 'TestResque';517 @meta static object = {};518 }519 @initialize520 @mixin(LeanES.NS.MemoryExecutorMixin)521 @partOf(Test)522 class MemoryResqueExecutor extends LeanES.NS.Mediator {523 @nameBy static __filename = 'MemoryResqueExecutor';524 @meta static object = {};525 @method start() {526 test = true;527 trigger.emit('CYCLE_PART');528 }529 }530 const resque = TestResque.new();531 resque.setName(LeanES.NS.RESQUE);532 facade.registerProxy(resque);533 resque.create(LeanES.NS.DELAYED_JOBS_QUEUE, 4);534 const executor = MemoryResqueExecutor.new();535 executor.setName(LeanES.NS.RESQUE_EXECUTOR);536 facade.registerMediator(executor);537 const promise = new Promise(function (resolve) {538 trigger.once('CYCLE_PART', resolve);539 });540 facade.sendNotification(LeanES.NS.START_RESQUE);541 await promise;542 assert.isNotNull(test);543 });544 it('should get result', async () => {545 const KEY = 'TEST_MEMORY_RESQUE_EXECUTOR_007';546 facade = LeanES.NS.Facade.getInstance(KEY);547 @initialize548 class Test extends LeanES {549 @nameBy static __filename = 'Test';550 @meta static object = {};551 @constant ROOT = `${__dirname}/../command/config`;552 }553 @initialize554 @mixin(LeanES.NS.MemoryResqueMixin)555 @partOf(Test)556 class TestResque extends LeanES.NS.Resque {557 @nameBy static __filename = 'TestResque';558 @meta static object = {};559 }560 @initialize561 @mixin(LeanES.NS.MemoryExecutorMixin)562 @partOf(Test)563 class MemoryResqueExecutor extends LeanES.NS.Mediator {564 @nameBy static __filename = 'MemoryResqueExecutor';565 @meta static object = {};566 }567 const resque = TestResque.new();568 resque.setName(LeanES.NS.RESQUE);569 facade.registerProxy(resque);570 resque.create(LeanES.NS.DELAYED_JOBS_QUEUE, 4);571 const executor = MemoryResqueExecutor.new();572 executor.setName(LeanES.NS.RESQUE_EXECUTOR);573 facade.registerMediator(executor);574 const type = 'TEST_TYPE';575 const promise = new Promise((resolve) => {576 executor.getViewComponent().once(type, resolve);577 });578 const body = {579 test: 'test'580 };581 facade.sendNotification(LeanES.NS.JOB_RESULT, body, type);582 const data = await promise;583 assert.deepEqual(data, body);584 });585 });586 describe('.cyclePart', () => {587 let facade = null;588 afterEach(async () => {589 facade != null ? typeof facade.remove === "function" ? await facade.remove() : void 0 : void 0;590 });591 it('should start cycle part', async () => {592 const KEY = 'TEST_MEMORY_RESQUE_EXECUTOR_008';593 facade = LeanES.NS.Facade.getInstance(KEY);594 const trigger = new EventEmitter();595 @initialize596 class Test extends LeanES {597 @nameBy static __filename = 'Test';598 @meta static object = {};599 @constant ROOT = `${__dirname}/command/config`;600 }601 @initialize602 @mixin(LeanES.NS.MemoryResqueMixin)603 @partOf(Test)604 class TestResque extends LeanES.NS.Resque {605 @nameBy static __filename = 'TestResque';606 @meta static object = {};607 }608 @initialize609 @mixin(LeanES.NS.MemoryExecutorMixin)610 @partOf(Test)611 class MemoryResqueExecutor extends LeanES.NS.Mediator {612 @nameBy static __filename = 'MemoryResqueExecutor';613 @meta static object = {};614 }615 @initialize616 @partOf(Test)617 class TestScript extends LeanES.NS.Script {618 @nameBy static __filename = 'TestScript';619 @meta static object = {};620 @method async body(data: ?any): Promise<?any> {621 trigger.emit('CYCLE_PART', data);622 return data623 }624 }625 facade.registerCommand('TEST_SCRIPT', TestScript);626 const resque = TestResque.new();627 resque.setName(LeanES.NS.RESQUE);628 facade.registerProxy(resque);629 await resque.create(LeanES.NS.DELAYED_JOBS_QUEUE, 4);630 const queue = await resque.get(LeanES.NS.DELAYED_JOBS_QUEUE);631 const executor = MemoryResqueExecutor.new();632 executor.setName(LeanES.NS.RESQUE_EXECUTOR);633 facade.registerMediator(executor);634 const promise = new Promise((resolve) => {635 trigger.once('CYCLE_PART', resolve);636 });637 const DELAY_UNTIL = Date.now() + 1000;638 const body = {639 arg1: 'ARG_1',640 arg2: 'ARG_2',641 arg3: 'ARG_3'642 };643 await queue.push('TEST_SCRIPT', body, DELAY_UNTIL);644 facade.sendNotification(LeanES.NS.START_RESQUE);645 const data = await promise;646 assert.deepEqual(data, body);647 });648 });649 describe('.fullQueueName', () => {650 let facade = null;651 afterEach(async () => {652 facade != null ? typeof facade.remove === "function" ? await facade.remove() : void 0 : void 0;653 });654 it('should get full queue name', async () => {655 const KEY = 'TEST_MEMORY_RESQUE_EXECUTOR_010';656 facade = LeanES.NS.Facade.getInstance(KEY);657 @initialize658 class Test extends LeanES {659 @nameBy static __filename = 'Test';660 @meta static object = {};661 @constant ROOT = `${__dirname}/../command/config`;662 }663 @initialize664 @mixin(LeanES.NS.MemoryResqueMixin)665 @partOf(Test)666 class TestResque extends LeanES.NS.Resque {667 @nameBy static __filename = 'TestResque';668 @meta static object = {};669 }670 @initialize671 @mixin(LeanES.NS.MemoryExecutorMixin)672 @partOf(Test)673 class MemoryResqueExecutor extends LeanES.NS.Mediator {674 @nameBy static __filename = 'MemoryResqueExecutor';675 @meta static object = {};676 }677 const resque = TestResque.new();678 resque.setName(LeanES.NS.RESQUE);679 facade.registerProxy(resque);680 resque.create('TEST_QUEUE_1', 4);681 resque.create('TEST_QUEUE_2', 4);682 const executorName = 'TEST_MEMORY_RESQUE_EXECUTOR';683 const viewComponent = {684 id: 'view-component'685 };686 const executor = MemoryResqueExecutor.new();687 executor.setName(executorName);688 executor.setViewComponent(viewComponent);689 facade.registerMediator(executor);690 const fullQueueName = executor.fullQueueName('TEST_QUEUE_1');691 assert.equal(fullQueueName, 'Test|>TEST_QUEUE_1');692 });693 });...
lokiWorker.js
Source:lokiWorker.js
1// @flow2// don't import whole `utils` to keep worker size small3import logError from '../../../utils/common/logError'4import invariant from '../../../utils/common/invariant'5import LokiExecutor from './executor'6import { actions, type WorkerAction, type WorkerResponse } from '../common'7const ExecutorProto = LokiExecutor.prototype8const executorMethods = {9 [actions.SETUP]: ExecutorProto.setUp,10 [actions.FIND]: ExecutorProto.find,11 [actions.QUERY]: ExecutorProto.query,12 [actions.COUNT]: ExecutorProto.count,13 [actions.BATCH]: ExecutorProto.batch,14 [actions.UNSAFE_RESET_DATABASE]: ExecutorProto.unsafeResetDatabase,15 [actions.GET_LOCAL]: ExecutorProto.getLocal,16 [actions.SET_LOCAL]: ExecutorProto.setLocal,17 [actions.REMOVE_LOCAL]: ExecutorProto.removeLocal,18 [actions.GET_DELETED_RECORDS]: ExecutorProto.getDeletedRecords,19 [actions.DESTROY_DELETED_RECORDS]: ExecutorProto.destroyDeletedRecords,20}21export default class LokiWorker {22 workerContext: DedicatedWorkerGlobalScope23 executor: ?LokiExecutor24 queue: WorkerAction[] = []25 _actionsExecuting: number = 026 constructor(workerContext: DedicatedWorkerGlobalScope): void {27 this.workerContext = workerContext28 this.workerContext.onmessage = (e: MessageEvent) => {29 const action: WorkerAction = (e.data: any)30 this.enqueue(action)31 }32 }33 enqueue(action: WorkerAction): void {34 this.queue.push(action)35 if (this.queue.length === 1) {36 this.executeNext()37 }38 }39 executeNext(): void {40 const action = this.queue[0]41 invariant(this._actionsExecuting === 0, 'worker should not have ongoing actions') // sanity check42 this.processAction(action)43 }44 onActionDone(response: WorkerResponse): void {45 invariant(this._actionsExecuting === 1, 'worker should be executing 1 action') // sanity check46 this._actionsExecuting = 047 this.queue.shift()48 try {49 this.workerContext.postMessage(response)50 } catch (error) {51 logError(error)52 }53 if (this.queue.length) {54 this.executeNext()55 }56 }57 processAction(action: WorkerAction): void {58 try {59 this._actionsExecuting += 160 const { type, payload, id } = action61 invariant(type in actions, `Unknown worker action ${type}`)62 if (type === actions.SETUP || type === actions.UNSAFE_RESET_DATABASE) {63 this.processActionAsync(action)64 } else {65 // run action66 invariant(this.executor, `Cannot run actions because executor is not set up`)67 const runExecutorAction = executorMethods[type].bind(this.executor)68 const response = runExecutorAction(...payload)69 this.onActionDone({ id, result: { value: response } })70 }71 } catch (error) {72 // Main process only receives error message â this logError is to retain call stack73 logError(error)74 this.onActionDone({ id: action.id, result: { error } })75 }76 }77 async processActionAsync(action: WorkerAction): Promise<void> {78 try {79 const { type, payload, id } = action80 if (type === actions.SETUP) {81 // app just launched, set up executor with options sent82 invariant(!this.executor, `Loki executor already set up - cannot set up again`)83 const [options] = payload84 const executor = new LokiExecutor(options)85 // set up, make this.executor available only if successful86 await executor.setUp()87 this.executor = executor88 this.onActionDone({ id, result: { value: null } })89 } else {90 // run action91 invariant(this.executor, `Cannot run actions because executor is not set up`)92 const runExecutorAction = executorMethods[type].bind(this.executor)93 const response = await runExecutorAction(...payload)94 this.onActionDone({ id, result: { value: response } })95 }96 } catch (error) {97 // Main process only receives error message â this logError is to retain call stack98 logError(error)99 this.onActionDone({ id: action.id, result: { error } })100 }101 }...
capability-executor-not-callable.js
Source:capability-executor-not-callable.js
...42var checkPoint = "";43assert.throws(TypeError, function() {44 constructorFunction = function(executor) {45 checkPoint += "a";46 executor();47 checkPoint += "b";48 };49 promise.then();50}, "executor called with no arguments");51assert.sameValue(checkPoint, "ab", "executor called with no arguments");52var checkPoint = "";53assert.throws(TypeError, function() {54 constructorFunction = function(executor) {55 checkPoint += "a";56 executor(undefined, undefined);57 checkPoint += "b";58 };59 promise.then();60}, "executor called with (undefined, undefined)");61assert.sameValue(checkPoint, "ab", "executor called with (undefined, undefined)");62var checkPoint = "";63assert.throws(TypeError, function() {64 constructorFunction = function(executor) {65 checkPoint += "a";66 executor(undefined, function() {});67 checkPoint += "b";68 };69 promise.then();70}, "executor called with (undefined, function)");71assert.sameValue(checkPoint, "ab", "executor called with (undefined, function)");72var checkPoint = "";73assert.throws(TypeError, function() {74 constructorFunction = function(executor) {75 checkPoint += "a";76 executor(function() {}, undefined);77 checkPoint += "b";78 };79 promise.then();80}, "executor called with (function, undefined)");81assert.sameValue(checkPoint, "ab", "executor called with (function, undefined)");82var checkPoint = "";83assert.throws(TypeError, function() {84 constructorFunction = function(executor) {85 checkPoint += "a";86 executor(123, "invalid value");87 checkPoint += "b";88 };89 promise.then();90}, "executor called with (Number, String)");...
capability-executor-called-twice.js
Source:capability-executor-called-twice.js
...31}(function() {});32var checkPoint = "";33constructorFunction = function(executor) {34 checkPoint += "a";35 executor();36 checkPoint += "b";37 executor(function() {}, function() {});38 checkPoint += "c";39};40promise.then();41assert.sameValue(checkPoint, "abc", "executor initially called with no arguments");42var checkPoint = "";43constructorFunction = function(executor) {44 checkPoint += "a";45 executor(undefined, undefined);46 checkPoint += "b";47 executor(function() {}, function() {});48 checkPoint += "c";49};50promise.then();51assert.sameValue(checkPoint, "abc", "executor initially called with (undefined, undefined)");52var checkPoint = "";53assert.throws(TypeError, function() {54 constructorFunction = function(executor) {55 checkPoint += "a";56 executor(undefined, function() {});57 checkPoint += "b";58 executor(function() {}, function() {});59 checkPoint += "c";60 };61 promise.then();62}, "executor initially called with (undefined, function)");63assert.sameValue(checkPoint, "ab", "executor initially called with (undefined, function)");64var checkPoint = "";65assert.throws(TypeError, function() {66 constructorFunction = function(executor) {67 checkPoint += "a";68 executor(function() {}, undefined);69 checkPoint += "b";70 executor(function() {}, function() {});71 checkPoint += "c";72 };73 promise.then();74}, "executor initially called with (function, undefined)");75assert.sameValue(checkPoint, "ab", "executor initially called with (function, undefined)");76var checkPoint = "";77assert.throws(TypeError, function() {78 constructorFunction = function(executor) {79 checkPoint += "a";80 executor("invalid value", 123);81 checkPoint += "b";82 executor(function() {}, function() {});83 checkPoint += "c";84 };85 promise.then();86}, "executor initially called with (String, Number)");...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) return console.error(err);4 console.log('Test status check: ' + data.statusText);5 wpt.getTestStatus(data.data.testId, function(err, data) {6 if (err) return console.error(err);7 console.log('Test status check: ' + data.statusText);8 });9});10var wpt = require('webpagetest');11var wpt = new WebPageTest('www.webpagetest.org');12 if (err) return console.error(err);13 console.log('Test status check: ' + data.statusText);14 wpt.getTestStatus(data.data.testId, function(err, data) {15 if (err) return console.error(err);16 console.log('Test status check: ' + data.statusText);17 });18});19var wpt = require('webpagetest');20var wpt = new WebPageTest('www.webpagetest.org');21 if (err) return console.error(err);22 console.log('Test status check: ' + data.statusText);23 wpt.getTestResults(data.data.testId, function(err, data) {24 if (err) return console.error(err);25 console.log('Test status check: ' + data.statusText);26 });27});28var wpt = require('webpagetest');
Using AI Code Generation
1var wpt = require('webpagetest');2var test = new wpt('www.webpagetest.org', 'A.3a6a5a6a5a6a5a6a5a6a5a6a5a6a5a6');3var options = {4};5test.runTest(url, options, function(err, data) {6 if (err) {7 console.log('Error: ' + err);8 } else {9 console.log('Test Results: ' + JSON.stringify(data));10 }11});12var wpt = require('webpagetest');13var test = new wpt('www.webpagetest.org', 'A.3a6a5a6a5a6a5a6a5a6a5a6a5a6a5a6');14var options = {15};16test.runTest(url, options)17 .then(function(data) {18 console.log('Test Results: ' + JSON.stringify(data));19 })20 .catch(function(err) {21 console.log('Error: ' + err);22 });23var wpt = require('webpagetest');24var test = new wpt('www.webpagetest.org', 'A.3a6a5a6a5a6a5a6a5a6a5a6a5a6a5a6');25var options = {26};27test.runTest(url, options, function(err, data) {28 if (err) {29 console.log('Error:
Using AI Code Generation
1const wpt = require('webpagetest');2const wptClient = wpt('www.webpagetest.org', 'A.9f9a7c0d0a2b7d2f3b3a7c2b3d4e5f6');3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9### wpt(host, apiKey)10#### WebPageTest.runTest(url, options, callback)
Using AI Code Generation
1var wpt = require('webpagetest');2var options = {3};4var wpt = new WebPageTest('www.webpagetest.org', 'A.3b6e7f6f0b6c2c0d9d9c2b0e8e6c7d6');5 if (err) return console.error(err);6 console.log('Test status:', data.statusText);7 if (data.statusCode == 200) {8 console.log('Test completed, results available at', data.data.userUrl);9 }10});
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!