Skip to content

Commit

Permalink
fix: Best agent configuration and forwarding methods (#98)
Browse files Browse the repository at this point in the history
* feat: Entry point for agent

* fix: Port env

* fix: Add error handler

* fix: Adding comment
  • Loading branch information
diervo authored Mar 19, 2018
1 parent a6410d2 commit 6c9e9c1
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 14 deletions.
2 changes: 2 additions & 0 deletions examples/best-agent/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const AGENT = require('best-agent');
AGENT.run();
25 changes: 25 additions & 0 deletions examples/best-agent/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "best-agent-example",
"version": "0.4.0",
"private": true,
"description": "Best agent example",
"scripts": {
"start": "best-agent"
},
"keywords": [
"lwc",
"agent",
"benchmark",
"perf",
"testing"
],
"author": "LWC Team",
"homepage": "https://github.com/salesforce/best",
"repository": {
"type": "git",
"url": "https://github.com/salesforce/best"
},
"dependencies": {
"best-agent": "0.4.0"
}
}
1 change: 1 addition & 0 deletions examples/simple_benchmark/best.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
benchmarkOnClient: true,
useMacroTaskAfterBenchmark: false,
benchmarkRunner: '@best/runner-headless',
// benchmarkRunner: '@best/runner-remote',

// This is for running @best/runner-remote
// "benchmarkRunnerConfig": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"watch": "yarn build && node ./scripts/watch.js",
"test": "jest --config jest.config.json",
"perf": "best --externalStorage=@best/store-aws",
"start": "cd examples/best-frontend && yarn serve",
"start": "node scripts/start.js",
"web:watch": "lerna exec --scope @best/frontend 'yarn watch'",
"web:watch:s3": "STORE_PLUGIN=@best/store-aws lerna exec --scope @best/frontend 'yarn watch'",
"release": "yarn prepare && lerna publish --exact --force-publish=* --registry='https://npm.lwcjs.org' && yarn changelog",
Expand Down
2 changes: 1 addition & 1 deletion packages/best-agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"Best",
"LWC"
],
"main": "build/index.js",
"main": "build/cli/index.js",
"module": "src/index.js",
"dependencies": {
"@best/runner": "0.4.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/best-agent/src/cli/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import express from 'express';
import { Server } from 'http';
import { runAgent } from '../agent-service';
const PORT = process.env.port || 5000;
const PORT = process.env.PORT || 5000;

export function run() {
const app = express();
Expand Down
15 changes: 9 additions & 6 deletions packages/best-agent/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@ const LOADER_CONFIG = {

function initializeForwarder(config, socket, logger) {
return {
onBenchmarkStart(benchmarkName) {
logger(`STATUS: running_benchmark (${benchmarkName})`);
socket.emit('running_benchmark_start', benchmarkName);
onBenchmarkStart(benchmarkName, projectName) {
logger(`STATUS: running_benchmark ${benchmarkName} (${projectName})`);
socket.emit('running_benchmark_start', benchmarkName, projectName);
},
updateBenchmarkProgress(state, opts) {
socket.emit('running_benchmark_update', { state, opts });
},
onBenchmarkEnd(benchmarkName) {
logger(`STATUS: finished_benchmark (${benchmarkName})`);
socket.emit('running_benchmark_end', benchmarkName);
onBenchmarkEnd(benchmarkName, projectName) {
logger(`STATUS: finished_benchmark ${benchmarkName} (${projectName})`);
socket.emit('running_benchmark_end', benchmarkName, projectName);
},
onBenchmarkError(benchmarkName, projectName) {
socket.emit('running_benchmark_error', benchmarkName, projectName);
},
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const MOCK_MESSAGER = {
updateBenchmarkProgress() {},
onBenchmarkEnd() {},
onBenchmarkError() {}

};

describe('run', () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/best-runner-remote/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ function proxifyRunner(benchmarkEntryBundle, runnerConfig, projectConfig, global
});
});

socket.on('running_benchmark_start', benchName => {
messager.onBenchmarkStart(benchName, {
socket.on('running_benchmark_start', (benchName, projectName) => {
messager.onBenchmarkStart(benchName, projectName, {
displayPath: `${host}/${benchName}`,
});
});

socket.on('running_benchmark_update', ({ state, opts }) => {
messager.updateBenchmarkProgress(state, opts);
});
socket.on('running_benchmark_end', benchName => {
messager.onBenchmarkEnd(benchName);
socket.on('running_benchmark_end', (benchName, projectName) => {
messager.onBenchmarkEnd(benchName, projectName);
});

// socket.on('disconnect', (s) => {
Expand Down
9 changes: 9 additions & 0 deletions scripts/start.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const BEST_SERVICE_TYPE = process.env.BEST_SERVICE_TYPE || 'frontend';

console.log(`Initializing ${BEST_SERVICE_TYPE}`);

if (BEST_SERVICE_TYPE === 'frontend') {
require('best-frontend-example');
} else if (BEST_SERVICE_TYPE === 'agent') {
require('best-agent').run();
}

0 comments on commit 6c9e9c1

Please sign in to comment.