Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/benchmark/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import {
} from "@vitest/runner";
import Debug from "debug";
import {Benchmark, BenchmarkOpts, BenchmarkResults} from "../types.ts";
import {consoleError} from "../utils/output.ts";
import {store} from "./globalState.ts";
import {BenchmarkReporter} from "./reporter.ts";

const debug = Debug("@chainsafe/benchmark/runner");

export class BenchmarkRunner implements VitestRunner {
readonly triggerGC: boolean;
failedCount = 0;
readonly config: VitestRunnerConfig;
readonly reporter: BenchmarkReporter;
readonly prevBench: Benchmark | null;
Expand Down Expand Up @@ -98,10 +100,20 @@ export class BenchmarkRunner implements VitestRunner {

debug("finished tests. passed: %i, skipped: %i, failed: %i", passed.length, skipped.length, failed.length);

if (passed.length + skipped.length + failed.length === res.length) {
return store.getAllResults();
if (passed.length + skipped.length + failed.length !== res.length) {
throw new Error("Some tests returned with unknown state");
}

throw new Error("Some tests cause returned with unknown state");
if (failed.length > 0) {
this.failedCount = failed.length;
consoleError(`${failed.length} benchmark(s) failed:\n`);
for (const f of failed) {
const error = f.result?.errors?.[0];
const errorMsg = error?.message ?? error?.toString() ?? "unknown error";
consoleError(` ✖ ${f.name}: ${errorMsg}`);
}
}
Comment on lines +103 to +115
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lodekeeper The diagnosis of the issue is fine but solution is a bit hacky. The runner pipeline expects process to return results. Instead of throwing here, will skip a lof of logic involving persistence of passed tests.

Better approach would be either:

  1. Console log the failures instead of the throwing, so all passed results can be persisted
  2. Return consolidated result set for passed and failed both and let the reporter decide how to report those.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point — throwing from process() skips the entire persistence + reporting pipeline for passed results. Pushed a fix: failures are now logged to stderr (with per-benchmark error details) instead of throwing, so store.getAllResults() still returns passed results and the downstream someFailed + noThrow handling in run.ts controls the final exit behavior.

Option 2 (consolidated pass/fail result set) would be the more complete approach long-term, but would require extending BenchmarkResults typing — happy to follow up on that if you'd prefer it over the logging approach.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the approach based on your feedback — now:

  1. Runner logs each failure to stderr with the error message (option 1)
  2. Passed results still flow through persistence + reporting pipeline
  3. failedCount exposed on the runner so run.ts can check after persistence/reporting
  4. run.ts throws after persistence + reporting when failedCount > 0 (respects noThrow)

This way passed benchmarks still get persisted/compared, and CI still fails on errors.


return store.getAllResults();
}
}
4 changes: 4 additions & 0 deletions src/cli/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ export async function run(opts_: FileCollectionOptions & StorageOptions & Benchm
if (resultsComp.someFailed && !opts.noThrow) {
throw Error("Performance regression");
}

if (runner.failedCount > 0 && !opts.noThrow) {
throw Error(`${runner.failedCount} benchmark(s) failed with errors`);
}
} catch (err) {
consoleLog(`Error processing benchmark files. ${(err as Error).message}`);
throw err;
Expand Down
4 changes: 4 additions & 0 deletions src/utils/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ export function consoleLog(...args: unknown[]): void {
// biome-ignore lint/suspicious/noConsoleLog: We explicitly need to log some output
console.log(...args);
}

export function consoleError(...args: unknown[]): void {
console.error(...args);
}
Loading