Skip to content

Commit

Permalink
fix: parsing error timeout (#121)
Browse files Browse the repository at this point in the history
* fix: parsing error timeout
* fix: minor comment change
* fix: accomodating test message
  • Loading branch information
diervo committed Sep 3, 2018
1 parent 27aad3e commit d283352
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 2 deletions.
9 changes: 9 additions & 0 deletions examples/simple_benchmark/best.prod.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ module.exports = {
"options": { path: '/best' },
"remoteRunner": "@best/runner-headless"
}
},
{
"runner": '@best/runner-remote',
"name": "remote",
"config": {
"host": "http://best-agent-pool.lwcjs.org/",
"options": { path: '/best' },
"remoteRunner": "@best/runner-headless"
}
}
],
};
2 changes: 1 addition & 1 deletion packages/best-config/src/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default {
runner: "default",
runnerConfig: [{ runner: '@best/runner-headless', config: {} }],
benchmarkEnvironment: 'production',
benchmarkMaxDuration: 1000 * 10, // 10s
benchmarkMaxDuration: 1000 * 15, // 15s
benchmarkMinIterations: 30,
benchmarkOnClient: false,
benchmarkIterations: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('errors', () => {
};

return expect(run(benchmarkConfig, PROJECT_CONFIG, GLOBAL_CONFIG, MOCK_MESSAGER)).rejects.toThrow(
/BEST is not defined/,
/Benchmark parse error/,
);
});

Expand Down
16 changes: 16 additions & 0 deletions packages/best-runner-headless/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ async function runServerIterations(page, state, opts, messager) {
}

async function runIterations(page, state, opts, messager) {
// TODO: Throw on timeouts, current logic is
// currently non-existant for clientside iteration mode
// if (state.executedTime > opts.maxDuration) {
// throw new Error('Benchmark timmed out');
// }

if (state.iterateOnClient) {
return runClientIterations(page, state, opts, messager);
}
Expand Down Expand Up @@ -130,15 +136,25 @@ export async function run({ benchmarkName, benchmarkEntry }, projectConfig, glob
const { projectName } = projectConfig;

let browser;
let parseError;
try {
browser = await puppeteer.launch(PUPPETEER_OPTIONS);
const environment = await normalizeEnvironment(browser, projectConfig, globalConfig);

messager.onBenchmarkStart(benchmarkName, projectName);

const page = await browser.newPage();
page.on('pageerror', (err) => (parseError = err));
await page.goto('file:///' + benchmarkEntry);

// page.goto() will wait for the onload
// if we caught something that throws there is a parsing error in the benchmark code
if (parseError) {
messager.onBenchmarkError(benchmarkName, projectName);
parseError.message = 'Benchmark parse error.\n' + parseError.message;
throw parseError;
}

const { results } = await runIterations(page, state, opts, messager);
return { results, environment };
} catch (e) {
Expand Down
2 changes: 2 additions & 0 deletions packages/best-runtime/src/runner.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getBenchmarkRootNode } from './state';
import { runBenchmarkIteration } from './run_iteration';
import { normalizeResults } from './results';
import { validateState } from "./utils/validate";

function collectResults(node) {
const { name, duration, startedAt, run } = node;
Expand Down Expand Up @@ -38,6 +39,7 @@ async function runIterations(config) {
}

export async function runBenchmark(benchmarkState) {
validateState(benchmarkState);
if (benchmarkState.benchmarkDefinitionError) {
throw benchmarkState.benchmarkDefinitionError;
}
Expand Down
10 changes: 10 additions & 0 deletions packages/best-runtime/src/utils/validate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export function validateState(benchmarkState) {
const { rootDescribeBlock, currentDescribeBlock } = benchmarkState;
if (rootDescribeBlock !== currentDescribeBlock) {
benchmarkState.benchmarkDefinitionError = 'Benchmark parsing error';
}

if (rootDescribeBlock.children === 0) {
benchmarkState.benchmarkDefinitionError = 'No benchmarks to run';
}
}

0 comments on commit d283352

Please sign in to comment.