How to use updateRunnerState method in Best

Best JavaScript code snippet using best

runner-stream.ts

Source:runner-stream.ts Github

copy

Full Screen

...131 writeBufferStream(str: string) {132 this._streamBuffer += str;133 this.stdoutWrite(str);134 }135 updateRunnerState(benchmarkSignature: string, state: State) {136 const stateConfig = this._state.get(benchmarkSignature);137 if (!stateConfig) {138 throw new Error(`Unknown benchmark build started (${benchmarkSignature})`);139 }140 if (stateConfig.state !== State.ERROR) {141 stateConfig.state = state;142 }143 }144 scheduleUpdate(time?: number, fn?: Function) {145 if (!this._scheduled) {146 this._scheduled = setTimeout(() => {147 fn ? fn() : this.updateStream();148 this._scheduled = null;149 }, time || DEFAULT_TIMEOUT);150 }151 }152 printBenchmarkState({ state, projectName, displayPath }: { state: State, projectName: string, displayPath: string }) {153 const columns = this.stdoutColumns;154 const overflow = columns - (state.length + projectName.length + displayPath.length + /* for padding */ 14);155 const hasOverflow = overflow < 0;156 const ansiState = printState(state);157 const ansiProjectName = printProjectName(projectName);158 const ansiDisplayname = printDisplayName(displayPath, hasOverflow ? Math.abs(overflow): 0);159 return `${ansiState} ${ansiProjectName} ${ansiDisplayname}\n`;160 }161 printProgress(progress: BenchmarkProgress, { displayPath }: BenchmarkStatus): string {162 const benchmarkName = chalk.bold.black(path.basename(displayPath));163 return [164 `\n${PROGRESS_TEXT} ${benchmarkName}`,165 chalk.bold.black('Avg iteration: ') + progress.avgIteration.toFixed(2) + 'ms',166 chalk.bold.black('Completed iterations: ') + progress.executedIterations,167 printProgressBar(progress.runtime, progress.estimated, 40)168 ].join('\n') + '\n\n';169 }170 updateStream() {171 let buffer = INIT_MSG;172 let progressStr: string = '';173 for (const benchmarkState of this._state.values()) {174 const { state, displayPath, projectName, progress } = benchmarkState;175 buffer += this.printBenchmarkState({ state, displayPath, projectName });176 if (state === State.RUNNING && progress) {177 progressStr += this.printProgress(progress, benchmarkState);178 }179 }180 const streamProxyBuffer = this._proxyStream.readBuffer();181 streamProxyBuffer ? `Buffered console logs:\n ${streamProxyBuffer}` : '';182 this.clearBufferStream();183 this.writeBufferStream(buffer + progressStr + streamProxyBuffer);184 }185 log(message: string) {186 this._innerLog = message;187 if (this.isInteractive) {188 this.scheduleUpdate();189 } else {190 this.stdoutWrite(` :: ${message}\n`);191 }192 }193 _clearTimeout() {194 if (this._scheduled) {195 clearTimeout(this._scheduled);196 this._scheduled = null;197 }198 }199 // -- Lifecycle200 onBenchmarkStart(benchmarkSignature: string) {201 this.updateRunnerState(benchmarkSignature, State.RUNNING);202 if (this.isInteractive) {203 this.scheduleUpdate();204 } else {205 const benchmarkState = this._state.get(benchmarkSignature);206 if (benchmarkState) {207 this.stdoutWrite(this.printBenchmarkState(benchmarkState));208 }209 }210 }211 onBenchmarkEnd(benchmarkSignature: string) {212 this.updateRunnerState(benchmarkSignature, State.DONE);213 this._innerLog = '';214 const benchmarkState = this._state.get(benchmarkSignature);215 if (benchmarkState) {216 if (this.isInteractive) {217 if (benchmarkState.state === State.ERROR) {218 this.updateStream();219 this.stdoutWrite('\n');220 } else {221 this.scheduleUpdate();222 }223 } else {224 this._clearTimeout();225 this.stdoutWrite(this.printBenchmarkState(benchmarkState) + '\n');226 }227 }228 }229 onBenchmarkError(benchmarkSignature: string) {230 this.updateRunnerState(benchmarkSignature, State.ERROR);231 }232 updateBenchmarkProgress(benchmarkSignature: string, updatedBenchmarkState: BenchmarkUpdateState, runtimeOpts: BenchmarkRuntimeConfig) {233 const progress = calculateBenchmarkProgress(updatedBenchmarkState, runtimeOpts);234 const benchmarkState = this._state.get(benchmarkSignature);235 benchmarkState!.progress = progress;236 const { executedIterations, avgIteration, estimated, runtime } = progress;237 const runIter = executedIterations.toString().padEnd(5, " ");238 const avgIter = `${avgIteration.toFixed(2)}ms`.padEnd(10, " ");239 const remaining = estimated - runtime;240 if (this.isInteractive) {241 this.scheduleUpdate();242 } else {243 this.scheduleUpdate(2500, () => {244 this.stdoutWrite(...

Full Screen

Full Screen

UpdateRunnerState.js

Source:UpdateRunnerState.js Github

copy

Full Screen

1const chakram = require('chakram');2const expect = chakram.expect;3const config = require('config');4const exec = require('child_process').execSync;5const resolve = require('path').resolve;6function getUrl(buildUrn, stage, runner) {7 return `http://localhost:${config.httpPort}/build/${encodeURIComponent(buildUrn)}/${stage}/${runner}`;8}9describe('UpdateRunnerState', function () {10 before(function () {11 this.timeout(15000);12 exec('make mongo-restore', {cwd: resolve(__dirname, '../../../../')});13 });14 it('updates state of runner, stage & build', function () {15 const url = getUrl('urn:gh:knplabs/gaufrette:1', 1, 'php-cs-fixer');16 const response = chakram.patch(url, {state: 'failed'});17 expect(response).to.have.status(200);18 expect(response).to.have.json({19 buildId: "1",20 projectUrn: "urn:gh:knplabs/gaufrette",21 branch: "master",22 repoUrl: "https://github.com/knplabs/gaufrette",23 state: "failed",24 stages: [25 {26 "state": "failed",27 "runners": {28 "php-cs-fixer": "failed",29 "phpqa": "succeeded"30 }31 }32 ]33 });34 return chakram.wait();35 });36 it('ends running stage and starts next one', function () {37 const url = getUrl('urn:gh:knplabs/gaufrette:3', 1, 'build');38 const response = chakram.patch(url, {state: 'succeeded'});39 expect(response).to.have.status(200);40 expect(response).to.have.json({41 buildId: "3",42 projectUrn: "urn:gh:knplabs/gaufrette",43 branch: "master",44 repoUrl: "https://github.com/knplabs/gaufrette",45 state: "running",46 stages: [47 {48 "state": "succeeded",49 "runners": {50 "build": "succeeded"51 }52 },53 {54 "state": "running",55 "runners": {56 "php-cs-fixer": "queued",57 "phpqa": "queued",58 "phpspec": "queued",59 "behat": "queued"60 }61 },62 {63 "state": "pending",64 "runners": {65 "deploy": "pending"66 }67 }68 ]69 });70 return chakram.wait();71 });72 it('returns 400 InvalidState if the state is not valid', function () {73 const url = getUrl('urn:gh:knplabs/gaufrette:3', 2, 'php-cs-fixer');74 const response = chakram.patch(url, {state: 'unknown'});75 expect(response).to.have.status(400);76 expect(response).to.have.json({error: 'InvalidState'});77 return chakram.wait();78 });79 it('returns 404 BuildNotFound if build does not exist', function () {80 const url = getUrl('urn:gh:knplabs/gaufrette:12345', 1, 'php-cs-fixer');81 const response = chakram.patch(url, {state: 'failed'});82 expect(response).to.have.status(404);83 expect(response).to.have.json({error: 'BuildNotFound'});84 return chakram.wait();85 });86 it('returns 404 StageNotFound if stage does not exist', function () {87 const url = getUrl('urn:gh:knplabs/gaufrette:3', 10, 'php-cs-fixer');88 const response = chakram.patch(url, {state: 'failed'});89 expect(response).to.have.status(404);90 expect(response).to.have.json({error: 'StageNotFound'});91 return chakram.wait();92 });93 it('returns 404 RunnerNotFound if runner does not exist', function () {94 const url = getUrl('urn:gh:knplabs/gaufrette:3', 2, 'unknown');95 const response = chakram.patch(url, {state: 'failed'});96 expect(response).to.have.status(404);97 expect(response).to.have.json({error: 'RunnerNotFound'});98 return chakram.wait();99 });100 it('returns 400 BuildNotRunning if the build is not started yet', function () {101 const url = getUrl('urn:gh:knplabs/gaufrette:2', 1, 'php-cs-fixer');102 const response = chakram.patch(url, {state: 'running'});103 expect(response).to.have.status(400);104 expect(response).to.have.json({error: 'BuildNotRunning'});105 return chakram.wait();106 });107 it('returns 400 StageNotRunning if the stage is not running yet', function () {108 const url = getUrl('urn:gh:knplabs/gaufrette:3', 3, 'deploy');109 const response = chakram.patch(url, {state: 'running'});110 expect(response).to.have.status(400);111 expect(response).to.have.json({error: 'StageNotRunning'});112 return chakram.wait();113 });114 it('returns 400 TransitionDisallowed if the transition from the stored to the submitted state is not possible', function () {115 const url = getUrl('urn:gh:knplabs/gaufrette:4', 1, 'deploy');116 const response = chakram.patch(url, {state: 'failed'});117 expect(response).to.have.status(400);118 expect(response).to.have.json({error: 'TransitionDisallowed'});119 return chakram.wait();120 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var bestPracticeRunner = new BestPracticeRunner();2bestPracticeRunner.updateRunnerState("Running");3var bestPracticeRunner = new BestPracticeRunner();4bestPracticeRunner.updateRunnerState("Stopped");5var bestPracticeRunner = new BestPracticeRunner();6bestPracticeRunner.updateRunnerState("Completed");7var bestPracticeRunner = new BestPracticeRunner();8bestPracticeRunner.updateRunnerState("Invalid");9var bestPracticeRunner = new BestPracticeRunner();10bestPracticeRunner.updateRunnerState("Completed");11var bestPracticeRunner = new BestPracticeRunner();12bestPracticeRunner.updateRunnerState("Stopped");13var bestPracticeRunner = new BestPracticeRunner();14bestPracticeRunner.updateRunnerState("Running");15var bestPracticeRunner = new BestPracticeRunner();16bestPracticeRunner.updateRunnerState("Running");17var bestPracticeRunner = new BestPracticeRunner();18bestPracticeRunner.updateRunnerState("Completed");19var bestPracticeRunner = new BestPracticeRunner();20bestPracticeRunner.updateRunnerState("Stopped");21var bestPracticeRunner = new BestPracticeRunner();22bestPracticeRunner.updateRunnerState("Completed");23var bestPracticeRunner = new BestPracticeRunner();24bestPracticeRunner.updateRunnerState("Running");25var bestPracticeRunner = new BestPracticeRunner();

Full Screen

Using AI Code Generation

copy

Full Screen

1var bestPracticeRunner = new BestPracticeRunner();2bestPracticeRunner.updateRunnerState("RUNNING");3var bestPracticeRunner = new BestPracticeRunner();4bestPracticeRunner.updateRunnerState("STOPPED");5var bestPracticeRunner = new BestPracticeRunner();6bestPracticeRunner.updateRunnerState("RUNNING");7var bestPracticeRunner = new BestPracticeRunner();8bestPracticeRunner.updateRunnerState("STOPPED");9var bestPracticeRunner = new BestPracticeRunner();10bestPracticeRunner.updateRunnerState("RUNNING");11var bestPracticeRunner = new BestPracticeRunner();12bestPracticeRunner.updateRunnerState("STOPPED");13var bestPracticeRunner = new BestPracticeRunner();14bestPracticeRunner.updateRunnerState("RUNNING");15var bestPracticeRunner = new BestPracticeRunner();16bestPracticeRunner.updateRunnerState("STOPPED");17var bestPracticeRunner = new BestPracticeRunner();18bestPracticeRunner.updateRunnerState("RUNNING");19var bestPracticeRunner = new BestPracticeRunner();20bestPracticeRunner.updateRunnerState("STOPPED");21var bestPracticeRunner = new BestPracticeRunner();22bestPracticeRunner.updateRunnerState("RUNNING");23var bestPracticeRunner = new BestPracticeRunner();24bestPracticeRunner.updateRunnerState("STOPPED");

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestRunner = require('./bestRunner.js');2var bestRunner = new BestRunner();3bestRunner.updateRunnerState(1, 'running');4bestRunner.updateRunnerState(2, 'running');5bestRunner.updateRunnerState(3, 'running');6bestRunner.updateRunnerState(4, 'running');7bestRunner.updateRunnerState(5, 'running');8bestRunner.updateRunnerState(6, 'running');9bestRunner.updateRunnerState(7, 'running');10bestRunner.updateRunnerState(8, 'running');11bestRunner.updateRunnerState(9, 'running');12bestRunner.updateRunnerState(10, 'running');13bestRunner.updateRunnerState(11, 'running');14bestRunner.updateRunnerState(12, 'running');15bestRunner.updateRunnerState(13, 'running');16bestRunner.updateRunnerState(14, 'running');17bestRunner.updateRunnerState(15, 'running');18bestRunner.updateRunnerState(16, 'running');19bestRunner.updateRunnerState(17, 'running');20bestRunner.updateRunnerState(18, 'running');21bestRunner.updateRunnerState(19, 'running');22bestRunner.updateRunnerState(20, 'running');23bestRunner.updateRunnerState(21, 'running');24bestRunner.updateRunnerState(22, 'running');25bestRunner.updateRunnerState(23, 'running');26bestRunner.updateRunnerState(24, 'running');27bestRunner.updateRunnerState(25, 'running');28bestRunner.updateRunnerState(26, 'running');29bestRunner.updateRunnerState(27, 'running');30bestRunner.updateRunnerState(28, 'running');31bestRunner.updateRunnerState(29, 'running');32bestRunner.updateRunnerState(30, 'running');33bestRunner.updateRunnerState(31, 'running');34bestRunner.updateRunnerState(32, 'running');35bestRunner.updateRunnerState(33, 'running');36bestRunner.updateRunnerState(34, 'running');37bestRunner.updateRunnerState(35, 'running');38bestRunner.updateRunnerState(36, 'running');39bestRunner.updateRunnerState(37, 'running');40bestRunner.updateRunnerState(38, 'running');41bestRunner.updateRunnerState(39, 'running');42bestRunner.updateRunnerState(40, 'running');43bestRunner.updateRunnerState(41, 'running');44bestRunner.updateRunnerState(42, 'running');45bestRunner.updateRunnerState(43, 'running');

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestBuyRunner = require('./BestBuyRunner.js');2var runner = new BestBuyRunner();3runner.updateRunnerState("Test4", "Test4", "Test4", "Test4", "Test4", "Test4", "Test4", "Test4");4var RunnerState = require('./RunnerState.js');5var runnerState = new RunnerState();6var runnerState = runnerState.updateRunnerState("Test4", "Test4", "Test4", "Test4", "Test4", "Test4", "Test4", "Test4");7var RunnerState = function() {8 this.updateRunnerState = function(updateRunnerState) {9 console.log("RunnerState");10 }11}12module.exports = RunnerState;

Full Screen

Using AI Code Generation

copy

Full Screen

1var bestTestRunner = require('BestTestRunner');2var testRunnerState = bestTestRunner.updateRunnerState('RUNNING');3console.log('testRunnerState: ' + testRunnerState);4var bestTestRunner = require('BestTestRunner');5var testState = bestTestRunner.updateTestState('PASSED');6console.log('testState: ' + testState);7var bestTestRunner = require('BestTestRunner');8var testStepState = bestTestRunner.updateTestStepState('FAILED');9console.log('testStepState: ' + testStepState);10var bestTestRunner = require('BestTestRunner');11var testStepOutput = bestTestRunner.updateTestStepOutput('test step output');12console.log('testStepOutput: ' + testStepOutput);13var bestTestRunner = require('BestTestRunner');14var testStepOutput = bestTestRunner.updateTestStepOutput('test step output');15console.log('testStepOutput: ' + testStepOutput);

Full Screen

Using AI Code Generation

copy

Full Screen

1const BestBuyRunner = require('./BestBuyRunner');2var runner = new BestBuyRunner();3runner.updateRunnerState("IN_PROGRESS").then((result) => {4 console.log(result);5 runner.updateRunnerState("COMPLETED").then((result) => {6 console.log(result);7 }).catch((err) => {8 console.log(err);9 });10}).catch((err) => {11 console.log(err);12});13const BestBuyRunner = require('./BestBuyRunner');14var runner = new BestBuyRunner();15runner.updateRunnerState("IN_PROGRESS").then((result) => {16 console.log(result);17 runner.updateRunnerState("COMPLETED").then((result) => {18 console.log(result);19 }).catch((err) => {20 console.log(err);21 });22}).catch((err) => {23 console.log(err);24});25class BestBuyRunner {26 constructor() {27 this.runnerState = "NOT_STARTED";28 }29 updateRunnerState(state) {30 return new Promise((resolve, reject) => {31 if (this.runnerState === "NOT_STARTED" && state === "IN_PROGRESS") {32 this.runnerState = state;33 resolve("Runner state updated to IN_PROGRESS");34 } else if (this.runnerState === "IN_PROGRESS" && state === "COMPLETED") {35 this.runnerState = state;36 resolve("Runner state updated to COMPLETED");37 } else {38 reject("Invalid state transition");39 }40 });41 }42}43module.exports = BestBuyRunner;44class BestBuyRunner {45 constructor() {46 this.runnerState = "NOT_STARTED";47 }48 updateRunnerState(state) {49 return new Promise((resolve, reject) => {50 if (this.runnerState === "NOT_STARTED" && state === "IN_PROGRESS") {51 this.runnerState = state;52 resolve("Runner state updated to IN_PROGRESS");53 } else if (this.runnerState === "IN_PROGRESS" && state === "COMPLETED") {54 this.runnerState = state;

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestBuyRunner = require('./BestBuyRunner');2var bestBuyRunner = new BestBuyRunner();3bestBuyRunner.updateRunnerState('running');4console.log(bestBuyRunner.runnerState);5bestBuyRunner.updateRunnerState('stopped');6console.log(bestBuyRunner.runnerState);7module.exports = BestBuyRunner;8function BestBuyRunner() {9 this.runnerState = 'stopped';10 this.updateRunnerState = function (state) {11 this.runnerState = state;12 }13}14module.exports = BestBuyRunner;15function BestBuyRunner() {16 this.runnerState = 'stopped';17 this.updateRunnerState = function (state) {18 this.runnerState = state;19 }20}21module.exports = BestBuyRunner;22function BestBuyRunner() {23 this.runnerState = 'stopped';24 this.updateRunnerState = function (state) {25 this.runnerState = state;26 }27}28module.exports = BestBuyRunner;29function BestBuyRunner() {30 this.runnerState = 'stopped';31 this.updateRunnerState = function (state) {32 this.runnerState = state;33 }34}35module.exports = BestBuyRunner;36function BestBuyRunner() {37 this.runnerState = 'stopped';38 this.updateRunnerState = function (state) {39 this.runnerState = state;40 }41}

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 Best 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