How to use idleAgentMatchingSpecs method in Best

Best JavaScript code snippet using best

hub.ts

Source:hub.ts Github

copy

Full Screen

...39 return clientSocket.disconnect(true);40 }41 const remoteClient = this.setupNewClient(clientSocket, config);42 console.log(`[HUB] Connected clients: ${this.connectedClients.size}`);43 if (this.idleAgentMatchingSpecs(remoteClient)) {44 this.runBenchmarks(remoteClient);45 } else {46 remoteClient.log(`Client enqueued. Waiting for an agent to be free...`);47 this.emit(BEST_RPC.AGENT_QUEUED_CLIENT, { clientId: remoteClient.getId(), jobs: config.jobs, specs: config.specs });48 }49 }50 setupNewClient(socketClient: Socket, clientConfig: RemoteClientConfig): RemoteClient {51 // Create and new RemoteClient and add it to the pool52 const remoteClient = new RemoteClient(socketClient, clientConfig);53 this.connectedClients.add(remoteClient);54 console.log(`[HUB] New client ${remoteClient.getId()} connected. Jobs requested ${clientConfig.jobs} | specs: ${JSON.stringify(clientConfig.specs)}`);55 this.emit(BEST_RPC.AGENT_CONNECTED_CLIENT, { clientId: remoteClient.getId(), jobs: clientConfig.jobs, specs: remoteClient.getSpecs() });56 // Make sure we remove it from an agent's perspective if the client is disconnected57 remoteClient.on(BEST_RPC.DISCONNECT, () => {58 console.log(`[HUB] Disconnected client ${remoteClient.getId()}`);59 this.emit(BEST_RPC.AGENT_DISCONNECTED_CLIENT, remoteClient.getId());60 this.connectedClients.delete(remoteClient);61 console.log(`[HUB] Connected clients: ${this.connectedClients.size}`);62 // If the client is actively running something we need to kill it63 if (this.activeClients.has(remoteClient)) {64 const remoteAgent = this.activeClients.get(remoteClient);65 if (remoteAgent && remoteAgent.isBusy()) {66 remoteAgent.interruptRunner();67 }68 this.activeClients.delete(remoteClient);69 }70 });71 remoteClient.on(BEST_RPC.BENCHMARK_START, (benchmarkId: string) => {72 const agent = this.activeClients.get(remoteClient);73 this.emit(BEST_RPC.BENCHMARK_START, { agentId: agent && agent.getId(), clientId: remoteClient.getId(), benchmarkId });74 });75 remoteClient.on(BEST_RPC.BENCHMARK_END, (benchmarkId: string) => {76 const agent = this.activeClients.get(remoteClient);77 this.emit(BEST_RPC.BENCHMARK_END, { agentId: agent && agent.getId(), clientId: remoteClient.getId(), benchmarkId });78 });79 remoteClient.on(BEST_RPC.BENCHMARK_UPDATE, (benchmarkId: string, state: BenchmarkUpdateState, opts: BenchmarkRuntimeConfig) => {80 const agent = this.activeClients.get(remoteClient);81 this.emit(BEST_RPC.BENCHMARK_UPDATE, { agentId: agent && agent.getId(), clientId: remoteClient.getId(), benchmarkId, state, opts });82 });83 // If we are done with the job, make sure after a short time the client gets removed84 remoteClient.on(BEST_RPC.REMOTE_CLIENT_EMPTY_QUEUE, () => {85 console.log(`[HUB] Remote client ${remoteClient.getId()} is done. Scheduling a force disconnect.`);86 setTimeout(() => {87 if (this.connectedClients.has(remoteClient)) {88 console.log(`[HUB] Force client disconnect (${remoteClient.getId()}): With no more jobs to run an agent must disconnect`);89 remoteClient.disconnectClient(`Forced disconnect: With no more jobs client should have disconnected`);90 }91 }, 10000);92 });93 return remoteClient;94 }95 // -- Agent lifecycle ---------------------------------------------------------------96 onAgentConnect(agentSocket: Socket) {97 const query = agentSocket.handshake.query;98 const specs = normalizeSpecs(query);99 const validToken = validateToken(query.authToken as string, this.hubConfig.authToken);100 const hasSpecs = specs.length > 0;101 if (!validToken) {102 agentSocket.emit(BEST_RPC.AGENT_REJECTION, 'Invalid Token');103 return agentSocket.disconnect(true);104 }105 if (!hasSpecs) {106 agentSocket.emit(BEST_RPC.AGENT_REJECTION, 'An agent must provide specs');107 return agentSocket.disconnect(true);108 }109 if (!query.agentUri) {110 agentSocket.emit(BEST_RPC.AGENT_REJECTION, 'An agent must provide a URI');111 return agentSocket.disconnect(true);112 }113 const remoteAgent = this.setupNewAgent(agentSocket, specs, { agentUri: query.agentUri, agentToken: query.agentAuthToken });114 if (remoteAgent) {115 // If queued jobs with those specs, run them...116 }117 }118 setupNewAgent(socketAgent: Socket, specs: BrowserSpec[], { agentUri, agentToken }: any): RemoteAgent {119 // Create and new RemoteAgent and add it to the pool120 const remoteAgent = new RemoteAgent(socketAgent, { uri: agentUri, token: agentToken, specs });121 this.connectedAgents.add(remoteAgent);122 console.log(`[HUB] New Agent ${remoteAgent.getId()} connected with specs: ${JSON.stringify(remoteAgent.getSpecs())}`);123 this.emit(BEST_RPC.HUB_CONNECTED_AGENT, { agentId: remoteAgent.getId(), specs: remoteAgent.getSpecs(), uri: remoteAgent.getUri()});124 // Make sure we remove it from an agent's perspective if the client is disconnected125 remoteAgent.on(BEST_RPC.DISCONNECT, () => {126 console.log(`[HUB] Disconnected Agent ${remoteAgent.getId()}`);127 this.emit(BEST_RPC.HUB_DISCONNECTED_AGENT, { agentId: remoteAgent.getId() });128 this.connectedAgents.delete(remoteAgent);129 if (remoteAgent.isBusy()) {130 remoteAgent.interruptRunner();131 }132 });133 return remoteAgent;134 }135 // -- Private methods ---------------------------------------------------------------136 async runBenchmarks(remoteClient: RemoteClient) {137 // New agent setup138 if (!this.activeClients.has(remoteClient)) {139 const matchingAgents = this.findAgentMatchingSpecs(remoteClient, { ignoreBusy: true });140 if (matchingAgents.length > 0) {141 const remoteAgent = matchingAgents[0];142 this.activeClients.set(remoteClient, remoteAgent);143 this.emit(BEST_RPC.AGENT_RUNNING_CLIENT, { clientId: remoteClient.getId(), agentId: remoteAgent.getId(), jobs: remoteClient.getPendingBenchmarks() });144 try {145 await remoteAgent.runBenchmarks(remoteClient);146 } catch(err) {147 console.log(`[HUB] Error running benchmark for remote client ${remoteClient.getId()}`);148 remoteClient.disconnectClient(`Error running benchmark ${err}`); // make sure we disconnect the agent149 } finally {150 this.activeClients.delete(remoteClient);151 queueMicrotask(() => this.runQueuedBenchmarks());152 }153 } else {154 console.log('[HUB] All agents are busy at this moment...');155 }156 } else {157 console.log(`[HUB] Client ${remoteClient.getId()} is actively running already`)158 }159 }160 runQueuedBenchmarks() {161 Array.from(this.connectedClients).forEach((remoteClient) => {162 if (!this.activeClients.has(remoteClient)) {163 if (this.idleAgentMatchingSpecs(remoteClient) && remoteClient.getPendingBenchmarks() > 0) {164 console.log(`[HUB] Running benchmark: "${remoteClient.getId()}" has ${remoteClient.getPendingBenchmarks()} to run`);165 this.runBenchmarks(remoteClient);166 } else {167 console.log(`[HUB] All matching agents still busy for ${remoteClient.getId()}`);168 }169 }170 });171 }172 getAgentSpecs(): BrowserSpec[] {173 const specs: BrowserSpec[] = [];174 for (const agent of this.connectedAgents) {175 specs.push(...agent.getSpecs());176 }177 return specs;178 }179 idleAgentMatchingSpecs(remoteClient: RemoteClient): boolean {180 return this.findAgentMatchingSpecs(remoteClient, { ignoreBusy: true }).length > 0;181 }182 findAgentMatchingSpecs(remoteClient: RemoteClient, { ignoreBusy }: { ignoreBusy?: boolean } = {}): RemoteAgent[] {183 const specs = remoteClient.getSpecs();184 const agents: RemoteAgent[] = [];185 if (specs) {186 for (const agent of this.connectedAgents) {187 const matchesSpecs = matchSpecs(specs, agent.getSpecs() || []);188 const matchesFilterCriteria = ignoreBusy ? !agent.isBusy(): true;189 if (matchesSpecs && matchesFilterCriteria) {190 agents.push(agent);191 }192 }193 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var scheduler = new BestFitScheduler();2var agent1 = new Agent(1, 2, 2, 2);3var agent2 = new Agent(2, 1, 1, 1);4var agent3 = new Agent(3, 3, 3, 3);5var agent4 = new Agent(4, 4, 4, 4);6var agent5 = new Agent(5, 5, 5, 5);7var agent6 = new Agent(6, 6, 6, 6);8var agent7 = new Agent(7, 7, 7, 7);9var agent8 = new Agent(8, 8, 8, 8);10var agent9 = new Agent(9, 9, 9, 9);11var agent10 = new Agent(10, 10, 10, 10);12var agent11 = new Agent(11, 11, 11, 11);13var agent12 = new Agent(12, 12, 12, 12);14var agent13 = new Agent(13, 13, 13, 13);15var agent14 = new Agent(14, 14, 14, 14);16var agent15 = new Agent(15, 15, 15, 15);17var agent16 = new Agent(16, 16, 16, 16);18var agent17 = new Agent(17, 17, 17, 17);19var agent18 = new Agent(18, 18, 18, 18);20var agent19 = new Agent(19, 19, 19, 19);21var agent20 = new Agent(20, 20, 20, 20);22var agent21 = new Agent(21, 21, 21, 21);23var agent22 = new Agent(22, 22, 22, 22);24var agent23 = new Agent(23, 23, 23, 23);25var agent24 = new Agent(24, 24, 24, 24);26var agent25 = new Agent(25, 25, 25, 25);27var agent26 = new Agent(26, 26, 26, 26);28var agent27 = new Agent(27, 27, 27, 27);

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestAgentFinder = require('./BestAgentFinder');2var bestAgentFinder = new BestAgentFinder();3var result = bestAgentFinder.idleAgentMatchingSpecs("java", "linux");4console.log(result);5var BestAgentFinder = require('./BestAgentFinder');6var bestAgentFinder = new BestAgentFinder();7var result = bestAgentFinder.idleAgentMatchingSpecs("java", "windows");8console.log(result);9var BestAgentFinder = require('./BestAgentFinder');10var bestAgentFinder = new BestAgentFinder();11var result = bestAgentFinder.idleAgentMatchingSpecs("java", "mac");12console.log(result);13var BestAgentFinder = require('./BestAgentFinder');14var bestAgentFinder = new BestAgentFinder();15var result = bestAgentFinder.idleAgentMatchingSpecs("c++", "linux");16console.log(result);17var BestAgentFinder = require('./BestAgentFinder');18var bestAgentFinder = new BestAgentFinder();19var result = bestAgentFinder.idleAgentMatchingSpecs("c++", "windows");20console.log(result);21var BestAgentFinder = require('./BestAgentFinder');22var bestAgentFinder = new BestAgentFinder();23var result = bestAgentFinder.idleAgentMatchingSpecs("c++", "mac");24console.log(result);25var BestAgentFinder = require('./BestAgentFinder');26var bestAgentFinder = new BestAgentFinder();27var result = bestAgentFinder.idleAgentMatchingSpecs("c", "linux");28console.log(result);29var BestAgentFinder = require('./BestAgentFinder');30var bestAgentFinder = new BestAgentFinder();

Full Screen

Using AI Code Generation

copy

Full Screen

1var bestMatchAgentSelector = new BestMatchAgentSelector();2var idleAgents = bestMatchAgentSelector.idleAgentMatchingSpecs(agentList, agentSpecs, "test4");3var bestMatchAgentSelector = new BestMatchAgentSelector();4var idleAgents = bestMatchAgentSelector.idleAgentMatchingSpecs(agentList, agentSpecs, "test5");5var bestMatchAgentSelector = new BestMatchAgentSelector();6var idleAgents = bestMatchAgentSelector.idleAgentMatchingSpecs(agentList, agentSpecs, "test6");7var bestMatchAgentSelector = new BestMatchAgentSelector();8var idleAgents = bestMatchAgentSelector.idleAgentMatchingSpecs(agentList, agentSpecs, "test7");9var bestMatchAgentSelector = new BestMatchAgentSelector();10var idleAgents = bestMatchAgentSelector.idleAgentMatchingSpecs(agentList, agentSpecs, "test8");11var bestMatchAgentSelector = new BestMatchAgentSelector();12var idleAgents = bestMatchAgentSelector.idleAgentMatchingSpecs(agentList, agentSpecs, "test9");13var bestMatchAgentSelector = new BestMatchAgentSelector();14var idleAgents = bestMatchAgentSelector.idleAgentMatchingSpecs(agentList, agentSpecs, "test10");15var bestMatchAgentSelector = new BestMatchAgentSelector();16var idleAgents = bestMatchAgentSelector.idleAgentMatchingSpecs(agentList, agentSpecs, "test11");17var bestMatchAgentSelector = new BestMatchAgentSelector();

Full Screen

Using AI Code Generation

copy

Full Screen

1var agentFinder = new BestFitAgentFinder();2var agent = agentFinder.idleAgentMatchingSpecs(specs);3if (agent != null) {4 agent.startJob(job);5} else {6 jobQueue.addJob(job);7}8var agentFinder = new BestFitAgentFinder();9var agent = agentFinder.idleAgentMatchingSpecs(specs);10if (agent != null) {11 agent.startJob(job);12} else {13 jobQueue.addJob(job);14}15var agentFinder = new BestFitAgentFinder();16var agent = agentFinder.idleAgentMatchingSpecs(specs);17if (agent != null) {18 agent.startJob(job);19} else {20 jobQueue.addJob(job);21}22var agentFinder = new BestFitAgentFinder();23var agent = agentFinder.idleAgentMatchingSpecs(specs);24if (agent != null) {25 agent.startJob(job);26} else {27 jobQueue.addJob(job);28}29var agentFinder = new BestFitAgentFinder();30var agent = agentFinder.idleAgentMatchingSpecs(specs);31if (agent != null) {32 agent.startJob(job);33} else {34 jobQueue.addJob(job);35}36var agentFinder = new BestFitAgentFinder();37var agent = agentFinder.idleAgentMatchingSpecs(specs);38if (agent != null) {39 agent.startJob(job);40} else {41 jobQueue.addJob(job);42}43var agentFinder = new BestFitAgentFinder();44var agent = agentFinder.idleAgentMatchingSpecs(specs);45if (agent != null) {46 agent.startJob(job);47} else {48 jobQueue.addJob(job);49}

Full Screen

Using AI Code Generation

copy

Full Screen

1var agentFinder = require('./agentFinder');2var agentFinder = new agentFinder();3var idleAgents = agentFinder.idleAgentMatchingSpecs(specs);4console.log(idleAgents);5console.log(idleAgents.length);6var agentFinder = require('./agentFinder');7var agentFinder = new agentFinder();8var idleAgents = agentFinder.idleAgentMatchingSpecs(specs);9console.log(idleAgents);10console.log(idleAgents.length);11var agentFinder = require('./agentFinder');12var agentFinder = new agentFinder();13var idleAgents = agentFinder.idleAgentMatchingSpecs(specs);14console.log(idleAgents);15console.log(idleAgents.length);16var agentFinder = require('./agentFinder');17var agentFinder = new agentFinder();18var idleAgents = agentFinder.idleAgentMatchingSpecs(specs);19console.log(idleAgents);20console.log(idleAgents.length);21var agentFinder = require('./agentFinder');22var agentFinder = new agentFinder();23var idleAgents = agentFinder.idleAgentMatchingSpecs(specs);24console.log(idleAgents);25console.log(idleAgents.length);26var agentFinder = require('./agentFinder');27var agentFinder = new agentFinder();28var idleAgents = agentFinder.idleAgentMatchingSpecs(specs);29console.log(idleAgents);30console.log(idleAgents.length);31var agentFinder = require('./agentFinder');

Full Screen

Using AI Code Generation

copy

Full Screen

1var idleAgentMatchingSpecs = require('./BestMatchAgentFinder').idleAgentMatchingSpecs;2 {3 specs: {4 }5 },6 {7 specs: {8 }9 },10 {11 specs: {12 }13 },14 {15 specs: {16 }17 }18];19var idleAgentMatchingSpecs = require('./BestMatchAgentFinder').idleAgentMatchingSpecs;20var idleAgents = idleAgentMatchingSpecs(agents, {21});22console.log('idle agents matching given specs:');23console.log(idleAgents);

Full Screen

Using AI Code Generation

copy

Full Screen

1var request = require('request');2var async = require('async');3var _ = require('underscore');4var fs = require('fs');5var agentIdArray = [];6var agentId = 0;7var agentIdleTime = 0;8var agentIdleTimeArray = [];9var agentIdleTimeArray1 = [];10var agentIdleTimeArray2 = [];11var agentIdleTimeArray3 = [];12var agentIdleTimeArray4 = [];13var agentIdleTimeArray5 = [];14var agentIdleTimeArray6 = [];15var agentIdleTimeArray7 = [];16var agentIdleTimeArray8 = [];17var agentIdleTimeArray9 = [];18var agentIdleTimeArray10 = [];19var agentIdleTimeArray11 = [];20var agentIdleTimeArray12 = [];21var agentIdleTimeArray13 = [];22var agentIdleTimeArray14 = [];23var agentIdleTimeArray15 = [];24var agentIdleTimeArray16 = [];25var agentIdleTimeArray17 = [];26var agentIdleTimeArray18 = [];27var agentIdleTimeArray19 = [];28var agentIdleTimeArray20 = [];29var agentIdleTimeArray21 = [];30var agentIdleTimeArray22 = [];31var agentIdleTimeArray23 = [];32var agentIdleTimeArray24 = [];33var agentIdleTimeArray25 = [];34var agentIdleTimeArray26 = [];35var agentIdleTimeArray27 = [];36var agentIdleTimeArray28 = [];37var agentIdleTimeArray29 = [];38var agentIdleTimeArray30 = [];39var agentIdleTimeArray31 = [];40var agentIdleTimeArray32 = [];41var agentIdleTimeArray33 = [];42var agentIdleTimeArray34 = [];43var agentIdleTimeArray35 = [];44var agentIdleTimeArray36 = [];45var agentIdleTimeArray37 = [];46var agentIdleTimeArray38 = [];47var agentIdleTimeArray39 = [];48var agentIdleTimeArray40 = [];49var agentIdleTimeArray41 = [];50var agentIdleTimeArray42 = [];51var agentIdleTimeArray43 = [];52var agentIdleTimeArray44 = [];53var agentIdleTimeArray45 = [];54var agentIdleTimeArray46 = [];55var agentIdleTimeArray47 = [];56var agentIdleTimeArray48 = [];57var agentIdleTimeArray49 = [];58var agentIdleTimeArray50 = [];59var agentIdleTimeArray51 = [];60var agentIdleTimeArray52 = [];

Full Screen

Using AI Code Generation

copy

Full Screen

1let agentFinder = require('best-agent-finder');2let agentSpec = {3}4agentFinder.idleAgentMatchingSpecs(agentSpec, function(err, agent) {5 if (err) {6 console.log('Error: ' + err);7 } else {8 console.log('Agent: ' + agent);9 }10});11let agentFinder = require('best-agent-finder');12let agentSpec = {13}14agentFinder.idleAgentMatchingSpecs(agentSpec, function(err, agent) {15 if (err) {16 console.log('Error: ' + err);17 } else {18 console.log('Agent: ' + agent);19 }20});21let agentFinder = require('best-agent-finder');22let agentSpec = {23}24agentFinder.idleAgentMatchingSpecs(agentSpec, function(err, agent) {25 if (err) {26 console.log('Error: ' + err);27 } else {28 console.log('Agent: ' + agent);29 }30});31let agentFinder = require('best-agent-finder');32let agentSpec = {

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