Best JavaScript code snippet using tracetest
admin-worker.worker.spec.js
Source:admin-worker.worker.spec.js
...53 });54 it('should call the consume call once', async () => {55 expect(succeed).toHaveBeenCalledTimes(0);56 expect(failing).toHaveBeenCalledTimes(0);57 expect(messageQueueServiceMock.startTimes()).toBe(1);58 await finishPendingTimeouts();59 expect(succeed).toHaveBeenCalledTimes(1);60 expect(failing).toHaveBeenCalledTimes(0);61 messageQueueServiceMock.stopConsumeCall();62 expect(messageQueueServiceMock.startTimes()).toBe(2);63 await finishPendingTimeouts();64 expect(succeed).toHaveBeenCalledTimes(1);65 expect(failing).toHaveBeenCalledTimes(0);66 expect(messageQueueServiceMock.startTimes()).toBe(2);67 });68 it('should call the consume call 2 times', async () => {69 expect(succeed).toHaveBeenCalledTimes(0);70 expect(failing).toHaveBeenCalledTimes(0);71 expect(messageQueueServiceMock.startTimes()).toBe(1);72 await finishPendingTimeouts();73 expect(succeed).toHaveBeenCalledTimes(1);74 expect(failing).toHaveBeenCalledTimes(0);75 expect(messageQueueServiceMock.startTimes()).toBe(2);76 await finishPendingTimeouts();77 expect(succeed).toHaveBeenCalledTimes(2);78 expect(failing).toHaveBeenCalledTimes(0);79 expect(messageQueueServiceMock.startTimes()).toBe(3);80 messageQueueServiceMock.stopConsumeCall();81 });82 it('should fail at the 3rd call', async () => {83 expect(succeed).toHaveBeenCalledTimes(0);84 expect(failing).toHaveBeenCalledTimes(0);85 expect(messageQueueServiceMock.startTimes()).toBe(1);86 await finishPendingTimeouts();87 expect(succeed).toHaveBeenCalledTimes(1);88 expect(failing).toHaveBeenCalledTimes(0);89 expect(messageQueueServiceMock.startTimes()).toBe(2);90 await finishPendingTimeouts();91 expect(succeed).toHaveBeenCalledTimes(2);92 expect(failing).toHaveBeenCalledTimes(0);93 expect(messageQueueServiceMock.startTimes()).toBe(3);94 await finishPendingTimeouts();95 expect(succeed).toHaveBeenCalledTimes(2);96 expect(failing).toHaveBeenCalledTimes(1);97 messageQueueServiceMock.stopConsumeCall();98 });99 it('should restart at the 4th call', async () => {100 expect(succeed).toHaveBeenCalledTimes(0);101 expect(failing).toHaveBeenCalledTimes(0);102 expect(messageQueueServiceMock.startTimes()).toBe(1);103 await finishPendingTimeouts();104 expect(succeed).toHaveBeenCalledTimes(1);105 expect(failing).toHaveBeenCalledTimes(0);106 expect(messageQueueServiceMock.startTimes()).toBe(2);107 await finishPendingTimeouts();108 expect(succeed).toHaveBeenCalledTimes(2);109 expect(failing).toHaveBeenCalledTimes(0);110 expect(messageQueueServiceMock.startTimes()).toBe(3);111 await finishPendingTimeouts();112 expect(succeed).toHaveBeenCalledTimes(2);113 expect(failing).toHaveBeenCalledTimes(1); // first error114 await finishPendingTimeouts(); // restart timeout115 expect(messageQueueServiceMock.startTimes()).toBe(4);116 await finishPendingTimeouts(); // finish consume call117 expect(succeed).toHaveBeenCalledTimes(3);118 expect(failing).toHaveBeenCalledTimes(1);119 messageQueueServiceMock.stopConsumeCall();120 });121 it('should have success at the 5th call', async () => {122 expect(succeed).toHaveBeenCalledTimes(0);123 expect(failing).toHaveBeenCalledTimes(0);124 expect(messageQueueServiceMock.startTimes()).toBe(1);125 await finishPendingTimeouts();126 expect(succeed).toHaveBeenCalledTimes(1);127 expect(failing).toHaveBeenCalledTimes(0);128 expect(messageQueueServiceMock.startTimes()).toBe(2);129 await finishPendingTimeouts();130 expect(succeed).toHaveBeenCalledTimes(2);131 expect(failing).toHaveBeenCalledTimes(0);132 expect(messageQueueServiceMock.startTimes()).toBe(3);133 await finishPendingTimeouts();134 expect(succeed).toHaveBeenCalledTimes(2);135 expect(failing).toHaveBeenCalledTimes(1); // first error136 await finishPendingTimeouts(); // restart timeout137 expect(messageQueueServiceMock.startTimes()).toBe(4);138 await finishPendingTimeouts(); // finish consume call139 expect(succeed).toHaveBeenCalledTimes(3);140 expect(failing).toHaveBeenCalledTimes(1);141 expect(messageQueueServiceMock.startTimes()).toBe(5);142 await finishPendingTimeouts();143 expect(succeed).toHaveBeenCalledTimes(4);144 expect(failing).toHaveBeenCalledTimes(1);145 messageQueueServiceMock.stopConsumeCall();146 });147 it('should have success at the 6th call', async () => {148 expect(succeed).toHaveBeenCalledTimes(0);149 expect(failing).toHaveBeenCalledTimes(0);150 expect(messageQueueServiceMock.startTimes()).toBe(1);151 await finishPendingTimeouts();152 expect(succeed).toHaveBeenCalledTimes(1);153 expect(failing).toHaveBeenCalledTimes(0);154 expect(messageQueueServiceMock.startTimes()).toBe(2);155 await finishPendingTimeouts();156 expect(succeed).toHaveBeenCalledTimes(2);157 expect(failing).toHaveBeenCalledTimes(0);158 expect(messageQueueServiceMock.startTimes()).toBe(3);159 await finishPendingTimeouts();160 expect(succeed).toHaveBeenCalledTimes(2);161 expect(failing).toHaveBeenCalledTimes(1); // first error162 await finishPendingTimeouts(); // restart timeout163 expect(messageQueueServiceMock.startTimes()).toBe(4);164 await finishPendingTimeouts(); // finish consume call165 expect(succeed).toHaveBeenCalledTimes(3);166 expect(failing).toHaveBeenCalledTimes(1);167 expect(messageQueueServiceMock.startTimes()).toBe(5);168 await finishPendingTimeouts();169 expect(succeed).toHaveBeenCalledTimes(4);170 expect(failing).toHaveBeenCalledTimes(1);171 expect(messageQueueServiceMock.startTimes()).toBe(6);172 await finishPendingTimeouts();173 expect(succeed).toHaveBeenCalledTimes(5);174 expect(failing).toHaveBeenCalledTimes(1);175 messageQueueServiceMock.stopConsumeCall();176 });177 it('should have restart after 10 seconds', async () => {178 expect(succeed).toHaveBeenCalledTimes(0);179 expect(failing).toHaveBeenCalledTimes(0);180 expect(messageQueueServiceMock.startTimes()).toBe(1);181 await finishPendingTimeouts();182 expect(succeed).toHaveBeenCalledTimes(1);183 expect(failing).toHaveBeenCalledTimes(0);184 expect(messageQueueServiceMock.startTimes()).toBe(2);185 await finishPendingTimeouts();186 expect(succeed).toHaveBeenCalledTimes(2);187 expect(failing).toHaveBeenCalledTimes(0);188 expect(messageQueueServiceMock.startTimes()).toBe(3);189 await finishPendingTimeouts();190 expect(succeed).toHaveBeenCalledTimes(2);191 expect(failing).toHaveBeenCalledTimes(1); // first error192 await succeed; await failing;193 jest.advanceTimersByTime(10000); // wait 10 seconds194 expect(messageQueueServiceMock.startTimes()).toBe(4);195 await finishPendingTimeouts(); // finish consume call196 expect(succeed).toHaveBeenCalledTimes(3);197 expect(failing).toHaveBeenCalledTimes(1);198 expect(messageQueueServiceMock.startTimes()).toBe(5);199 await finishPendingTimeouts();200 expect(succeed).toHaveBeenCalledTimes(4);201 expect(failing).toHaveBeenCalledTimes(1);202 messageQueueServiceMock.stopConsumeCall();203 });204 it('should not restart before 10 seconds', async () => {205 expect(succeed).toHaveBeenCalledTimes(0);206 expect(failing).toHaveBeenCalledTimes(0);207 expect(messageQueueServiceMock.startTimes()).toBe(1);208 await finishPendingTimeouts();209 expect(succeed).toHaveBeenCalledTimes(1);210 expect(failing).toHaveBeenCalledTimes(0);211 expect(messageQueueServiceMock.startTimes()).toBe(2);212 await finishPendingTimeouts();213 expect(succeed).toHaveBeenCalledTimes(2);214 expect(failing).toHaveBeenCalledTimes(0);215 expect(messageQueueServiceMock.startTimes()).toBe(3);216 await finishPendingTimeouts();217 expect(succeed).toHaveBeenCalledTimes(2);218 expect(failing).toHaveBeenCalledTimes(1); // first error219 await succeed; await failing;220 jest.advanceTimersByTime(5000); // wait 5 seconds221 expect(messageQueueServiceMock.startTimes()).toBe(4);222 await finishPendingTimeouts(); // there should be no pending timeout223 expect(succeed).toHaveBeenCalledTimes(2);224 expect(failing).toHaveBeenCalledTimes(1);225 expect(messageQueueServiceMock.startTimes()).toBe(4);226 await finishPendingTimeouts();227 expect(succeed).toHaveBeenCalledTimes(3);228 expect(failing).toHaveBeenCalledTimes(1);229 messageQueueServiceMock.stopConsumeCall();230 });...
IndividualStartController.js
Source:IndividualStartController.js
1angular.module('skApp.IndividualStartController', [])2.controller('IndividualStartController', ['AppConfig', '$interval', 'IndividualService', 'PersistentStateService', function(AppConfig, $interval, IndividualService, PersistentStateService) {3 var self = this;4 var moment = require('moment');5 self.individualStartTime = AppConfig.indActiveEventStart;6 self.currentTime = false;7 self.startTimes = [];8 self.status = '';9 self.saveStart = function(idx) {10 if (typeof self.startTimes[idx].bikeType !== 'undefined' && typeof self.startTimes[idx].number !== 'undefined' && self.startTimes[idx].number !== null) {11 if (self.startTimes[idx].status !== 'confirmed') {12 self.startTimes[idx].status = 'saving';13 }14 IndividualService.query({15 eventYear: 2020, // @todo 202016 number: self.startTimes[idx].number,17 limit: 118 }, function(response) {19 if (response.length > 0) {20 if (response[0].start === null || self.startTimes[idx].status === 'confirmed') {21 response[0].start = self.startTimes[idx].strTime;22 response[0].bikeType = self.startTimes[idx].bikeType;23 self.startTimes[idx].name = response[0].name;24 IndividualService.update(response[0], function(response) {25 for (var i = 0; i < self.startTimes.length; i++) {26 if (self.startTimes[i].number === response.number && self.startTimes[i].strTime !== response.start) {27 self.startTimes[i].number = '';28 self.startTimes[i].name = '';29 self.startTimes[i].bikeType = '';30 self.startTimes[i].group = '';31 self.startTimes[i].status = '';32 }33 }34 self.startTimes[idx].status = 'saved';35 self.startTimes[idx].group = response.group;36 self.status = '';37 });38 } else {39 self.startTimes[idx].status = 'unconfirmed';40 self.status = 'invalid';41 }42 } else {43 self.startTimes[idx].status = 'failed';44 self.status = 'invalid';45 }46 });47 }48 };49 self.sec2humanReadable = function (duration) {50 var hour = 0;51 var min = 0;52 var sec = 0;53 if (duration) {54 if (duration >= 60) {55 min = Math.floor(duration / 60);56 sec = duration % 60;57 } else {58 sec = duration;59 }60 if (min >= 60) {61 hour = Math.floor(min / 60);62 min = min - hour * 60;63 }64 if (hour < 10) {65 hour = '0'+hour;66 }67 if (min < 10) {68 min = '0'+min;69 }70 if (sec < 10) {71 sec = '0'+sec;72 }73 }74 return hour +":"+ min +":"+ sec;75 }76 self.setStartTimes = function() {77 self.startTimes = [];78 var startAt = moment().subtract(80, 'seconds').diff(79 moment(self.individualStartTime),80 'seconds'81 );82 startAt = startAt - startAt%20;83 var humanTime = '';84 var timeQuery = '';85 for (var i = 0; i < 20; i++) {86 humanTime = self.sec2humanReadable(startAt);87 timeQuery = timeQuery + (timeQuery === '' ? '' : ',') + humanTime;88 self.startTimes.push({89 strTime: humanTime,90 time: startAt,91 });92 startAt = startAt + 20;93 }94 IndividualService.query({95 eventYear: 2020, // @todo 202096 start: timeQuery,97 limit: 20,98 }, function(response) {99 for (var i = 0; i < self.startTimes.length; i++) {100 for (var j = 0; j < response.length; j++) {101 if (self.startTimes[i].strTime === response[j].start) {102 self.startTimes[i].number = response[j].number;103 self.startTimes[i].bikeType = response[j].bikeType;104 self.startTimes[i].name = response[j].name;105 self.startTimes[i].group = response[j].group;106 self.startTimes[i].status = 'saved';107 response.splice(j, 1);108 }109 }110 }111 });112 };113 self.updateStartTimes = function() {114 if (self.status !== 'invalid') {115 var startAt = moment().diff(116 moment(self.individualStartTime),117 'seconds'118 );119 for (var i = 0; i < self.startTimes.length; i++) {120 if ((startAt - self.startTimes[i].time) > 80) {121 var x = self.startTimes.splice(i, 1);122 self.startTimes.push({123 strTime: self.sec2humanReadable(self.startTimes[self.startTimes.length-1].time+20),124 time: self.startTimes[self.startTimes.length-1].time+20,125 });126 }127 }128 }129 }130 if (false === PersistentStateService.startInterval) {131 PersistentStateService.startInterval = $interval(self.updateStartTimes, 1000);132 }133 self.setStartTimes();...
codefight-4-8-17-rough-notes.js
Source:codefight-4-8-17-rough-notes.js
1function backupTimeEstimator(startTimes, backupDuration, maxThreads) {2 var estimations = [[],[], []]; // start, end, backupDurationLeft3 var activeThreads = 0;4 var queue = [];5 var queueCandidate = null;6 var smallestBackup = Infinity;7 var time = startTimes[0];8 while (true) {9 // Time it will take to perform one more step of backup10 time += activeThreads;11 // Perform that one more step of backup on any active threads12 for (s in startTimes) {13 if (estimations[0].includes(startTimes[s])14 && estimations[2][estimations[0].indexOf(startTimes[s])] > 0) {15 estimations[1][estimations[0].indexOf(startTimes[s])] += time; // New end time estimate16 estimations[2][estimations[0].indexOf(startTimes[s])]17 }18 }19 // See what's done20 // Add new21 for (t in startTimes) {22 if (startTimes[t] <= time23 && !estimations[0].includes(startTimes[t])24 && !queue.includes(t)) {25 queue.push(t);26 }27 }28 while (activeThreads < maxThreads) {29 for (i in queue) {30 if (backupDuration[queue[i]] < smallestBackup) {31 smallestBackup = backupDuration[i];32 queueCandidate = queue[i]; // Index of particular backup start time and duration33 }34 }35 estimations[0].push(startTimes[queueCandidate]);36 estimations[1].push(time+backupDuration);37 queue.splice(indexOf(queueCandidate),1);38 activeThreads++;39 smallestBackup = Infinity;40 }41 // Advance everything 1 step42 queue = startTimes.filter(t => !estimations[0].includes(t)43 && t <= time && )44 break;45 }46 var time = startTimes[0];47 var nTimes = startTimes.length;48 var completionPercents = [[], [], []];49 var timeLeft = null;50 while (estimations.length < nTimes) {51 for (var i = 0; i <= activeThreads; i++) {52 }53 //add to queue54 //check if complete55 //56 for (t in startTimes) {57 // Add backup to queue58 if (59 time >= startTimes[t]60 && !completionPercents[0].includes(startTimes[t])61 && activeThreads < maxThreads62 ) {63 backupDuration64 activeThreads++;65 completionPercents[0].push(startTimes[t]);66 completionPercents[1].push(backupDuration[t]);67 completionPercents[2].push(0);68 }69 }70 time += 1*activeThreads71 for (a in completionPercents) {72 // Garbage-collecting73 if (completionPercents[a][2] >= 1) {74 estimations.push(time);75 completionPercents.splice(a, 1);76 }77 }78 // Account for backup time in completion time79 for (i in completionPercents) {80 timeLeft = completionPercents[i][1]*(1-completionPercents[i][2]);81 timeLeft -= 1/activeThreads;82 completionPercents[i][2] = 1 - timeLeft/backupDuration;83 }84 take away when done85 time++86 }87 for (var i = 1; i < startTimes.length; i++) {88 for (j in completionPercents) {89 completionPercents[j][]90 completionPercents[j][1]--;91 }92 if (activeThreads93 startTimes[i]94 }95 in startTimes) {96 if (activeThreads <= maxThreads) {97 activeThreads++;98 } else {99 completionPercents = [[startTimes[i], backupDuration[i], 0]];100 }101 }102 //tofixed...
Using AI Code Generation
1const tracetest = require('tracetest');2tracetest.startTimes();3const tracetest = require('tracetest');4tracetest.endTimes();5const tracetest = require('tracetest');6tracetest.getTimes();7### **startTimes()**8### **endTimes()**9### **getTimes()**10const tracetest = require('tracetest');11tracetest.startTimes();12const tracetest = require('tracetest');13tracetest.endTimes();14const tracetest = require('tracetest');15tracetest.getTimes();
Using AI Code Generation
1var trace = require('./tracetest');2trace.startTimes();3trace.stopTimes();4var times = trace.getTimes();5console.log(times);6trace.clearTimes();7trace.logTimes();8 times.push({start: new Date().getTime()});9};10 times[times.length-1].stop = new Date().getTime();11};12 return times;13};14 times = [];15};16 times.forEach(function(time) {17 console.log('Time: ' + (time.stop - time.start) + 'ms');18 });19};20module.exports.startTimes = startTimes;21module.exports.stopTimes = stopTimes;22module.exports.getTimes = getTimes;23module.exports.clearTimes = clearTimes;24module.exports.logTimes = logTimes;25[ { start: 1443469013169, stop: 1443469013170 } ]
Using AI Code Generation
1var TraceTest = require('./tracetest');2var traceTest = new TraceTest();3traceTest.startTimes();4var TraceTest = require('./tracetest');5var traceTest = new TraceTest();6traceTest.startTimes();7var TraceTest = require('./tracetest');8var traceTest = new TraceTest();9traceTest.startTimes();10var TraceTest = require('./tracetest');11var traceTest = new TraceTest();12traceTest.startTimes();13var TraceTest = require('./tracetest');14var traceTest = new TraceTest();15traceTest.startTimes();16var TraceTest = require('./tracetest');17var traceTest = new TraceTest();18traceTest.startTimes();19var TraceTest = require('./tracetest');20var traceTest = new TraceTest();21traceTest.startTimes();22var TraceTest = require('./tracetest');23var traceTest = new TraceTest();24traceTest.startTimes();25var TraceTest = require('./tracetest');26var traceTest = new TraceTest();27traceTest.startTimes();28var TraceTest = require('./tracetest');29var traceTest = new TraceTest();30traceTest.startTimes();31var TraceTest = require('./tracetest');32var traceTest = new TraceTest();33traceTest.startTimes();34var TraceTest = require('./tracetest');35var traceTest = new TraceTest();36traceTest.startTimes();
Using AI Code Generation
1const tracetest = require('tracetest');2const trace = new tracetest();3trace.startTimes();4trace.endTimes();5const tracetest = require('tracetest');6const trace = new tracetest();7trace.startTimes();8trace.endTimes();
Using AI Code Generation
1var tracetest = require('tracetest');2var trace = new tracetest.trace();3var startTime = trace.startTimes();4var endTime = trace.endTimes();5console.log(startTime);6console.log(endTime);7var trace = function() {8 this.startTimes = function() {9 return Date.now();10 };11 this.endTimes = function() {12 return Date.now();13 };14};15module.exports.trace = trace;
Using AI Code Generation
1var tracetest = require('tracetest');2tracetest.startTimes();3var myVar = setInterval(function(){myTimer()},1000);4function myTimer() {5 var d = new Date();6 console.log(d.toLocaleTimeString());7}8tracetest.endTimes();9The startTimes() and endTimes() methods are not necessary, but they are useful in a few cases. For example, if you want to measure the time that it takes to run a function, you could use the startTimes() and endTimes() methods to measure the time that it takes to
Using AI Code Generation
1var tracetest = require("./tracetest.js");2tracetest.startTimes();3var startTime = new Date();4var endTime = new Date();5var duration = endTime - startTime;6exports.startTimes = function() {7 startTime = new Date();8 console.log("Start time: " + startTime);9 endTimes();10}11function endTimes() {12 endTime = new Date();13 console.log("End time: " + endTime);14 duration = endTime - startTime;15 console.log("Duration: " + duration);16}17module.exports = {18};19var tracetest = require("./tracetest.js");20tracetest.startTimes();21tracetest.endTimes();
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!!