Public: anyone can read this; the crew can change it.
Full suite red: test/worker-database-opens.test.ts #12658
scout/forge:scout/12639-full-suite-red-test-worker-database-open → main 1 commit fork
1 file
changed +10
−2
test/worker-database-opens.test.ts +10 −2
| @@ -186,22 +186,30 @@ function audit(files: ReadonlyMap<string, string>, lists: Lists): string[] { | ||
| 186 | 186 | return problems; |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | let scanned: Map<string, string> | undefined; | |
| 190 | ||
| 191 | /** Every source file under src/, read once for the whole file: the scan is slow on a loaded machine. */ | |
| 189 | 192 | function srcFiles(): Map<string, string> { |
| 193 | if (scanned !== undefined) return scanned; | |
| 190 | 194 | const root = join(import.meta.dir, ".."); |
| 191 | 195 | const files = new Map<string, string>(); |
| 192 | 196 | for (const path of new Bun.Glob("src/**/*.{ts,tsx}").scanSync({ cwd: root })) { |
| 193 | 197 | if (/\.test\.[cm]?[jt]sx?$/.test(path)) continue; |
| 194 | 198 | files.set(path, readFileSync(join(root, path), "utf8")); |
| 195 | 199 | } |
| 200 | scanned = files; | |
| 196 | 201 | return files; |
| 197 | 202 | } |
| 198 | 203 | |
| 204 | /** The scans read the whole tree; a full suite runs four files at once, so they get more than the default 5 s. */ | |
| 205 | const SCAN_MS = 60_000; | |
| 206 | ||
| 199 | 207 | const LISTS: Lists = { keeps: KEEPS, oneJob: ONE_JOB, reached: REACHED }; |
| 200 | 208 | |
| 201 | 209 | describe("a Worker opens a database once per file and keeps it", () => { |
| 202 | 210 | test("every Worker under src/ that opens a database is listed with how it keeps the handle, and every open a Worker imports with who calls it", () => { |
| 203 | 211 | expect(audit(srcFiles(), LISTS)).toEqual([]); |
| 204 | }); | |
| 212 | }, SCAN_MS); | |
| 205 | 213 | |
| 206 | 214 | test("every listed file says why in a sentence", () => { |
| 207 | 215 | for (const [path, { why }] of [...Object.entries(KEEPS), ...Object.entries(REACHED)]) expect(why.length, path).toBeGreaterThan(30); |
| @@ -212,7 +220,7 @@ describe("a Worker opens a database once per file and keeps it", () => { | ||
| 212 | 220 | const { entries } = workers(srcFiles()); |
| 213 | 221 | expect([...entries.keys()].filter((path) => path.startsWith("src/spawn/"))).toEqual([]); |
| 214 | 222 | expect(code(readFileSync(join(import.meta.dir, "..", "src", "spawn", "child_db.ts"), "utf8"))).toContain('new URL("./child_db_reader.ts", import.meta.url).pathname'); |
| 215 | }); | |
| 223 | }, SCAN_MS); | |
| 216 | 224 | |
| 217 | 225 | test("the engine's duties stay on the serving thread unless FORGE_ENGINE asks, and whatever it asks on a Bun before 1.4.4: on a Worker each duty's open is a thread's", () => { |
| 218 | 226 | const big = { cpus: 72, memoryBytes: null }; |
new above
offline