-
-
Notifications
You must be signed in to change notification settings - Fork 0
fix: fail benchmark reindex when indexer exits non-zero #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@stainless-code/codemap": patch | ||
| --- | ||
|
|
||
| Fail benchmark reindex runs when the spawned indexer exits non-zero instead of recording misleading timings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import { describe, expect, it } from "bun:test"; | ||
|
|
||
| import { runBenchmarkReindex } from "./benchmark-reindex"; | ||
|
|
||
| describe("runBenchmarkReindex", () => { | ||
| it("throws when the indexer exits non-zero instead of recording a timing", async () => { | ||
| let spawnCalls = 0; | ||
| await expect( | ||
| runBenchmarkReindex("fail case", ["--full"], { | ||
| runs: 1, | ||
| spawnIndexer: async () => { | ||
| spawnCalls++; | ||
| return { | ||
| exitCode: 1, | ||
| stderr: "indexer exploded", | ||
| stdout: "", | ||
| }; | ||
| }, | ||
| }), | ||
| ).rejects.toThrow(/benchmark reindex "fail case" failed \(exit 1\)/); | ||
| expect(spawnCalls).toBe(1); | ||
| }); | ||
|
|
||
| it("rejects invalid runs values", async () => { | ||
| const spawnIndexer = async () => ({ | ||
| exitCode: 0, | ||
| stderr: "", | ||
| stdout: "", | ||
| }); | ||
| await expect( | ||
| runBenchmarkReindex("bad-runs", [], { runs: 0, spawnIndexer }), | ||
| ).rejects.toThrow(/requires runs >= 1/); | ||
| await expect( | ||
| runBenchmarkReindex("bad-runs", [], { runs: -1, spawnIndexer }), | ||
| ).rejects.toThrow(/requires runs >= 1/); | ||
| await expect( | ||
| runBenchmarkReindex("bad-runs", [], { runs: 1.5, spawnIndexer }), | ||
| ).rejects.toThrow(/requires runs >= 1/); | ||
| }); | ||
|
|
||
| it("records timings when every run exits zero", async () => { | ||
| const result = await runBenchmarkReindex("ok", [], { | ||
| runs: 2, | ||
| spawnIndexer: async () => ({ | ||
| exitCode: 0, | ||
| stderr: "", | ||
| stdout: "", | ||
| }), | ||
| }); | ||
| expect(result.label).toBe("ok"); | ||
| expect(result.runs).toBe(2); | ||
| expect(result.avg).toBeGreaterThanOrEqual(0); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| async function timeMsAsync(fn: () => Promise<void>): Promise<{ ms: number }> { | ||
| const start = performance.now(); | ||
| await fn(); | ||
| return { ms: performance.now() - start }; | ||
| } | ||
|
|
||
| export interface IndexerSpawnResult { | ||
| exitCode: number | null; | ||
| stderr: string; | ||
| stdout: string; | ||
| } | ||
|
|
||
| export type IndexerSpawn = (args: string[]) => Promise<IndexerSpawnResult>; | ||
|
|
||
| export async function runBenchmarkReindex( | ||
| label: string, | ||
| args: string[], | ||
| opts: { spawnIndexer: IndexerSpawn; runs?: number }, | ||
| ): Promise<{ | ||
| label: string; | ||
| avg: number; | ||
| min: number; | ||
| max: number; | ||
| runs: number; | ||
| }> { | ||
| const runs = opts.runs ?? 3; | ||
| if (!Number.isInteger(runs) || runs < 1) { | ||
| throw new Error(`benchmark reindex "${label}" requires runs >= 1`); | ||
| } | ||
| const times: number[] = []; | ||
| for (let i = 0; i < runs; i++) { | ||
| const t = await timeMsAsync(async () => { | ||
| const { exitCode, stderr, stdout } = await opts.spawnIndexer(args); | ||
| if (exitCode !== 0) { | ||
| const detail = [stderr, stdout].filter(Boolean).join("\n").trim(); | ||
| throw new Error( | ||
| `benchmark reindex "${label}" failed (exit ${exitCode ?? "?"}): ${detail || "(no output)"}`, | ||
| ); | ||
| } | ||
| }); | ||
| times.push(t.ms); | ||
| } | ||
| const avg = times.reduce((a, b) => a + b, 0) / runs; | ||
| const min = Math.min(...times); | ||
| const max = Math.max(...times); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| return { label, avg, min, max, runs }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win
Document the exported benchmark API surface.
The exported interface/type/function are public API but currently have no accompanying docs. Add concise JSDoc that captures intent/contract (especially failure behavior and
runssemantics).📝 Proposed doc additions
export interface IndexerSpawnResult { exitCode: number | null; stderr: string; stdout: string; } +/** Spawns an indexer process for the provided CLI arguments. */ export type IndexerSpawn = (args: string[]) => Promise<IndexerSpawnResult>; +/** + * Benchmarks repeated reindex runs and returns aggregate timing stats. + * Throws when any run exits non-zero to avoid reporting failed runs as timings. + */ export async function runBenchmarkReindex(As per coding guidelines, "
**/*.{ts,tsx,js,jsx}: All public APIs must have accompanying documentation".🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skipping JSDoc here — this is an internal benchmark helper (
benchmark.ts+ tests only), not package public API. Names and types are self-explanatory; we avoid signature-restating comments on smallsrc/utilities per project comment discipline.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SutuSebastian, understood — theexportkeyword here is for testability, not public package API surface, and the names+types speak for themselves. Happy to defer to the project's comment discipline. I'll note this for future reviews.( ˘︹˘ ) 🐇
✏️ Learnings added
🧠 Learnings used