Skip to content

armgit / Ix

Public Imported from GitHub
0

Understand any codebase instantly. System intelligence for codebases, built for humans and AI.

test: make the IN-05 bulk-size tests and resolveEdges scaling check reliable (#875)

Ian Hockae5d3c814651
diff --git a/core-ingestion/src/__tests__/resolveEdges.batching.test.ts b/core-ingestion/src/__tests__/resolveEdges.batching.test.ts
index 112bae37..cac0be36 100644
--- a/core-ingestion/src/__tests__/resolveEdges.batching.test.ts
+++ b/core-ingestion/src/__tests__/resolveEdges.batching.test.ts
@@ -125,23 +125,30 @@ describe('resolveEdges scales with the repository', () => {
return out;
}
- it('doubling the files keeps the time well under quadratic', () => {
- // Best of seven on sizes large enough that one scheduler hiccup can't swing
- // the ratio. Linear doubling is ~2x and quadratic ~4x; shared CI runners sit
- // well above linear, so the bound is 3.5x, which still catches quadratic.
- const time = (results: FileParseResult[]) => {
- const index = indexOf(results);
- return Math.min(...Array.from({ length: 7 }, () => {
- const t = performance.now();
- resolveEdges(results, undefined, index);
- return performance.now() - t;
- }));
- };
- const small = synthetic(2000);
+ it('quadrupling the files keeps the time well under quadratic', () => {
+ // 1,000 files against 4,000. Linear is ~4x and quadratic ~16x, so the
+ // bound sits at 10x (about n^1.66), with room on both sides. It used to
+ // double, 2,000 against 4,000, with a bound of 3.5x: linear ~2x and
+ // quadratic ~4x left so little between them that one slow stretch on a
+ // shared runner put a linear run at 3.5x.
+ //
+ // The two sizes are timed in turn, seven rounds of each, and each keeps
+ // its best. Timed in two blocks, a runner that slowed down for the second
+ // block charged all of it to the large size; interleaved, a slow stretch
+ // lands on both.
+ const small = synthetic(1000);
const large = synthetic(4000);
- time(small); // warm up
- time(large);
- expect(time(large) / time(small)).toBeLessThan(3.5);
+ const sizes = [small, large].map((results) => ({ results, index: indexOf(results), best: Infinity }));
+ const timeOnce = (s: (typeof sizes)[number]) => {
+ const t = performance.now();
+ resolveEdges(s.results, undefined, s.index);
+ return performance.now() - t;
+ };
+ for (const s of sizes) timeOnce(s); // warm up
+ for (let round = 0; round < 7; round++) {
+ for (const s of sizes) s.best = Math.min(s.best, timeOnce(s));
+ }
+ expect(sizes[1].best / sizes[0].best).toBeLessThan(10);
}, 60_000);
});
diff --git a/ix-cli/src/cli/__tests__/ingest-files.test.ts b/ix-cli/src/cli/__tests__/ingest-files.test.ts
index 071d81d1..c26d4aa5 100644
--- a/ix-cli/src/cli/__tests__/ingest-files.test.ts
+++ b/ix-cli/src/cli/__tests__/ingest-files.test.ts
@@ -198,6 +198,7 @@ describe("ingestFiles against a fake backend", () => {
"IX_STITCH_COOLDOWN_MS",
"IX_STITCH_WAIT_MS",
"IX_MAP_DEADLINE_MS",
+ "IX_PARSE_STREAM_CHUNK",
]) {
saved[k] = process.env[k];
delete process.env[k];
@@ -1527,50 +1528,63 @@ describe("ingestFiles against a fake backend", () => {
});
describe("bulk requests bounded by size (IN-05)", () => {
- // More than one parse batch (500 files), so what the first batch learns has
- // a later batch to hold for. The backend refuses a bulk over 300 ops.
+ // More than one parse batch, so what the first batch learns has a later
+ // batch to hold for.
+ //
+ // The batches are 50 files here (IX_PARSE_STREAM_CHUNK), not the default
+ // 500, and every count below is a tenth of what a 500-file batch needs: the
+ // files, the batches and the backend's cap. These tests used to write,
+ // `git add`, read and parse 560 to 1,100 files each. That costs well under
+ // a second on Linux and macOS, but on the 4-core windows-2022 runner, with
+ // the rest of the suite running beside it, it took from seven to more than
+ // thirty seconds, and timed out. The work was all per file, and none of it
+ // is what these tests check: the batch boundaries, the ops per request and
+ // the 413s are the same at a tenth of the size. The backend refuses a bulk
+ // over 30 ops; at 7 ops a file that is 4 files a request. (The variable
+ // is cleared and restored around every test by the describe above.)
const tooLarge = () => backend.requests.filter(r => r.path === "/v1/patches/bulk" && r.code === 413).length;
+ const smallBatches = (): void => { process.env.IX_PARSE_STREAM_CHUNK = "50"; };
const saved = process.env.IX_COMMIT_MAX_OPS;
afterEach(() => {
if (saved === undefined) delete process.env.IX_COMMIT_MAX_OPS;
else process.env.IX_COMMIT_MAX_OPS = saved;
});
- // 560 files, two parse batches: 500, then 60. At 7 ops a file the second
- // batch is 420 ops, over the cap at the default bounds, so it is refused
- // too unless the run kept what the first batch learned. It used to be
- // 1,100 files (three batches), which timed out once on a slow Windows
- // runner; the second batch alone is what the assertion needs. The longer
- // timeout is a backstop for the fixture writes and parse there.
- it("learns the size from the first 413 that suggests one, and is refused no more that run", { timeout: 90_000 }, async () => {
- fixture(560);
- backend.maxBulkOps = 300;
+ // 56 files, two parse batches: 50, then 6. At 7 ops a file the second
+ // batch is 42 ops, over the cap at the default bounds, so it is refused
+ // too unless the run kept what the first batch learned.
+ it("learns the size from the first 413 that suggests one, and is refused no more that run", async () => {
+ smallBatches();
+ fixture(56);
+ backend.maxBulkOps = 30;
backend.suggestMaxPatches = true;
const summary = await run();
expect(tooLarge()).toBe(1);
expect(summary.commitErrors).toBe(0);
- expect(summary.patchesApplied).toBe(560);
+ expect(summary.patchesApplied).toBe(56);
expect(backend.singleCount, "no per-file fallback").toBe(0);
// Both batches were sent in bounded requests. Without the learned size,
- // the second batch goes out as one 60-patch request and is refused.
+ // the second batch goes out as one 6-patch request and is refused.
const accepted = backend.requests.filter(r => r.path === "/v1/patches/bulk" && r.code !== 413);
- expect(Math.max(...accepted.map(r => r.patches))).toBeLessThanOrEqual(Math.floor(300 / 7));
+ expect(Math.max(...accepted.map(r => r.patches))).toBeLessThanOrEqual(Math.floor(30 / 7));
});
it("halves on a 413 that suggests nothing, and later batches start at the learned size", async () => {
- fixture(1100);
- backend.maxBulkOps = 300;
+ // Three parse batches: 50, 50, then 10.
+ smallBatches();
+ fixture(110);
+ backend.maxBulkOps = 30;
const summary = await run();
- // A few halvings in the first batch only; bisecting each batch afresh
- // was three times as many.
+ // A few halvings in the first batch only (50, 25, 12, 6 refused; 3
+ // fits); bisecting each batch afresh was more than twice as many.
expect(tooLarge()).toBeGreaterThan(0);
expect(tooLarge()).toBeLessThanOrEqual(4);
expect(summary.commitErrors).toBe(0);
- expect(summary.patchesApplied).toBe(1100);
+ expect(summary.patchesApplied).toBe(110);
});
it("keeps its op budget after a 413 for bytes: one large file does not shrink the requests after it", async () => {
@@ -1600,14 +1614,15 @@ describe("ingestFiles against a fake backend", () => {
});
it("is never refused when IX_COMMIT_MAX_OPS keeps every request under the cap", async () => {
- fixture(1100);
- backend.maxBulkOps = 300;
- process.env.IX_COMMIT_MAX_OPS = "300";
+ smallBatches();
+ fixture(110);
+ backend.maxBulkOps = 30;
+ process.env.IX_COMMIT_MAX_OPS = "30";
const summary = await run();
expect(tooLarge()).toBe(0);
- expect(summary.patchesApplied).toBe(1100);
+ expect(summary.patchesApplied).toBe(110);
});
});
diff --git a/ix-cli/src/cli/commands/ingest.ts b/ix-cli/src/cli/commands/ingest.ts
index 41356d81..036cc1f0 100644
--- a/ix-cli/src/cli/commands/ingest.ts
+++ b/ix-cli/src/cli/commands/ingest.ts
@@ -3232,7 +3232,9 @@ export async function ingestFiles(
// Smaller chunks pipeline better: resolve(N) overlaps with commit(N-1) + parse(N+1).
// With 2000-file chunks, resolve takes 68s and dominates. With 500, resolve ~17s
// and overlaps well with commit (~5s) + parse (~5s).
- const PARSE_STREAM_CHUNK = 500;
+ // IX_PARSE_STREAM_CHUNK is for tests: it lets a run of a hundred files
+ // cross the same batch boundaries as a run of a thousand. Unset, 500.
+ const PARSE_STREAM_CHUNK = parsePositiveIntEnv('IX_PARSE_STREAM_CHUNK', 500);
const COMMIT_HTTP_MAX_FILES = parsePositiveIntEnv('IX_COMMIT_HTTP_MAX_FILES', 1000); // files per HTTP request to the backend
// Ops per HTTP request; see DEFAULT_COMMIT_MAX_OPS.
const COMMIT_MAX_OPS = parsePositiveIntEnv('IX_COMMIT_MAX_OPS', DEFAULT_COMMIT_MAX_OPS);