Public: anyone can read this; the crew can change it.

Two order-dependent flakes made deterministic: tui-crawlers pins loop lag; job-alloc measures a kept buffer after a full collection #16875

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

fix/test-order-flakes → main 0 commits

  • Merged. fix/test-order-flakes was merged into main as b5f87f0.

Review

Sign in to review this change.
2 files changed +20 −16
test/job-alloc.test.ts +16 −15
@@ -12,20 +12,24 @@ const MIB = 1024 * 1024;
1212 /** A stopped clock, so the real heap's read time never spends the tally's budget here. */
1313 const { counted, take: takeAllocations } = createTally(undefined, () => 0);
1414 const keep: unknown[] = [];
15 /** Grow the JS heap (typed arrays live off it) and keep it, so no collection undoes it. */
16 const grow = (n = 100_000): number => keep.push(Array.from({ length: n }, (_, i) => ({ i, s: `v${i}` })));
17 /** Run `fn` as `name` until the heap was seen to grow across it: a collection can hide one try. */
15 /** Grow the heap by 4 MiB and keep it: an ArrayBuffer is counted in heapSize() at its size. */
16 const grow = (): number => keep.push(new ArrayBuffer(4 * MIB));
17 /**
18 * Run `fn` as `name` once, after a full collection. The test files before this one in a shard leave
19 * garbage behind; a collection that ran inside the slice reclaimed it and read as the slice
20 * shrinking the heap (-42 MiB measured), so small object arrays showed as no growth, or under the
21 * 1 MiB a line names. Collected first, there is nothing for one inside the slice to reclaim, and
22 * the kept buffer is counted whole.
23 */
1824 function grown(c: (name: string, fn: () => unknown) => unknown, name: string, fn: () => unknown = grow): void {
19 for (let i = 0; i < 40; i++) {
20 const before = heapSize();
21 try {
22 c(name, fn);
23 } catch {
24 // the caller's own assertion covers a throw
25 }
26 if (heapSize() - before > 0) return;
25 Bun.gc(true);
26 const before = heapSize();
27 try {
28 c(name, fn);
29 } catch {
30 // the caller's own assertion covers a throw
2731 }
28 throw new Error(`the heap never grew across ${name}`);
32 if (heapSize() - before <= 0) throw new Error(`the heap did not grow across ${name}`);
2933 }
3034
3135 test("a job that keeps what it allocates is named with its size, and the count is emptied by reading it", () => {
@@ -107,9 +111,6 @@ afterAll(async () => {
107111
108112 test("allocationsOf merges the unowned and this forge's jobs, most first, five at most", () => {
109113 allocationsOf(app);
110 // An ArrayBuffer is counted in heapSize() at its size even when a collection runs inside the
111 // slice; small object arrays are not (a collection reclaiming old garbage hides them), which
112 // made a 20,000-object slice read as no growth on all forty tries in a loaded process.
113114 const duringGrown = (name: string, bytes: number, owner?: object) =>
114115 grown((nm, fn) => during(nm, fn as () => number, undefined, owner), name, () => keep.push(new ArrayBuffer(bytes)));
115116 for (let i = 0; i < 5; i++) duringGrown(`own-${i}`, MIB, app);
test/tui-crawlers.test.ts +4 −1
@@ -6,7 +6,7 @@ import { tmpdir } from "node:os";
66 import { join } from "node:path";
77 import { createApp, type App } from "../src/app.ts";
88 import { createUser, type User } from "../src/core/users.ts";
9 import { setCrawlClock, takeCrawl } from "../src/http/crawl.ts";
9 import { pinCrawlLag, setCrawlClock, takeCrawl } from "../src/http/crawl.ts";
1010 import { createForgeApp, forgeCommands } from "../src/tui/forge.ts";
1111 import { crawlersScreen } from "../src/tui/screens/crawlers.ts";
1212 import { headlessTerminal } from "../src/tui/term/terminal.ts";
@@ -25,6 +25,9 @@ beforeAll(async () => {
2525 dir = await mkdtemp(join(tmpdir(), "forge-tui-crawlers-"));
2626 app = createApp({ dataDir: dir, port: 0 });
2727 quietWeek(app.db);
28 // The lag reading is the process's: a busy file before this one in the shard left it behind, the
29 // budgets were divided by four, and the screen said "address 7" for 8 deep reads, not 2.
30 pinCrawlLag(app, false);
2831 const mk = async (username: string, isAdmin: boolean) => {
2932 const r = await createUser(app.db, { origin: "seed", trusted: true, username, email: `${username}@forge.local`, password: "a-good-passphrase", isAdmin });
3033 if (!r.ok) throw new Error(r.error);

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs